@@ -4,12 +4,21 @@ local cwd = vim.fn.getcwd()
44local mock = require (" luassert.mock" )
55
66describe (" find_project_root" , function ()
7+ local function with_temp_fixture (test_name , setup_func , test_func )
8+ local temp_dir = vim .fn .stdpath (" data" ) .. " /pymple_test_tmp/" .. test_name
9+ local Path = require (" plenary.path" )
10+ Path :new (temp_dir ):mkdir ({ parents = true })
11+ setup_func (temp_dir )
12+ test_func (temp_dir )
13+ Path :new (temp_dir ):rm ({ recursive = true })
14+ end
15+
716 it (" src present" , function ()
817 local result = utils .find_project_root (
918 FIXTURES_PATH .. " /project_with_src/src" ,
1019 { " pyproject.toml" }
1120 )
12- assert .equals (FIXTURES_PATH .. " /project_with_src/src " , result )
21+ assert .equals (FIXTURES_PATH .. " /project_with_src" , result )
1322 end )
1423
1524 it (" no src" , function ()
@@ -27,6 +36,39 @@ describe("find_project_root", function()
2736 )
2837 assert .equals (nil , result )
2938 end )
39+
40+ it (" src is a module (with __init__.py)" , function ()
41+ with_temp_fixture (" src_as_module" , function (temp_dir )
42+ local Path = require (" plenary.path" )
43+ local project_root = Path :new (temp_dir )
44+ local src_dir = project_root :joinpath (" src" )
45+ src_dir :mkdir ({ parents = true })
46+ src_dir :joinpath (" __init__.py" ):touch ()
47+ project_root :joinpath (" pyproject.toml" ):touch ()
48+ end , function (temp_dir )
49+ local result = utils .find_project_root (
50+ temp_dir .. " /src/module.py" ,
51+ { " pyproject.toml" }
52+ )
53+ assert .equals (temp_dir , result )
54+ end )
55+ end )
56+
57+ it (" src is a source layout (without __init__.py)" , function ()
58+ with_temp_fixture (" src_as_layout" , function (temp_dir )
59+ local Path = require (" plenary.path" )
60+ local project_root = Path :new (temp_dir )
61+ local src_dir = project_root :joinpath (" src" )
62+ src_dir :mkdir ({ parents = true })
63+ project_root :joinpath (" pyproject.toml" ):touch ()
64+ end , function (temp_dir )
65+ local result = utils .find_project_root (
66+ temp_dir .. " /src/module.py" ,
67+ { " pyproject.toml" }
68+ )
69+ assert .equals (temp_dir .. " /src" , result )
70+ end )
71+ end )
3072end )
3173
3274describe (" to_python_reference_path" , function ()
0 commit comments