]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/linter/test_flake8.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / test / linter / test_flake8.vader
1 Before:
2   call ale#assert#SetUpLinterTest('python', 'flake8')
3
4   let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
5
6   GivenCommandOutput ['3.0.0']
7
8 After:
9   unlet! b:executable
10   unlet! b:bin_dir
11   call ale#assert#TearDownLinterTest()
12
13 Execute(The flake8 callbacks should return the correct default values):
14   AssertLinter 'flake8', [
15   \ ale#Escape('flake8') . ' --version',
16   \ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
17   \]
18
19   " The version check should be cached.
20   GivenCommandOutput []
21   AssertLinter 'flake8', [
22   \ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
23   \]
24
25   " Try with older versions.
26   call ale#semver#ResetVersionCache()
27   GivenCommandOutput ['2.9.9']
28   AssertLinter 'flake8', [
29   \ ale#Escape('flake8') . ' --version',
30   \ ale#Escape('flake8') . ' --format=default -',
31   \]
32
33 Execute(The option for disabling changing directories should work):
34   let g:ale_python_flake8_change_directory = 'off'
35
36   AssertLinterCwd ['', '']
37   call ale#semver#ResetVersionCache()
38   AssertLinter 'flake8', [
39   \ ale#Escape('flake8') . ' --version',
40   \ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
41   \]
42
43   let g:ale_python_flake8_change_directory = 0
44
45   AssertLinterCwd ['']
46   AssertLinter 'flake8', [
47   \ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
48   \]
49
50   " Invalid options should be considered the same as turning the setting off.
51   let g:ale_python_flake8_change_directory = 'xxx'
52
53   AssertLinterCwd ['']
54   AssertLinter 'flake8', [
55   \ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
56   \]
57
58 Execute(The option for changing directory to project root should work):
59   call ale#test#SetFilename('../test-files/python/namespace_package_tox/namespace/foo/bar.py')
60
61   AssertLinterCwd ale#python#FindProjectRootIni(bufnr(''))
62   call ale#semver#ResetVersionCache()
63   AssertLinter 'flake8', [
64   \ ale#Escape('flake8') . ' --version',
65   \ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
66   \]
67
68 Execute(The option for changing directory to file dir should work):
69   let g:ale_python_flake8_change_directory = 'file'
70   call ale#test#SetFilename('../test-files/python/namespace_package_tox/namespace/foo/bar.py')
71
72   AssertLinter 'flake8', [
73   \ ale#Escape('flake8') . ' --version',
74   \ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
75   \]
76
77   let g:ale_python_flake8_change_directory = 1
78
79   AssertLinter 'flake8', [
80   \ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
81   \]
82
83 Execute(The flake8 command callback should let you set options):
84   let g:ale_python_flake8_options = '--some-option'
85
86   GivenCommandOutput ['3.0.4']
87   AssertLinter 'flake8', [
88   \ ale#Escape('flake8') . ' --version',
89   \ ale#Escape('flake8') . ' --some-option'
90   \   . ' --format=default --stdin-display-name %s -',
91   \]
92
93   call ale#semver#ResetVersionCache()
94   GivenCommandOutput ['2.9.9']
95   AssertLinter 'flake8', [
96   \ ale#Escape('flake8') . ' --version',
97   \ ale#Escape('flake8') . ' --some-option --format=default -',
98   \]
99
100 Execute(You should be able to set a custom executable and it should be escaped):
101   call ale#test#SetFilename('../test-files/dummy')
102
103   let g:ale_python_flake8_executable = 'executable with spaces'
104
105   AssertLinterCwd ['%s:h', '%s:h']
106   call ale#semver#ResetVersionCache()
107   AssertLinter 'executable with spaces', [
108   \ ale#Escape('executable with spaces') . ' --version',
109   \ ale#Escape('executable with spaces')
110   \   . ' --format=default'
111   \   . ' --stdin-display-name %s -',
112   \]
113
114 Execute(The flake8 callbacks should detect virtualenv directories):
115   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
116
117   let b:executable = ale#path#Simplify(
118   \ g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/flake8'
119   \)
120
121   AssertLinter b:executable, [
122   \ ale#Escape(b:executable) . ' --version',
123   \ ale#Escape(b:executable)
124   \   . ' --format=default'
125   \   . ' --stdin-display-name %s -',
126   \]
127
128 Execute(The FindProjectRoot should detect the project root directory for namespace package via Manifest.in):
129   call ale#test#SetFilename('../test-files/python/namespace_package_manifest/namespace/foo/bar.py')
130
131   AssertEqual
132   \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_manifest'),
133   \ ale#python#FindProjectRoot(bufnr(''))
134
135 Execute(The FindProjectRoot should detect the project root directory for namespace package via setup.cf):
136   call ale#test#SetFilename('../test-files/python/namespace_package_setup/namespace/foo/bar.py')
137
138   AssertEqual
139   \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_setup'),
140   \ ale#python#FindProjectRoot(bufnr(''))
141
142 Execute(The FindProjectRoot should detect the project root directory for namespace package via pytest.ini):
143   call ale#test#SetFilename('../test-files/python/namespace_package_pytest/namespace/foo/bar.py')
144
145   AssertEqual
146   \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_pytest'),
147   \ ale#python#FindProjectRoot(bufnr(''))
148
149 Execute(The FindProjectRoot should detect the project root directory for namespace package via tox.ini):
150   call ale#test#SetFilename('../test-files/python/namespace_package_tox/namespace/foo/bar.py')
151
152   AssertEqual
153   \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_tox'),
154   \ ale#python#FindProjectRoot(bufnr(''))
155
156 Execute(The FindProjectRoot should detect the project root directory for non-namespace package):
157   call ale#test#SetFilename('../test-files/python/no_virtualenv/subdir/foo/bar.py')
158
159   AssertEqual
160   \ ale#path#Simplify(g:dir . '/../test-files/python/no_virtualenv/subdir'),
161   \ ale#python#FindProjectRoot(bufnr(''))
162
163 " Some users currently run flake8 this way, so we should support it.
164 Execute(Using `python -m flake8` should be supported for running flake8):
165   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
166
167   let g:ale_python_flake8_executable = 'python'
168   let g:ale_python_flake8_options = '-m flake8 --some-option'
169
170   GivenCommandOutput ['2.9.9']
171   AssertLinter 'python', [
172   \ ale#Escape('python') . ' -m flake8 --version',
173   \ ale#Escape('python')
174   \   . ' -m flake8 --some-option --format=default -'
175   \]
176
177   call ale#semver#ResetVersionCache()
178
179   " Leading spaces shouldn't matter
180   let g:ale_python_flake8_options = '  -m flake8 --some-option'
181
182   GivenCommandOutput ['2.9.9']
183   AssertLinter 'python', [
184   \ ale#Escape('python') . ' -m flake8 --version',
185   \ ale#Escape('python')
186   \   . '   -m flake8 --some-option --format=default -'
187   \]
188
189 Execute(Setting executable to 'pipenv' should append 'run flake8'):
190   let g:ale_python_flake8_executable = 'path/to/pipenv'
191
192   " FIXME: pipenv should check the version with flake8.
193   GivenCommandOutput []
194   AssertLinter 'path/to/pipenv',
195   \ ale#Escape('path/to/pipenv') . ' run flake8 --format=default -'
196
197 Execute(Pipenv is detected when python_flake8_auto_pipenv is set):
198   let g:ale_python_flake8_auto_pipenv = 1
199   call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
200
201   AssertLinterCwd ale#python#FindProjectRootIni(bufnr(''))
202   AssertLinter 'pipenv',
203   \ ale#Escape('pipenv') . ' run flake8 --format=default --stdin-display-name %s -'
204
205 Execute(Setting executable to 'poetry' should append 'run flake8'):
206   let g:ale_python_flake8_executable = 'path/to/poetry'
207
208   " FIXME: poetry should check the version with flake8.
209   GivenCommandOutput []
210   AssertLinter 'path/to/poetry',
211   \ ale#Escape('path/to/poetry') . ' run flake8 --format=default -'
212
213 Execute(poetry is detected when python_flake8_auto_poetry is set):
214   let g:ale_python_flake8_auto_poetry = 1
215   call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
216
217   AssertLinterCwd ale#python#FindProjectRootIni(bufnr(''))
218   AssertLinter 'poetry',
219   \ ale#Escape('poetry') . ' run flake8 --format=default --stdin-display-name %s -'
220
221 Execute(uv is detected when python_flake8_auto_uv is set):
222   let g:ale_python_flake8_auto_uv = 1
223   call ale#test#SetFilename('../test-files/python/uv/whatever.py')
224
225   AssertLinter 'uv',
226   \ ale#Escape('uv') . ' run flake8 --format=default --stdin-display-name %s -'