2020-08-07 11:16:13 +00:00
|
|
|
Before:
|
|
|
|
call ale#assert#SetUpLinterTest('python', 'pyright')
|
2023-02-08 09:11:31 +00:00
|
|
|
Save b:ale_python_auto_virtualenv
|
2020-08-07 11:16:13 +00:00
|
|
|
|
|
|
|
let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
|
|
|
|
|
|
|
|
After:
|
|
|
|
unlet! b:bin_dir
|
2023-02-08 09:11:31 +00:00
|
|
|
unlet! b:venv_bin
|
|
|
|
unlet! b:sep
|
2020-08-07 11:16:13 +00:00
|
|
|
unlet! b:executable
|
|
|
|
|
2023-02-08 09:25:15 +00:00
|
|
|
call ale#test#SetFilename('..')
|
2020-08-07 11:16:13 +00:00
|
|
|
call ale#assert#TearDownLinterTest()
|
|
|
|
|
|
|
|
Execute(The command callback should return the correct default string):
|
2022-12-24 13:28:08 +00:00
|
|
|
call ale#test#SetFilename('./foo.py')
|
|
|
|
|
2020-08-07 11:16:13 +00:00
|
|
|
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': {}}
|
|
|
|
|
2022-12-24 13:28:08 +00:00
|
|
|
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')
|
|
|
|
|
2020-08-07 11:16:13 +00:00
|
|
|
Execute(virtualenv paths should be set in configuration by default):
|
2021-03-20 22:11:22 +00:00
|
|
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
2020-08-07 11:16:13 +00:00
|
|
|
|
|
|
|
AssertLSPConfig {
|
|
|
|
\ 'python': {
|
2021-03-20 22:11:22 +00:00
|
|
|
\ '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'),
|
2020-08-07 11:16:13 +00:00
|
|
|
\ },
|
|
|
|
\}
|
|
|
|
|
2022-10-29 11:56:09 +00:00
|
|
|
Execute(The pythonPath should be set based on whatever the override for the venvPath is set to):
|
2021-03-20 22:11:22 +00:00
|
|
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
2020-08-07 11:16:13 +00:00
|
|
|
|
|
|
|
" 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):
|
2021-03-20 22:11:22 +00:00
|
|
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
2020-08-07 11:16:13 +00:00
|
|
|
|
|
|
|
" This overrides the default detection of the path.
|
|
|
|
let b:ale_python_pyright_config = {
|
|
|
|
\ 'python': {
|
|
|
|
\ 'pythonPath': '/bin/python',
|
|
|
|
\ },
|
|
|
|
\}
|
|
|
|
|
|
|
|
AssertLSPConfig {
|
|
|
|
\ 'python': {
|
|
|
|
\ 'pythonPath': '/bin/python',
|
2021-03-20 22:11:22 +00:00
|
|
|
\ 'venvPath': ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env'),
|
2020-08-07 11:16:13 +00:00
|
|
|
\ },
|
|
|
|
\}
|
|
|
|
|
|
|
|
Execute(You should be able to override both pythonPath and venvPath):
|
2021-03-20 22:11:22 +00:00
|
|
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
2020-08-07 11:16:13 +00:00
|
|
|
|
|
|
|
" 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):
|
2021-03-20 22:11:22 +00:00
|
|
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
2020-08-07 11:16:13 +00:00
|
|
|
|
|
|
|
let b:ale_python_pyright_config = {
|
|
|
|
\ 'python': {
|
|
|
|
\ 'analysis': {'logLevel': 'warning'},
|
|
|
|
\ },
|
|
|
|
\ 'pyright': {
|
|
|
|
\ 'disableLanguageServices': v:true,
|
|
|
|
\ },
|
|
|
|
\}
|
|
|
|
|
|
|
|
AssertLSPConfig {
|
|
|
|
\ 'python': {
|
|
|
|
\ 'analysis': {'logLevel': 'warning'},
|
2021-03-20 22:11:22 +00:00
|
|
|
\ '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'),
|
2020-08-07 11:16:13 +00:00
|
|
|
\ },
|
|
|
|
\ 'pyright': {
|
|
|
|
\ 'disableLanguageServices': v:true,
|
|
|
|
\ },
|
|
|
|
\}
|
2023-02-08 08:24:16 +00:00
|
|
|
|
|
|
|
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'
|
|
|
|
|
2023-02-08 09:11:31 +00:00
|
|
|
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')
|
|
|
|
|
2023-03-07 01:59:05 +00:00
|
|
|
AssertLinter b:executable, ale#python#AutoVirtualenvEnvString(bufnr(''))
|
2023-02-08 09:11:31 +00:00
|
|
|
\ . ale#Escape(b:executable) . ' --stdio'
|
2023-03-07 01:59:05 +00:00
|
|
|
Assert !empty(ale#python#AutoVirtualenvEnvString(bufnr('')))
|
2023-02-08 09:11:31 +00:00
|
|
|
|
2023-04-12 23:54:49 +00:00
|
|
|
Execute(Setting executable to 'pipenv' should append 'run pyright-langserver'):
|
2023-02-08 08:24:16 +00:00
|
|
|
call ale#test#SetFilename('../test-files')
|
|
|
|
|
|
|
|
let g:ale_python_pyright_executable = 'path/to/pipenv'
|
|
|
|
|
|
|
|
GivenCommandOutput []
|
|
|
|
AssertLinter 'path/to/pipenv',
|
2023-04-12 23:54:49 +00:00
|
|
|
\ ale#Escape('path/to/pipenv') . ' run pyright-langserver --stdio'
|
2023-02-08 08:24:16 +00:00
|
|
|
|
|
|
|
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',
|
2023-04-12 23:54:49 +00:00
|
|
|
\ ale#Escape('pipenv') . ' run pyright-langserver --stdio'
|
2023-02-08 08:24:16 +00:00
|
|
|
|
2023-04-12 23:54:49 +00:00
|
|
|
Execute(Setting executable to 'poetry' should append 'run pyright-langserver'):
|
2023-02-08 08:24:16 +00:00
|
|
|
let g:ale_python_pyright_executable = 'path/to/poetry'
|
|
|
|
|
|
|
|
GivenCommandOutput []
|
|
|
|
AssertLinter 'path/to/poetry',
|
2023-04-12 23:54:49 +00:00
|
|
|
\ ale#Escape('path/to/poetry') . ' run pyright-langserver --stdio'
|
2023-02-08 08:24:16 +00:00
|
|
|
|
|
|
|
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',
|
2023-04-12 23:54:49 +00:00
|
|
|
\ ale#Escape('poetry') . ' run pyright-langserver --stdio'
|
2024-09-05 06:37:30 +00:00
|
|
|
|
|
|
|
Execute(uv is detected when python_pyright_auto_uv is set):
|
|
|
|
let g:ale_python_pyright_auto_uv = 1
|
|
|
|
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
|
|
|
|
|
|
|
|
AssertLinter 'uv',
|
|
|
|
\ ale#Escape('uv') . ' run pyright-langserver --stdio'
|