Skip to content

Commit 088ca77

Browse files
committed
test: more tests, remove windows from test target
1 parent b0ee99d commit 088ca77

8 files changed

Lines changed: 149 additions & 17 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ jobs:
3333
include:
3434
- os: macos-latest
3535
neovim_version: v0.11.3
36-
- os: windows-latest
37-
neovim_version: v0.11.3
36+
# TODO include windows when I have access to test on a windows machine.
37+
# - os: windows-latest
38+
# neovim_version: v0.11.3
3839
runs-on: ${{ matrix.os }}
3940

4041
steps:

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,12 @@ return {
289289

290290
- [x] Linux
291291

292-
- [x] MacOS (Mostly should work)
292+
- [x] MacOS
293293

294-
- [x] I am detecting python interpreters in homebrew and hatch. Does the community use other methods of installing python?
294+
- [x] I am detecting python interpreters in homebrew and hatch and uv. Testing in ci.
295295

296296
- [ ] Windows (Un tested)
297-
- [ ] Most likely spots where we are mixing up `/` vs `\` in paths
297+
- [ ] Need to test this plugin on a windows machine to verify. I have seen online that neovim users are deciding on WezTerm + WSL to handle support for neovim plugins.
298298

299299
## Special Thanks
300300

tests/_test_template.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ local T = new_set({
1414
-- Restart child process with custom 'init.lua' script
1515
child.restart({ '-u', 'scripts/minimal_init.lua' })
1616
-- Load tested plugin
17-
child.lua([[M = require('python')]])
17+
child.lua([[require('python').setup()]])
1818
end,
1919
-- This will be executed one after all tests from this set are finished
2020
post_once = child.stop,

tests/test_interpreters.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
-- Define helper aliases
3+
local new_set = MiniTest.new_set
4+
local expect, eq = MiniTest.expect, MiniTest.expect.equality
5+
6+
-- Create (but not start) child Neovim object
7+
local child = MiniTest.new_child_neovim()
8+
9+
-- Define main test set of this file
10+
local T = new_set({
11+
-- Register hooks
12+
hooks = {
13+
-- This will be executed before every (even nested) case
14+
pre_case = function()
15+
-- Restart child process with custom 'init.lua' script
16+
child.restart({ '-u', 'scripts/minimal_init.lua' })
17+
-- Load tested plugin
18+
child.lua([[require('python').setup()]])
19+
end,
20+
-- This will be executed one after all tests from this set are finished
21+
post_once = child.stop,
22+
},
23+
})
24+
25+
T['interpreters'] = MiniTest.new_set()
26+
27+
T['interpreters']['python'] = function()
28+
child.lua("inter = require('python.venv.interpreters')")
29+
local pythons = child.lua("return inter.python_interpreters()")
30+
assert(#pythons > 0)
31+
end
32+
33+
-- Return test set which will be collected and execute inside `MiniTest.run()`
34+
return T

tests/test_keymap.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-- Define helper aliases
2+
local new_set = MiniTest.new_set
3+
local expect, eq = MiniTest.expect, MiniTest.expect.equality
4+
5+
-- Create (but not start) child Neovim object
6+
local child = MiniTest.new_child_neovim()
7+
8+
-- Define main test set of this file
9+
local T = new_set({
10+
-- Register hooks
11+
hooks = {
12+
-- This will be executed before every (even nested) case
13+
pre_case = function()
14+
-- Restart child process with custom 'init.lua' script
15+
child.restart({ '-u', 'scripts/minimal_init.lua' })
16+
-- Load tested plugin
17+
child.lua([[require('python').setup()]])
18+
end,
19+
-- This will be executed one after all tests from this set are finished
20+
post_once = child.stop,
21+
},
22+
})
23+
24+
-- Keymaps can be loaded
25+
T['keymaps'] = function()
26+
child.cmd("cd examples/python_projects/uv")
27+
child.cmd("e main.py")
28+
local keymap = child.cmd_capture("map <leader>pi")
29+
assert(string.find(keymap, "python venv install", 1, true))
30+
end
31+
32+
-- Return test set which will be collected and execute inside `MiniTest.run()`
33+
return T

tests/test_luasnip.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- Define helper aliases
2+
local new_set = MiniTest.new_set
3+
local expect, eq = MiniTest.expect, MiniTest.expect.equality
4+
5+
-- Create (but not start) child Neovim object
6+
local child = MiniTest.new_child_neovim()
7+
8+
-- Define main test set of this file
9+
local T = new_set({
10+
-- Register hooks
11+
hooks = {
12+
-- This will be executed before every (even nested) case
13+
pre_case = function()
14+
-- Restart child process with custom 'init.lua' script
15+
child.restart({ '-u', 'scripts/minimal_init.lua' })
16+
-- Load tested plugin
17+
child.lua([[require('python').setup({ python_lua_snippets = true })]])
18+
end,
19+
-- This will be executed one after all tests from this set are finished
20+
post_once = child.stop,
21+
},
22+
})
23+
24+
T['snips will load'] = function()
25+
child.lua([[M = require('python.snip')]])
26+
child.lua([[M.load_snippets()]])
27+
eq(child.lua([[return vim.g._python_nvim_snippets_loaded]]), true)
28+
end
29+
30+
-- Return test set which will be collected and execute inside `MiniTest.run()`
31+
return T

tests/test_uv.lua

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- Define helper aliases
2+
local new_set = MiniTest.new_set
3+
local expect, eq = MiniTest.expect, MiniTest.expect.equality
4+
5+
-- Create (but not start) child Neovim object
6+
local child = MiniTest.new_child_neovim()
7+
8+
-- Define main test set of this file
9+
local T = new_set({
10+
-- Register hooks
11+
hooks = {
12+
-- This will be executed before every (even nested) case
13+
pre_case = function()
14+
-- Restart child process with custom 'init.lua' script
15+
child.restart({ '-u', 'scripts/minimal_init.lua' })
16+
-- Load tested plugin
17+
child.lua([[require('python').setup()]])
18+
end,
19+
-- This will be executed one after all tests from this set are finished
20+
post_once = child.stop,
21+
},
22+
})
23+
T['uv'] = MiniTest.new_set({
24+
hooks = {
25+
pre_case = function()
26+
end
27+
}
28+
})
29+
30+
T['uv']['command'] = function()
31+
child.cmd("cd examples/python_projects/uv")
32+
child.cmd("e main.py")
33+
child.cmd([[!rm -rf .venv]])
34+
child.cmd([[UV sync]])
35+
local dir = child.lua("return vim.fn.expand('%:p:h')")
36+
local venv_dir = vim.fs.joinpath(dir, ".venv")
37+
38+
-- give some seconds for uv sync to download package
39+
vim.loop.sleep(3000)
40+
eq(child.lua(("return vim.fn.isdirectory('%s')"):format(venv_dir)), 1)
41+
end
42+
43+
-- Return test set which will be collected and execute inside `MiniTest.run()`
44+
return T

tests/test_venv_create.lua

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ end
3737

3838
-- NOTE: requires uv installed on system
3939
T['create']['uv_sync'] = function()
40-
local IS_WINDOWS = vim.uv.os_uname().sysname == 'Windows_NT'
4140
child.lua("create = require('python.venv.create')")
4241
child.cmd("cd examples/python_projects/uv")
4342
child.cmd("!rm -rf .venv")
@@ -48,19 +47,9 @@ T['create']['uv_sync'] = function()
4847
local dep_path = vim.fn.system(
4948
[[examples/python_projects/uv/.venv/bin/python -c 'import sys; print(sys.path[-1], end="")']])
5049

51-
-- Have to do a special test for windows to check for requests being installed in .venv
52-
if IS_WINDOWS then
53-
print(vim.fn.system([[ dir examples\python_projects\uv\.venv\Lib\site-packages ]]))
54-
print(vim.fn.system([[ cd examples\python_projects\uv && uv sync ]]))
55-
eq(vim.fn.isdirectory([[examples\python_projects\uv\.venv\Lib\site-packages\requests]]), 1)
56-
return
57-
end
58-
59-
print("\ndep_path: " .. dep_path .. "\n")
6050
assert(string.find(dep_path, "python_projects", 1, true))
6151

6252
local check_dir = vim.fs.joinpath(dep_path, "requests")
63-
print("\nchecking: " .. check_dir .. "\n")
6453
eq(vim.fn.isdirectory(check_dir), 1)
6554
end
6655

0 commit comments

Comments
 (0)