]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/linter/test_pyright.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:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / linter / test_pyright.vader
1 Before:
2   call ale#assert#SetUpLinterTest('python', 'pyright')
3   Save b:ale_python_auto_virtualenv
4
5   let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
6
7 After:
8   unlet! b:bin_dir
9   unlet! b:venv_bin
10   unlet! b:sep
11   unlet! b:executable
12
13   call ale#test#SetFilename('..')
14   call ale#assert#TearDownLinterTest()
15
16 Execute(The command callback should return the correct default string):
17   call ale#test#SetFilename('./foo.py')
18
19   AssertLinter
20   \ 'pyright-langserver',
21   \ ale#Escape('pyright-langserver') . ' --stdio'
22
23 Execute(The executable should be configurable):
24   let g:ale_python_pyright_executable = '/bin/foo-bar'
25
26   AssertLinter
27   \ '/bin/foo-bar',
28   \ ale#Escape('/bin/foo-bar') . ' --stdio'
29
30 Execute(The default configuration should be mostly empty):
31   " The default configuration needs to have at least one key in it,
32   " or the server won't start up properly.
33   AssertLSPConfig {'python': {}}
34
35   let b:ale_python_pyright_config = {}
36
37   AssertLSPConfig {'python': {}}
38
39 Execute(The cwd and project root should be detected correctly):
40   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
41
42   AssertLinterCwd ale#test#GetFilename('../test-files/python/with_virtualenv/subdir')
43   AssertLSPProject ale#test#GetFilename('../test-files/python/with_virtualenv/subdir')
44
45 Execute(virtualenv paths should be set in configuration by default):
46   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
47
48   AssertLSPConfig {
49   \ 'python': {
50   \   'pythonPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/python'),
51   \   'venvPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env'),
52   \ },
53   \}
54
55 Execute(The pythonPath should be set based on whatever the override for the venvPath is set to):
56   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
57
58   " This overrides the default detection of the path.
59   let b:ale_python_pyright_config = {
60   \ 'python': {
61   \   'venvPath': '/foo/bar',
62   \ },
63   \}
64
65   AssertLSPConfig {
66   \ 'python': {
67   \   'pythonPath': ale#path#Simplify('/foo/bar/' . b:bin_dir . '/python'),
68   \   'venvPath': '/foo/bar',
69   \ },
70   \}
71
72 Execute(You should be able to override pythonPath when venvPath is detected):
73   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
74
75   " This overrides the default detection of the path.
76   let b:ale_python_pyright_config = {
77   \ 'python': {
78   \   'pythonPath': '/bin/python',
79   \ },
80   \}
81
82   AssertLSPConfig {
83   \ 'python': {
84   \   'pythonPath': '/bin/python',
85   \   'venvPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env'),
86   \ },
87   \}
88
89 Execute(You should be able to override both pythonPath and venvPath):
90   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
91
92   " This overrides the default detection of the path.
93   let b:ale_python_pyright_config = {
94   \ 'python': {
95   \   'pythonPath': '/bin/python',
96   \   'venvPath': '/other/dir',
97   \ },
98   \}
99
100   AssertLSPConfig {
101   \ 'python': {
102   \   'pythonPath': '/bin/python',
103   \   'venvPath': '/other/dir',
104   \ },
105   \}
106
107 Execute(You should be able to define other settings):
108   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
109
110   let b:ale_python_pyright_config = {
111   \ 'python': {
112   \   'analysis': {'logLevel': 'warning'},
113   \ },
114   \ 'pyright': {
115   \   'disableLanguageServices': v:true,
116   \ },
117   \}
118
119   AssertLSPConfig {
120   \ 'python': {
121   \   'analysis': {'logLevel': 'warning'},
122   \   'pythonPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/python'),
123   \   'venvPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env'),
124   \ },
125   \ 'pyright': {
126   \   'disableLanguageServices': v:true,
127   \ },
128   \}
129
130 Execute(The pyright callbacks should detect virtualenv directories):
131   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
132
133   let b:executable = ale#path#Simplify(
134   \ g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/pyright-langserver'
135   \)
136
137   AssertLinter b:executable, ale#Escape(b:executable) . ' --stdio'
138
139 Execute(virtualenv vars should be used when ale_python_auto_virtualenv = 1):
140   let b:ale_python_auto_virtualenv = 1
141   call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
142
143   let b:venv_bin = ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir)
144   let b:sep = has('win32') ? ';' : ':'
145   let b:executable = ale#path#Simplify(b:venv_bin . '/pyright-langserver')
146
147   AssertLinter b:executable, ale#python#AutoVirtualenvEnvString(bufnr(''))
148   \   . ale#Escape(b:executable) . ' --stdio'
149   Assert !empty(ale#python#AutoVirtualenvEnvString(bufnr('')))
150
151 Execute(Setting executable to 'pipenv' should append 'run pyright-langserver'):
152   call ale#test#SetFilename('../test-files')
153
154   let g:ale_python_pyright_executable = 'path/to/pipenv'
155
156   GivenCommandOutput []
157   AssertLinter 'path/to/pipenv',
158   \ ale#Escape('path/to/pipenv') . ' run pyright-langserver --stdio'
159
160 Execute(Pipenv is detected when python_pyright_auto_pipenv is set):
161   let g:ale_python_pyright_auto_pipenv = 1
162   call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
163
164   AssertLinterCwd ale#python#FindProjectRootIni(bufnr(''))
165   AssertLinter 'pipenv',
166   \ ale#Escape('pipenv') . ' run pyright-langserver --stdio'
167
168 Execute(Setting executable to 'poetry' should append 'run pyright-langserver'):
169   let g:ale_python_pyright_executable = 'path/to/poetry'
170
171   GivenCommandOutput []
172   AssertLinter 'path/to/poetry',
173   \ ale#Escape('path/to/poetry') . ' run pyright-langserver --stdio'
174
175 Execute(poetry is detected when python_pyright_auto_poetry is set):
176   let g:ale_python_pyright_auto_poetry = 1
177   call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
178
179   AssertLinterCwd ale#python#FindProjectRootIni(bufnr(''))
180   AssertLinter 'poetry',
181   \ ale#Escape('poetry') . ' run pyright-langserver --stdio'
182
183 Execute(uv is detected when python_pyright_auto_uv is set):
184   let g:ale_python_pyright_auto_uv = 1
185   call ale#test#SetFilename('../test-files/python/uv/whatever.py')
186
187   AssertLinter 'uv',
188   \ ale#Escape('uv') . ' run pyright-langserver --stdio'