summaryrefslogtreecommitdiff
path: root/test/linter/test_pyright.vader
blob: c81ab4b4e7bec407fe8cf69317b041ba08ded876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Before:
  call ale#assert#SetUpLinterTest('python', 'pyright')
  Save b:ale_python_auto_virtualenv

  let b:bin_dir = has('win32') ? 'Scripts' : 'bin'

After:
  unlet! b:bin_dir
  unlet! b:venv_bin
  unlet! b:sep
  unlet! b:executable

  call ale#assert#TearDownLinterTest()

Execute(The command callback should return the correct default string):
  call ale#test#SetFilename('./foo.py')

  AssertLinter
  \ 'pyright-langserver',
  \ ale#Escape('pyright-langserver') . ' --stdio'

Execute(The executable should be configurable):
  let g:ale_python_pyright_executable = '/bin/foo-bar'

  AssertLinter
  \ '/bin/foo-bar',
  \ ale#Escape('/bin/foo-bar') . ' --stdio'

Execute(The default configuration should be mostly empty):
  " The default configuration needs to have at least one key in it,
  " or the server won't start up properly.
  AssertLSPConfig {'python': {}}

  let b:ale_python_pyright_config = {}

  AssertLSPConfig {'python': {}}

Execute(The cwd and project root should be detected correctly):
  call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')

  AssertLinterCwd ale#test#GetFilename('../test-files/python/with_virtualenv/subdir')
  AssertLSPProject ale#test#GetFilename('../test-files/python/with_virtualenv/subdir')

Execute(virtualenv paths should be set in configuration by default):
  call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')

  AssertLSPConfig {
  \ 'python': {
  \   'pythonPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/python'),
  \   'venvPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env'),
  \ },
  \}

Execute(The pythonPath should be set based on whatever the override for the venvPath is set to):
  call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')

  " This overrides the default detection of the path.
  let b:ale_python_pyright_config = {
  \ 'python': {
  \   'venvPath': '/foo/bar',
  \ },
  \}

  AssertLSPConfig {
  \ 'python': {
  \   'pythonPath': ale#path#Simplify('/foo/bar/' . b:bin_dir . '/python'),
  \   'venvPath': '/foo/bar',
  \ },
  \}

Execute(You should be able to override pythonPath when venvPath is detected):
  call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')

  " This overrides the default detection of the path.
  let b:ale_python_pyright_config = {
  \ 'python': {
  \   'pythonPath': '/bin/python',
  \ },
  \}

  AssertLSPConfig {
  \ 'python': {
  \   'pythonPath': '/bin/python',
  \   'venvPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env'),
  \ },
  \}

Execute(You should be able to override both pythonPath and venvPath):
  call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')

  " This overrides the default detection of the path.
  let b:ale_python_pyright_config = {
  \ 'python': {
  \   'pythonPath': '/bin/python',
  \   'venvPath': '/other/dir',
  \ },
  \}

  AssertLSPConfig {
  \ 'python': {
  \   'pythonPath': '/bin/python',
  \   'venvPath': '/other/dir',
  \ },
  \}

Execute(You should be able to define other settings):
  call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')

  let b:ale_python_pyright_config = {
  \ 'python': {
  \   'analysis': {'logLevel': 'warning'},
  \ },
  \ 'pyright': {
  \   'disableLanguageServices': v:true,
  \ },
  \}

  AssertLSPConfig {
  \ 'python': {
  \   'analysis': {'logLevel': 'warning'},
  \   'pythonPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/python'),
  \   'venvPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env'),
  \ },
  \ 'pyright': {
  \   'disableLanguageServices': v:true,
  \ },
  \}

Execute(The pyright callbacks should detect virtualenv directories):
  call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')

  let b:executable = ale#path#Simplify(
  \ g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/pyright-langserver'
  \)

  AssertLinter b:executable, ale#Escape(b:executable) . ' --stdio'

Execute(virtualenv vars should be used when ale_python_auto_virtualenv = 1):
  let b:ale_python_auto_virtualenv = 1
  call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')

  let b:venv_bin = ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir)
  let b:sep = has('win32') ? ';' : ':'
  let b:executable = ale#path#Simplify(b:venv_bin . '/pyright-langserver')

  AssertLinter b:executable, ale#Env('PATH', b:venv_bin . b:sep . $PATH)
  \   . ale#Escape(b:executable) . ' --stdio'

Execute(Setting executable to 'pipenv' should append 'run pyright'):
  call ale#test#SetFilename('../test-files')

  let g:ale_python_pyright_executable = 'path/to/pipenv'

  GivenCommandOutput []
  AssertLinter 'path/to/pipenv',
  \ ale#Escape('path/to/pipenv') . ' run pyright --stdio'

Execute(Pipenv is detected when python_pyright_auto_pipenv is set):
  let g:ale_python_pyright_auto_pipenv = 1
  call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')

  AssertLinterCwd ale#python#FindProjectRootIni(bufnr(''))
  AssertLinter 'pipenv',
  \ ale#Escape('pipenv') . ' run pyright --stdio'

Execute(Setting executable to 'poetry' should append 'run pyright'):
  let g:ale_python_pyright_executable = 'path/to/poetry'

  GivenCommandOutput []
  AssertLinter 'path/to/poetry',
  \ ale#Escape('path/to/poetry') . ' run pyright --stdio'

Execute(poetry is detected when python_pyright_auto_poetry is set):
  let g:ale_python_pyright_auto_poetry = 1
  call ale#test#SetFilename('../test-files/python/poetry/whatever.py')

  AssertLinterCwd ale#python#FindProjectRootIni(bufnr(''))
  AssertLinter 'poetry',
  \ ale#Escape('poetry') . ' run pyright --stdio'