/ test / handler / test_flake8_handler.vader
test_flake8_handler.vader
  1  Before:
  2    Save g:ale_warn_about_trailing_blank_lines
  3    Save g:ale_warn_about_trailing_whitespace
  4  
  5    let g:ale_warn_about_trailing_blank_lines = 1
  6    let g:ale_warn_about_trailing_whitespace = 1
  7  
  8    runtime ale_linters/python/flake8.vim
  9  
 10  After:
 11    Restore
 12  
 13    unlet! b:ale_warn_about_trailing_blank_lines
 14    unlet! b:ale_warn_about_trailing_whitespace
 15  
 16    call ale#linter#Reset()
 17  
 18  Execute(The flake8 handler should handle basic warnings and syntax errors):
 19    AssertEqual
 20    \ [
 21    \   {
 22    \     'lnum': 6,
 23    \     'col': 6,
 24    \     'vcol': 1,
 25    \     'type': 'E',
 26    \     'text': 'indentation is not a multiple of four',
 27    \     'code': 'E111',
 28    \     'sub_type': 'style',
 29    \   },
 30    \   {
 31    \     'lnum': 7,
 32    \     'col': 6,
 33    \     'vcol': 1,
 34    \     'type': 'W',
 35    \     'text': 'some warning',
 36    \     'code': 'W123',
 37    \     'sub_type': 'style',
 38    \   },
 39    \   {
 40    \     'lnum': 8,
 41    \     'col': 3,
 42    \     'vcol': 1,
 43    \     'type': 'E',
 44    \     'text': 'SyntaxError: invalid syntax',
 45    \     'code': 'E999',
 46    \   },
 47    \ ],
 48    \ ale_linters#python#flake8#Handle(1, [
 49    \   'stdin:6:6: E111 indentation is not a multiple of four',
 50    \   'stdin:7:6: W123 some warning',
 51    \   'stdin:8:3: E999 SyntaxError: invalid syntax',
 52    \ ])
 53  
 54  Execute(The flake8 handler should set end column indexes for certain errors):
 55    AssertEqual
 56    \ [
 57    \   {
 58    \     'lnum': 25,
 59    \     'col': 1,
 60    \     'vcol': 1,
 61    \     'type': 'E',
 62    \     'end_col': 3,
 63    \     'text': 'undefined name ''foo''',
 64    \     'code': 'F821',
 65    \   },
 66    \   {
 67    \     'lnum': 28,
 68    \     'col': 5,
 69    \     'vcol': 1,
 70    \     'type': 'E',
 71    \     'end_col': 9,
 72    \     'text': 'hello may be undefined, or defined from star imports: x',
 73    \     'code': 'F405',
 74    \   },
 75    \   {
 76    \     'lnum': 104,
 77    \     'col': 5,
 78    \     'vcol': 1,
 79    \     'type': 'E',
 80    \     'end_col': 12,
 81    \     'text': '''continue'' not properly in loop',
 82    \     'code': 'F999',
 83    \   },
 84    \   {
 85    \     'lnum': 106,
 86    \     'col': 5,
 87    \     'vcol': 1,
 88    \     'type': 'E',
 89    \     'end_col': 9,
 90    \     'text': '''break'' outside loop',
 91    \     'code': 'F999',
 92    \   },
 93    \   {
 94    \     'lnum': 109,
 95    \     'col': 5,
 96    \     'vcol': 1,
 97    \     'type': 'E',
 98    \     'end_col': 8,
 99    \     'text': 'local variable ''test'' is assigned to but never used',
100    \     'code': 'F841',
101    \   },
102    \ ],
103    \ ale_linters#python#flake8#Handle(1, [
104    \ 'foo.py:25:1: F821 undefined name ''foo''',
105    \ 'foo.py:28:5: F405 hello may be undefined, or defined from star imports: x',
106    \ 'foo.py:104:5: F999 ''continue'' not properly in loop',
107    \ 'foo.py:106:5: F999 ''break'' outside loop',
108    \ 'foo.py:109:5: F841 local variable ''test'' is assigned to but never used',
109    \ ])
110  
111  Execute(The flake8 handler should handle stack traces):
112    AssertEqual
113    \ [
114    \   {
115    \     'lnum': 1,
116    \     'text': 'ImportError: No module named parser (See :ALEDetail)',
117    \     'detail': join([
118    \       'Traceback (most recent call last):',
119    \       '  File "/usr/local/bin/flake8", line 7, in <module>',
120    \       '    from flake8.main.cli import main',
121    \       '  File "/usr/local/lib/python2.7/dist-packages/flake8/main/cli.py", line 2, in <module>',
122    \       '    from flake8.main import application',
123    \       '  File "/usr/local/lib/python2.7/dist-packages/flake8/main/application.py", line 17, in <module>',
124    \       '    from flake8.plugins import manager as plugin_manager',
125    \       '  File "/usr/local/lib/python2.7/dist-packages/flake8/plugins/manager.py", line 5, in <module>',
126    \       '    import pkg_resources',
127    \       '  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 35, in <module>',
128    \       '    import email.parser',
129    \       'ImportError: No module named parser',
130    \     ], "\n"),
131    \   },
132    \ ],
133    \ ale_linters#python#flake8#Handle(42, [
134    \   'Traceback (most recent call last):',
135    \   '  File "/usr/local/bin/flake8", line 7, in <module>',
136    \   '    from flake8.main.cli import main',
137    \   '  File "/usr/local/lib/python2.7/dist-packages/flake8/main/cli.py", line 2, in <module>',
138    \   '    from flake8.main import application',
139    \   '  File "/usr/local/lib/python2.7/dist-packages/flake8/main/application.py", line 17, in <module>',
140    \   '    from flake8.plugins import manager as plugin_manager',
141    \   '  File "/usr/local/lib/python2.7/dist-packages/flake8/plugins/manager.py", line 5, in <module>',
142    \   '    import pkg_resources',
143    \   '  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 35, in <module>',
144    \   '    import email.parser',
145    \   'ImportError: No module named parser',
146    \ ])
147  
148  Execute(The flake8 handler should handle names with spaces):
149    AssertEqual
150    \ [
151    \   {
152    \     'lnum': 6,
153    \     'col': 6,
154    \     'vcol': 1,
155    \     'type': 'E',
156    \     'text': 'indentation is not a multiple of four',
157    \     'code': 'E111',
158    \     'sub_type': 'style',
159    \   },
160    \ ],
161    \ ale_linters#python#flake8#Handle(42, [
162    \   'C:\something\with spaces.py:6:6: E111 indentation is not a multiple of four',
163    \ ])
164  
165  Execute(Warnings about trailing whitespace should be reported by default):
166    AssertEqual
167    \ [
168    \   {
169    \     'lnum': 6,
170    \     'col': 1,
171    \     'vcol': 1,
172    \     'code': 'W291',
173    \     'type': 'W',
174    \     'sub_type': 'style',
175    \     'text': 'who cares',
176    \   },
177    \   {
178    \     'lnum': 6,
179    \     'col': 1,
180    \     'vcol': 1,
181    \     'code': 'W293',
182    \     'type': 'W',
183    \     'sub_type': 'style',
184    \     'text': 'who cares',
185    \   },
186    \ ],
187    \ ale_linters#python#flake8#Handle(bufnr(''), [
188    \   'foo.py:6:1: W291 who cares',
189    \   'foo.py:6:1: W293 who cares',
190    \ ])
191  
192  Execute(Disabling trailing whitespace warnings should work):
193    let b:ale_warn_about_trailing_whitespace = 0
194  
195    AssertEqual
196    \ [
197    \ ],
198    \ ale_linters#python#flake8#Handle(bufnr(''), [
199    \   'foo.py:6:1: W291 who cares',
200    \   'foo.py:6:1: W293 who cares',
201    \ ])
202  
203  Execute(Warnings about trailing blank lines should be reported by default):
204    AssertEqual
205    \ [
206    \   {
207    \     'lnum': 6,
208    \     'col': 1,
209    \     'vcol': 1,
210    \     'code': 'W391',
211    \     'type': 'W',
212    \     'sub_type': 'style',
213    \     'text': 'blank line at end of file',
214    \   },
215    \ ],
216    \ ale_linters#python#flake8#Handle(bufnr(''), [
217    \   'foo.py:6:1: W391 blank line at end of file',
218    \ ])
219  
220  Execute(Disabling trailing blank line warnings should work):
221    let b:ale_warn_about_trailing_blank_lines = 0
222  
223    AssertEqual
224    \ [
225    \ ],
226    \ ale_linters#python#flake8#Handle(bufnr(''), [
227    \   'foo.py:6:1: W391 blank line at end of file',
228    \ ])
229  
230  Execute(F401 should be a warning):
231    AssertEqual
232    \ [
233    \   {
234    \     'lnum': 6,
235    \     'col': 1,
236    \     'vcol': 1,
237    \     'code': 'F401',
238    \     'type': 'W',
239    \     'text': 'module imported but unused',
240    \   },
241    \ ],
242    \ ale_linters#python#flake8#Handle(bufnr(''), [
243    \   'foo.py:6:1: F401 module imported but unused',
244    \ ])
245  
246  Execute(E112 should be a syntax error):
247    AssertEqual
248    \ [
249    \   {
250    \     'lnum': 6,
251    \     'col': 1,
252    \     'vcol': 1,
253    \     'code': 'E112',
254    \     'type': 'E',
255    \     'text': 'expected an indented block',
256    \   },
257    \ ],
258    \ ale_linters#python#flake8#Handle(bufnr(''), [
259    \   'foo.py:6:1: E112 expected an indented block',
260    \ ])
261  
262  Execute(Compatibility with hacking which uses older style flake8):
263    AssertEqual
264    \ [
265    \   {
266    \     'lnum': 6,
267    \     'col': 1,
268    \     'vcol': 1,
269    \     'code': 'H306',
270    \     'type': 'W',
271    \     'text': 'imports not in alphabetical order (smtplib, io)',
272    \   },
273    \ ],
274    \ ale_linters#python#flake8#Handle(bufnr(''), [
275    \   'foo.py:6:1: H306: imports not in alphabetical order (smtplib, io)',
276    \ ])