summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKevin Locke <kevin@kevinlocke.name>2019-02-08 21:44:34 +0000
committerw0rp <w0rp@users.noreply.github.com>2019-02-08 21:44:34 +0000
commita24f0b4d5f91f9214c64ae281fadcd981e0dadfc (patch)
tree25e07c98b5de66ab70db85b980fcbe9f3675358d /test
parent422908a5721e11be73935b765f599f9fc672802e (diff)
downloadale-a24f0b4d5f91f9214c64ae281fadcd981e0dadfc.zip
Support pylama for python (#2266)
* Add pylama for python * Consolidate python traceback handling
Diffstat (limited to 'test')
-rwxr-xr-xtest/command_callback/python_paths/with_virtualenv/env/Scripts/pylama.exe0
-rwxr-xr-xtest/command_callback/python_paths/with_virtualenv/env/bin/pylama0
-rw-r--r--test/command_callback/test_pylama_command_callback.vader85
-rw-r--r--test/handler/test_flake8_handler.vader2
-rw-r--r--test/handler/test_pylama_handler.vader212
-rw-r--r--test/handler/test_vulture_handler.vader2
-rw-r--r--test/test_python_traceback.vader79
7 files changed, 378 insertions, 2 deletions
diff --git a/test/command_callback/python_paths/with_virtualenv/env/Scripts/pylama.exe b/test/command_callback/python_paths/with_virtualenv/env/Scripts/pylama.exe
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/with_virtualenv/env/Scripts/pylama.exe
diff --git a/test/command_callback/python_paths/with_virtualenv/env/bin/pylama b/test/command_callback/python_paths/with_virtualenv/env/bin/pylama
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/with_virtualenv/env/bin/pylama
diff --git a/test/command_callback/test_pylama_command_callback.vader b/test/command_callback/test_pylama_command_callback.vader
new file mode 100644
index 00000000..a24b55f8
--- /dev/null
+++ b/test/command_callback/test_pylama_command_callback.vader
@@ -0,0 +1,85 @@
+Before:
+ call ale#assert#SetUpLinterTest('python', 'pylama')
+ call ale#test#SetFilename('test.py')
+
+ let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
+ let b:command_tail = ' %t'
+
+After:
+ unlet! b:bin_dir
+ unlet! b:executable
+ unlet! b:command_tail
+
+ call ale#assert#TearDownLinterTest()
+
+Execute(The pylama command callback should return a default):
+ AssertLinter 'pylama',
+ \ ale#path#BufferCdString(bufnr(''))
+ \ . ale#Escape('pylama') . b:command_tail
+
+Execute(The option for disabling changing directories should work):
+ let g:ale_python_pylama_change_directory = 0
+
+ AssertLinter 'pylama', ale#Escape('pylama') . b:command_tail
+
+Execute(The pylama executable should be configurable, and escaped properly):
+ let g:ale_python_pylama_executable = 'executable with spaces'
+
+ AssertLinter 'executable with spaces',
+ \ ale#path#BufferCdString(bufnr(''))
+ \ . ale#Escape('executable with spaces') . b:command_tail
+
+Execute(The pylama command callback should let you set options):
+ let g:ale_python_pylama_options = '--some-option'
+
+ AssertLinter 'pylama',
+ \ ale#path#BufferCdString(bufnr(''))
+ \ . ale#Escape('pylama') . ' --some-option' . b:command_tail
+
+Execute(The pylama command callback should switch directories to the detected project root):
+ silent execute 'file ' . fnameescape(g:dir . '/python_paths/no_virtualenv/subdir/foo/bar.py')
+
+ AssertLinter 'pylama',
+ \ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/no_virtualenv/subdir'))
+ \ . ale#Escape('pylama') . b:command_tail
+
+Execute(The pylama command callback shouldn't detect virtualenv directories where they don't exist):
+ silent execute 'file ' . fnameescape(g:dir . '/python_paths/no_virtualenv/subdir/foo/bar.py')
+
+ AssertLinter 'pylama',
+ \ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/no_virtualenv/subdir'))
+ \ . ale#Escape('pylama') . b:command_tail
+
+Execute(The pylama command callback should detect virtualenv directories and switch to the project root):
+ silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py')
+
+ let b:executable = ale#path#Simplify(
+ \ g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/pylama'
+ \)
+
+ AssertLinter b:executable,
+ \ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir'))
+ \ . ale#Escape(b:executable) . b:command_tail
+
+Execute(You should able able to use the global pylama instead):
+ silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py')
+ let g:ale_python_pylama_use_global = 1
+
+ AssertLinter 'pylama',
+ \ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir'))
+ \ . ale#Escape('pylama') . b:command_tail
+
+Execute(Setting executable to 'pipenv' appends 'run pylama'):
+ let g:ale_python_pylama_executable = 'path/to/pipenv'
+
+ AssertLinter 'path/to/pipenv',
+ \ ale#path#BufferCdString(bufnr(''))
+ \ . ale#Escape('path/to/pipenv') . ' run pylama' . b:command_tail
+
+Execute(Pipenv is detected when python_pylama_auto_pipenv is set):
+ let g:ale_python_pylama_auto_pipenv = 1
+ call ale#test#SetFilename('/testplugin/test/python_fixtures/pipenv/whatever.py')
+
+ AssertLinter 'pipenv',
+ \ ale#path#BufferCdString(bufnr(''))
+ \ . ale#Escape('pipenv') . ' run pylama' . b:command_tail
diff --git a/test/handler/test_flake8_handler.vader b/test/handler/test_flake8_handler.vader
index fe42211a..1c9956fa 100644
--- a/test/handler/test_flake8_handler.vader
+++ b/test/handler/test_flake8_handler.vader
@@ -113,7 +113,7 @@ Execute(The flake8 handler should handle stack traces):
\ [
\ {
\ 'lnum': 1,
- \ 'text': 'An exception was thrown. See :ALEDetail',
+ \ 'text': 'ImportError: No module named parser (See :ALEDetail)',
\ 'detail': join([
\ 'Traceback (most recent call last):',
\ ' File "/usr/local/bin/flake8", line 7, in <module>',
diff --git a/test/handler/test_pylama_handler.vader b/test/handler/test_pylama_handler.vader
new file mode 100644
index 00000000..854765db
--- /dev/null
+++ b/test/handler/test_pylama_handler.vader
@@ -0,0 +1,212 @@
+Before:
+ Save g:ale_warn_about_trailing_whitespace
+
+ let g:ale_warn_about_trailing_whitespace = 1
+
+ runtime ale_linters/python/pylama.vim
+
+After:
+ Restore
+
+ call ale#linter#Reset()
+
+ silent file something_else.py
+
+Execute(The pylama handler should handle no messages):
+ AssertEqual [], ale_linters#python#pylama#Handle(bufnr(''), [])
+
+Execute(The pylama handler should handle basic warnings and syntax errors):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 8,
+ \ 'col': 1,
+ \ 'code': 'W0611',
+ \ 'type': 'W',
+ \ 'sub_type': '',
+ \ 'text': '''foo'' imported but unused [pyflakes]',
+ \ },
+ \ {
+ \ 'lnum': 8,
+ \ 'col': 0,
+ \ 'code': 'E0401',
+ \ 'type': 'E',
+ \ 'sub_type': '',
+ \ 'text': 'Unable to import ''foo'' [pylint]',
+ \ },
+ \ {
+ \ 'lnum': 10,
+ \ 'col': 1,
+ \ 'code': 'E302',
+ \ 'type': 'E',
+ \ 'sub_type': '',
+ \ 'text': 'expected 2 blank lines, found 1 [pycodestyle]',
+ \ },
+ \ {
+ \ 'lnum': 11,
+ \ 'col': 1,
+ \ 'code': 'D401',
+ \ 'type': 'W',
+ \ 'sub_type': 'style',
+ \ 'text': 'First line should be in imperative mood (''Get'', not ''Gets'') [pydocstyle]',
+ \ },
+ \ {
+ \ 'lnum': 15,
+ \ 'col': 81,
+ \ 'code': 'E501',
+ \ 'type': 'E',
+ \ 'sub_type': '',
+ \ 'text': 'line too long (96 > 80 characters) [pycodestyle]',
+ \ },
+ \ {
+ \ 'lnum': 16,
+ \ 'col': 1,
+ \ 'code': 'D203',
+ \ 'type': 'W',
+ \ 'sub_type': 'style',
+ \ 'text': '1 blank line required before class docstring (found 0) [pydocstyle]',
+ \ },
+ \ {
+ \ 'lnum': 18,
+ \ 'col': 1,
+ \ 'code': 'D107',
+ \ 'type': 'W',
+ \ 'sub_type': 'style',
+ \ 'text': 'Missing docstring in __init__ [pydocstyle]',
+ \ },
+ \ {
+ \ 'lnum': 20,
+ \ 'col': 0,
+ \ 'code': 'C4001',
+ \ 'type': 'W',
+ \ 'sub_type': 'style',
+ \ 'text': 'Invalid string quote ", should be '' [pylint]',
+ \ },
+ \ ],
+ \ ale_linters#python#pylama#Handle(bufnr(''), [
+ \ 'No config file found, using default configuration',
+ \ 'index.py:8:1: W0611 ''foo'' imported but unused [pyflakes]',
+ \ 'index.py:8:0: E0401 Unable to import ''foo'' [pylint]',
+ \ 'index.py:10:1: E302 expected 2 blank lines, found 1 [pycodestyle]',
+ \ 'index.py:11:1: D401 First line should be in imperative mood (''Get'', not ''Gets'') [pydocstyle]',
+ \ 'index.py:15:81: E501 line too long (96 > 80 characters) [pycodestyle]',
+ \ 'index.py:16:1: D203 1 blank line required before class docstring (found 0) [pydocstyle]',
+ \ 'index.py:18:1: D107 Missing docstring in __init__ [pydocstyle]',
+ \ 'index.py:20:0: C4001 Invalid string quote ", should be '' [pylint]',
+ \ ])
+
+Execute(The pylama handler should handle tracebacks with parsable messages):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 1,
+ \ 'text': 'ParseError: Cannot parse file. (See :ALEDetail)',
+ \ 'detail': join([
+ \ 'Traceback (most recent call last):',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pylama/core.py", line 66, in run',
+ \ ' path, code=code, ignore=ignore, select=select, params=lparams)',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pylama/lint/pylama_pydocstyle.py", line 37, in run',
+ \ ' } for e in PyDocChecker().check_source(*check_source_args)]',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pydocstyle/checker.py", line 64, in check_source',
+ \ ' module = parse(StringIO(source), filename)',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pydocstyle/parser.py", line 340, in __call__',
+ \ ' return self.parse(*args, **kwargs)',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pydocstyle/parser.py", line 328, in parse',
+ \ ' six.raise_from(ParseError(), error)',
+ \ ' File "/usr/local/lib/python2.7/site-packages/six.py", line 737, in raise_from',
+ \ ' raise value',
+ \ 'ParseError: Cannot parse file.',
+ \ ], "\n"),
+ \ },
+ \ {
+ \ 'lnum': 11,
+ \ 'col': 1,
+ \ 'code': 'E302',
+ \ 'type': 'E',
+ \ 'sub_type': '',
+ \ 'text': 'expected 2 blank lines, found 1 [pycodestyle]',
+ \ },
+ \ {
+ \ 'lnum': 16,
+ \ 'col': 81,
+ \ 'code': 'E501',
+ \ 'type': 'E',
+ \ 'sub_type': '',
+ \ 'text': 'line too long (96 > 80 characters) [pycodestyle]',
+ \ },
+ \ ],
+ \ ale_linters#python#pylama#Handle(bufnr(''), [
+ \ 'Traceback (most recent call last):',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pylama/core.py", line 66, in run',
+ \ ' path, code=code, ignore=ignore, select=select, params=lparams)',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pylama/lint/pylama_pydocstyle.py", line 37, in run',
+ \ ' } for e in PyDocChecker().check_source(*check_source_args)]',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pydocstyle/checker.py", line 64, in check_source',
+ \ ' module = parse(StringIO(source), filename)',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pydocstyle/parser.py", line 340, in __call__',
+ \ ' return self.parse(*args, **kwargs)',
+ \ ' File "/usr/local/lib/python2.7/site-packages/pydocstyle/parser.py", line 328, in parse',
+ \ ' six.raise_from(ParseError(), error)',
+ \ ' File "/usr/local/lib/python2.7/site-packages/six.py", line 737, in raise_from',
+ \ ' raise value',
+ \ 'ParseError: Cannot parse file.',
+ \ '',
+ \ 'index.py:11:1: E302 expected 2 blank lines, found 1 [pycodestyle]',
+ \ 'index.py:16:81: E501 line too long (96 > 80 characters) [pycodestyle]',
+ \ ])
+
+" Note: This is probably a bug, since all pylama plugins produce codes, but
+" should be handled for compatibility.
+" Note: The pylama isort plugin is distributed in the isort package.
+Execute(The pylama handler should handle messages without codes):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 0,
+ \ 'col': 0,
+ \ 'code': '',
+ \ 'type': 'W',
+ \ 'sub_type': '',
+ \ 'text': 'Incorrectly sorted imports. [isort]'
+ \ },
+ \ ],
+ \ ale_linters#python#pylama#Handle(bufnr(''), [
+ \ 'index.py:0:0: Incorrectly sorted imports. [isort]',
+ \ ])
+
+" Note: This is a pylama bug, but should be handled for compatibility.
+" See https://github.com/klen/pylama/pull/146
+Execute(The pylama handler should handle message codes followed by a colon):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 31,
+ \ 'col': 1,
+ \ 'code': 'E800',
+ \ 'type': 'E',
+ \ 'sub_type': '',
+ \ 'text': 'Found commented out code: # needs_sphinx = ''1.0'' [eradicate]',
+ \ },
+ \ ],
+ \ ale_linters#python#pylama#Handle(bufnr(''), [
+ \ 'index.py:31:1: E800: Found commented out code: # needs_sphinx = ''1.0'' [eradicate]',
+ \ ])
+
+" The directory created for %t may not comply with pylint module name config.
+" This should not be reported to users.
+Execute(The pylama handler should ignore C0103 from temp dir, not others):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 29,
+ \ 'col': 0,
+ \ 'code': 'C0103',
+ \ 'type': 'W',
+ \ 'sub_type': 'style',
+ \ 'text': 'Constant name "badname" doesn''t conform to UPPER_CASE naming style [pylint]',
+ \ },
+ \ ],
+ \ ale_linters#python#pylama#Handle(bufnr(''), [
+ \ '../../../../tmp/vmynR33/456/__init__.py:1:0: C0103 Module name "456" doesn''t conform to snake_case naming style [pylint]',
+ \ '../../../../tmp/vmynR33/456/__init__.py:29:0: C0103 Constant name "badname" doesn''t conform to UPPER_CASE naming style [pylint]',
+ \ ])
diff --git a/test/handler/test_vulture_handler.vader b/test/handler/test_vulture_handler.vader
index c6bd7643..b28055db 100644
--- a/test/handler/test_vulture_handler.vader
+++ b/test/handler/test_vulture_handler.vader
@@ -70,7 +70,7 @@ Execute(Vulture exception should be handled):
\ [
\ {
\ 'lnum': 1,
- \ 'text': 'An exception was thrown. See :ALEDetail',
+ \ 'text': 'BaddestException: Everything gone wrong (See :ALEDetail)',
\ 'detail': join([
\ 'Traceback (most recent call last):',
\ ' File "/usr/lib/python3.6/site-packages/vulture/__init__.py", line 13, in <module>',
diff --git a/test/test_python_traceback.vader b/test/test_python_traceback.vader
new file mode 100644
index 00000000..6a659986
--- /dev/null
+++ b/test/test_python_traceback.vader
@@ -0,0 +1,79 @@
+Execute(ale#python#HandleTraceback returns empty List for empty lines):
+ AssertEqual
+ \ [],
+ \ ale#python#HandleTraceback([], 10)
+
+Execute(ale#python#HandleTraceback returns traceback, when present):
+ AssertEqual
+ \ [{
+ \ 'lnum': 1,
+ \ 'text': 'Exception: Example error (See :ALEDetail)',
+ \ 'detail': join([
+ \ 'Traceback (most recent call last):',
+ \ ' File "./example.py", line 5, in <module>',
+ \ ' raise Exception(''Example message'')',
+ \ 'Exception: Example error',
+ \ ], "\n"),
+ \ }],
+ \ ale#python#HandleTraceback([
+ \ 'Traceback (most recent call last):',
+ \ ' File "./example.py", line 5, in <module>',
+ \ ' raise Exception(''Example message'')',
+ \ 'Exception: Example error',
+ \ ], 1)
+
+" SyntaxError has extra output lines about the source
+Execute(ale#python#HandleTraceback returns SyntaxError traceback):
+ AssertEqual
+ \ [{
+ \ 'lnum': 1,
+ \ 'text': 'SyntaxError: invalid syntax (See :ALEDetail)',
+ \ 'detail': join([
+ \ 'Traceback (most recent call last):',
+ \ ' File "<string>", line 1, in <module>',
+ \ ' File "example.py", line 5',
+ \ ' +',
+ \ ' ^',
+ \ 'SyntaxError: invalid syntax',
+ \ ], "\n"),
+ \ }],
+ \ ale#python#HandleTraceback([
+ \ 'Traceback (most recent call last):',
+ \ ' File "<string>", line 1, in <module>',
+ \ ' File "example.py", line 5',
+ \ ' +',
+ \ ' ^',
+ \ 'SyntaxError: invalid syntax',
+ \ ], 1)
+
+Execute(ale#python#HandleTraceback ignores traceback after line limit):
+ AssertEqual
+ \ [],
+ \ ale#python#HandleTraceback([
+ \ '',
+ \ 'Traceback (most recent call last):',
+ \ ' File "./example.py", line 5, in <module>',
+ \ ' raise Exception(''Example message'')',
+ \ 'Exception: Example error',
+ \ ], 1)
+
+Execute(ale#python#HandleTraceback doesn't include later lines in detail):
+ AssertEqual
+ \ [{
+ \ 'lnum': 1,
+ \ 'text': 'Exception: Example error (See :ALEDetail)',
+ \ 'detail': join([
+ \ 'Traceback (most recent call last):',
+ \ ' File "./example.py", line 5, in <module>',
+ \ ' raise Exception(''Example message'')',
+ \ 'Exception: Example error',
+ \ ], "\n"),
+ \ }],
+ \ ale#python#HandleTraceback([
+ \ 'Traceback (most recent call last):',
+ \ ' File "./example.py", line 5, in <module>',
+ \ ' raise Exception(''Example message'')',
+ \ 'Exception: Example error',
+ \ 'file:1:2: Style issue',
+ \ 'file:3:4: Non-style issue',
+ \ ], 1)