/ test / handler / test_pycodestyle_handler.vader
test_pycodestyle_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/pycodestyle.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 pycodestyle handler should parse output):
 19    AssertEqual
 20    \ [
 21    \   {
 22    \     'lnum': 8,
 23    \     'col': 3,
 24    \     'type': 'E',
 25    \     'text': 'SyntaxError: invalid syntax',
 26    \     'code': 'E999',
 27    \   },
 28    \   {
 29    \     'lnum': 69,
 30    \     'col': 11,
 31    \     'text': 'multiple imports on one line',
 32    \     'code': 'E401',
 33    \     'type': 'E',
 34    \     'sub_type': 'style',
 35    \   },
 36    \   {
 37    \     'lnum': 77,
 38    \     'col': 1,
 39    \     'text': 'expected 2 blank lines, found 1',
 40    \     'code': 'E302',
 41    \     'type': 'E',
 42    \     'sub_type': 'style',
 43    \   },
 44    \   {
 45    \     'lnum': 88,
 46    \     'col': 5,
 47    \     'text': 'expected 1 blank line, found 0',
 48    \     'code': 'E301',
 49    \     'type': 'E',
 50    \     'sub_type': 'style',
 51    \   },
 52    \   {
 53    \     'lnum': 222,
 54    \     'col': 34,
 55    \     'text': 'deprecated form of raising exception',
 56    \     'code': 'W602',
 57    \     'type': 'W',
 58    \     'sub_type': 'style',
 59    \   },
 60    \   {
 61    \     'lnum': 544,
 62    \     'col': 21,
 63    \     'text': '.has_key() is deprecated, use ''in''',
 64    \     'code': 'W601',
 65    \     'type': 'W',
 66    \     'sub_type': 'style',
 67    \   },
 68    \ ],
 69    \ ale_linters#python#pycodestyle#Handle(bufnr(''), [
 70    \   'stdin:8:3: E999 SyntaxError: invalid syntax',
 71    \   'stdin:69:11: E401 multiple imports on one line',
 72    \   'stdin:77:1: E302 expected 2 blank lines, found 1',
 73    \   'stdin:88:5: E301 expected 1 blank line, found 0',
 74    \   'stdin:222:34: W602 deprecated form of raising exception',
 75    \   'example.py:544:21: W601 .has_key() is deprecated, use ''in''',
 76    \ ])
 77  
 78  Execute(Warnings about trailing whitespace should be reported by default):
 79    AssertEqual
 80    \ [
 81    \   {
 82    \     'lnum': 6,
 83    \     'col': 1,
 84    \     'code': 'W291',
 85    \     'type': 'W',
 86    \     'sub_type': 'style',
 87    \     'text': 'who cares',
 88    \   },
 89    \   {
 90    \     'lnum': 6,
 91    \     'col': 1,
 92    \     'code': 'W293',
 93    \     'type': 'W',
 94    \     'sub_type': 'style',
 95    \     'text': 'who cares',
 96    \   },
 97    \ ],
 98    \ ale_linters#python#pycodestyle#Handle(bufnr(''), [
 99    \   'foo.py:6:1: W291 who cares',
100    \   'foo.py:6:1: W293 who cares',
101    \ ])
102  
103  Execute(Disabling trailing whitespace warnings should work):
104    let b:ale_warn_about_trailing_whitespace = 0
105  
106    AssertEqual
107    \ [
108    \ ],
109    \ ale_linters#python#pycodestyle#Handle(bufnr(''), [
110    \   'foo.py:6:1: W291 who cares',
111    \   'foo.py:6:1: W293 who cares',
112    \ ])
113  
114  Execute(Warnings about trailing blank lines should be reported by default):
115    AssertEqual
116    \ [
117    \   {
118    \     'lnum': 6,
119    \     'col': 1,
120    \     'code': 'W391',
121    \     'type': 'W',
122    \     'sub_type': 'style',
123    \     'text': 'blank line at end of file',
124    \   },
125    \ ],
126    \ ale_linters#python#pycodestyle#Handle(bufnr(''), [
127    \   'foo.py:6:1: W391 blank line at end of file',
128    \ ])
129  
130  Execute(Disabling trailing blank line warnings should work):
131    let b:ale_warn_about_trailing_blank_lines = 0
132  
133    AssertEqual
134    \ [
135    \ ],
136    \ ale_linters#python#pycodestyle#Handle(bufnr(''), [
137    \   'foo.py:6:1: W391 blank line at end of file',
138    \ ])
139  
140  Execute(E112 should be a syntax error):
141    AssertEqual
142    \ [
143    \   {
144    \     'lnum': 6,
145    \     'col': 1,
146    \     'code': 'E112',
147    \     'type': 'E',
148    \     'text': 'expected an indented block',
149    \   },
150    \ ],
151    \ ale_linters#python#pycodestyle#Handle(bufnr(''), [
152    \   'foo.py:6:1: E112 expected an indented block',
153    \ ])