/ test / handler / test_prospector_handler.vader
test_prospector_handler.vader
  1  Before:
  2    Save g:ale_warn_about_trailing_whitespace
  3  
  4    let g:ale_warn_about_trailing_whitespace = 1
  5  
  6    runtime ale_linters/python/prospector.vim
  7  
  8  After:
  9    Restore
 10  
 11    call ale#linter#Reset()
 12  
 13  Execute(Basic prospector errors should be handle):
 14    AssertEqual
 15    \ [
 16    \   {
 17    \     'lnum': 20,
 18    \     'col': 1,
 19    \     'text': 'Trailing whitespace',
 20    \     'code': '(pylint) trailing-whitespace',
 21    \     'type': 'E',
 22    \   },
 23    \   {
 24    \     'lnum': 1,
 25    \     'col': 1,
 26    \     'text': 'Missing module docstring',
 27    \     'code': '(pylint) missing-docstring',
 28    \     'type': 'E',
 29    \   },
 30    \   {
 31    \     'lnum': 2,
 32    \     'col': 1,
 33    \     'text': 'Missing function docstring',
 34    \     'code': '(pylint) missing-docstring',
 35    \     'type': 'E',
 36    \   },
 37    \   {
 38    \     'lnum': 3,
 39    \     'col': 5,
 40    \     'text': '''break'' not properly in loop',
 41    \     'code': '(pylint) not-in-loop',
 42    \     'type': 'E',
 43    \   },
 44    \   {
 45    \     'lnum': 4,
 46    \     'col': 5,
 47    \     'text': 'Unreachable code',
 48    \     'code': '(pylint) unreachable',
 49    \     'type': 'E',
 50    \   },
 51    \   {
 52    \     'lnum': 7,
 53    \     'col': 33,
 54    \     'text': 'No exception type(s) specified',
 55    \     'code': '(pylint) bare-except',
 56    \     'type': 'E',
 57    \   },
 58    \ ],
 59    \ ale_linters#python#prospector#Handle(bufnr(''), [
 60    \ '{',
 61    \ '  "messages": [',
 62    \ '    {',
 63    \ '      "source": "pylint",',
 64    \ '      "code": "trailing-whitespace",',
 65    \ '      "message": "Trailing whitespace",',
 66    \ '      "location": {',
 67    \ '        "character": 0,',
 68    \ '        "line": 20',
 69    \ '      }',
 70    \ '    },',
 71    \ '    {',
 72    \ '      "source": "pylint",',
 73    \ '      "code": "missing-docstring",',
 74    \ '      "message": "Missing module docstring",',
 75    \ '      "location": {',
 76    \ '        "character": 0,',
 77    \ '        "line": 1',
 78    \ '      }',
 79    \ '    },',
 80    \ '    {',
 81    \ '      "source": "pylint",',
 82    \ '      "code": "missing-docstring",',
 83    \ '      "message": "Missing function docstring",',
 84    \ '      "location": {',
 85    \ '        "character": 0,',
 86    \ '        "line": 2',
 87    \ '      }',
 88    \ '    },',
 89    \ '    {',
 90    \ '      "source": "pylint",',
 91    \ '      "code": "not-in-loop",',
 92    \ '      "message": "''break'' not properly in loop",',
 93    \ '      "location": {',
 94    \ '        "character": 4,',
 95    \ '        "line": 3',
 96    \ '      }',
 97    \ '    },',
 98    \ '    {',
 99    \ '      "source": "pylint",',
100    \ '      "code": "unreachable",',
101    \ '      "message": "Unreachable code",',
102    \ '      "location": {',
103    \ '        "character": 4,',
104    \ '        "line": 4',
105    \ '      }',
106    \ '    },',
107    \ '    {',
108    \ '      "source": "pylint",',
109    \ '      "code": "bare-except",',
110    \ '      "message": "No exception type(s) specified",',
111    \ '      "location": {',
112    \ '        "character": 32,',
113    \ '        "line": 7',
114    \ '      }',
115    \ '    }',
116    \ '  ]',
117    \ '}',
118    \ ])
119  
120  Execute(Ignoring trailing whitespace messages should work):
121    let g:ale_warn_about_trailing_whitespace = 0
122  
123    AssertEqual
124    \ [
125    \   {
126    \     'lnum': 1,
127    \     'col': 1,
128    \     'text': 'Missing module docstring',
129    \     'code': '(pylint) missing-docstring',
130    \     'type': 'E',
131    \   },
132    \ ],
133    \ ale_linters#python#prospector#Handle(bufnr(''), [
134    \ '{',
135    \ '  "messages": [',
136    \ '    {',
137    \ '      "source": "pylint",',
138    \ '      "code": "trailing-whitespace",',
139    \ '      "message": "Trailing whitespace",',
140    \ '      "location": {',
141    \ '        "character": 0,',
142    \ '        "line": 4',
143    \ '      }',
144    \ '    },',
145    \ '    {',
146    \ '      "source": "pylint",',
147    \ '      "code": "missing-docstring",',
148    \ '      "message": "Missing module docstring",',
149    \ '      "location": {',
150    \ '        "character": 0,',
151    \ '        "line": 1',
152    \ '      }',
153    \ '    }',
154    \ '  ]',
155    \ '}',
156    \ ])
157  
158  Execute(The prospector handler should handle empty output):
159    AssertEqual
160    \ [],
161    \ ale_linters#python#prospector#Handle(bufnr(''), [])