diff --git a/test/test_api/test_project.py b/test/test_api/test_project.py index c8533618..9ca4686c 100644 --- a/test/test_api/test_project.py +++ b/test/test_api/test_project.py @@ -6,6 +6,7 @@ import pytest from ..helpers import get_example_dir, set_cwd, root_dir, test_dir from jedi import Interpreter from jedi.api import Project, get_default_project +from jedi.api.project import _is_potential_project, _CONTAINS_POTENTIAL_PROJECT def test_django_default_project(Script): @@ -160,3 +161,21 @@ def test_complete_search(Script, string, completions, all_scopes): project = Project(test_dir) defs = project.complete_search(string, all_scopes=all_scopes) assert [d.complete for d in defs] == completions + + +@pytest.mark.parametrize( + 'path,expected', [ + (Path(__file__).parents[2], True), # The path of the project + (Path(__file__).parents[1], False), # The path of the tests, not a project + (Path.home(), None) + ] +) +def test_is_potential_project(path, expected): + + if expected is None: + try: + expected = _CONTAINS_POTENTIAL_PROJECT in os.listdir(path) + except OSError: + expected = False + + assert _is_potential_project(path) == expected diff --git a/test/test_inference/test_sys_path.py b/test/test_inference/test_sys_path.py index 2fa0e4df..d22cc2e0 100644 --- a/test/test_inference/test_sys_path.py +++ b/test/test_inference/test_sys_path.py @@ -108,3 +108,13 @@ def test_transform_path_to_dotted(sys_path_, module_path, expected, is_package): module_path = os.path.abspath(module_path) assert sys_path.transform_path_to_dotted(sys_path_, Path(module_path)) \ == (expected, is_package) + + +@pytest.mark.parametrize( + 'path,filename,expected', [ + (Path(__file__).parents[1], "setup.py", Path(__file__).parents[2]), + (Path(__file__).parents[2], os.path.basename(__file__), None) + ] +) +def test_get_parent_dir_with_file(path, filename, expected): + assert sys_path._get_parent_dir_with_file(path, filename) == expected