/ test / handler / test_mypy_handler.vader
test_mypy_handler.vader
  1  Before:
  2    Save g:ale_python_mypy_ignore_invalid_syntax
  3    Save g:ale_python_mypy_show_notes
  4  
  5    unlet! g:ale_python_mypy_show_notes
  6    unlet! g:ale_python_mypy_ignore_invalid_syntax
  7  
  8    runtime ale_linters/python/mypy.vim
  9  
 10    call ale#test#SetDirectory('/testplugin/test/handler')
 11  
 12  After:
 13    Restore
 14  
 15    call ale#test#RestoreDirectory()
 16    call ale#linter#Reset()
 17  
 18  Execute(The mypy handler should parse lines correctly):
 19    call ale#test#SetFilename('__init__.py')
 20  
 21    let g:ale_python_mypy_show_notes = 0
 22  
 23    AssertEqual
 24    \ [
 25    \   {
 26    \     'lnum': 768,
 27    \     'col': 38,
 28    \     'filename': ale#path#Simplify(g:dir . '/baz.py'),
 29    \     'type': 'E',
 30    \     'text': 'Cannot determine type of ''SOME_SYMBOL''',
 31    \   },
 32    \   {
 33    \     'lnum': 821,
 34    \     'col': 38,
 35    \     'filename': ale#path#Simplify(g:dir . '/baz.py'),
 36    \     'type': 'E',
 37    \     'text': 'Cannot determine type of ''SOME_SYMBOL''',
 38    \   },
 39    \   {
 40    \     'lnum': 38,
 41    \     'col': 44,
 42    \     'filename': ale#path#Simplify(g:dir . '/other.py'),
 43    \     'type': 'E',
 44    \     'text': 'Cannot determine type of ''ANOTHER_SYMBOL''',
 45    \   },
 46    \   {
 47    \     'lnum': 15,
 48    \     'col': 3,
 49    \     'filename': ale#path#Simplify(g:dir . '/__init__.py'),
 50    \     'type': 'E',
 51    \     'text': 'Argument 1 to "somefunc" has incompatible type "int"; expected "str"'
 52    \   },
 53    \   {
 54    \     'lnum': 72,
 55    \     'col': 1,
 56    \     'filename': ale#path#Simplify(g:dir . '/__init__.py'),
 57    \     'type': 'W',
 58    \     'text': 'Some warning',
 59    \   },
 60    \ ],
 61    \ ale_linters#python#mypy#Handle(bufnr(''), [
 62    \ 'baz.py: note: In class "SomeClass":',
 63    \ 'baz.py:768:38: error: Cannot determine type of ''SOME_SYMBOL''',
 64    \ 'baz.py: note: In class "AnotherClass":',
 65    \ 'baz.py:821:38: error: Cannot determine type of ''SOME_SYMBOL''',
 66    \ '__init__.py:92: note: In module imported here:',
 67    \ 'other.py: note: In class "YetAnotherClass":',
 68    \ 'other.py:38:44: error: Cannot determine type of ''ANOTHER_SYMBOL''',
 69    \ '__init__.py: note: At top level:',
 70    \ '__init__.py:15:3: error: Argument 1 to "somefunc" has incompatible type "int"; expected "str"',
 71    \ 'another_module/bar.py:14: note: In module imported here,',
 72    \ 'another_module/__init__.py:16: note: ... from here,',
 73    \ '__init__.py:72:1: warning: Some warning',
 74    \ ])
 75  
 76  Execute(The mypy handler should show notes if enabled):
 77    call ale#test#SetFilename('__init__.py')
 78  
 79    AssertEqual
 80    \ [
 81    \   {
 82    \     'lnum': 72,
 83    \     'col': 1,
 84    \     'filename': ale#path#Simplify(g:dir . '/__init__.py'),
 85    \     'type': 'I',
 86    \     'text': 'A note',
 87    \   },
 88    \ ],
 89    \ ale_linters#python#mypy#Handle(bufnr(''), [
 90    \   '__init__.py:72:1: note: A note',
 91    \ ])
 92  
 93    let g:ale_python_mypy_show_notes = 0
 94  
 95    AssertEqual
 96    \ [],
 97    \ ale_linters#python#mypy#Handle(bufnr(''), [
 98    \   '__init__.py:72:1: note: A note',
 99    \ ])
100  
101  Execute(The mypy handler should handle Windows names with spaces):
102    " This test works on Unix, where this is seen as a single filename
103    silent file C:\\something\\with\ spaces.py
104  
105    AssertEqual
106    \ [
107    \   {
108    \     'lnum': 4,
109    \     'col': 0,
110    \     'filename': ale#path#Simplify('C:\something\with spaces.py'),
111    \     'type': 'E',
112    \     'text': 'No library stub file for module ''django.db''',
113    \   },
114    \ ],
115    \ ale_linters#python#mypy#Handle(bufnr(''), [
116    \   'C:\something\with spaces.py:4: error: No library stub file for module ''django.db''',
117    \ ])
118  
119  Execute(The mypy syntax errors shouldn't be ignored by default):
120    AssertEqual
121    \ [
122    \   {
123    \     'lnum': 4,
124    \     'col': 0,
125    \     'filename': ale#path#Simplify(g:dir . '/foo.py'),
126    \     'type': 'E',
127    \     'text': 'invalid syntax',
128    \   },
129    \ ],
130    \ ale_linters#python#mypy#Handle(bufnr(''), [
131    \   'foo.py:4: error: invalid syntax',
132    \ ])
133  
134  Execute(The mypy syntax errors should be ignored when the option is on):
135    let g:ale_python_mypy_ignore_invalid_syntax = 1
136  
137    AssertEqual
138    \ [],
139    \ ale_linters#python#mypy#Handle(bufnr(''), [
140    \   'foo.py:4: error: invalid syntax',
141    \ ])