From 451a12c451200dbd0ed12e17a127d23bb51c5145 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 6 Apr 2024 18:49:02 -0300 Subject: [PATCH] Improve is_importable tests --- testing/test_pathlib.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py index dcfd10970..dbdc03b50 100644 --- a/testing/test_pathlib.py +++ b/testing/test_pathlib.py @@ -1373,12 +1373,30 @@ class TestNamespacePackages: ) == (tmp_path / "src/dist2", "ns.a.core.foo.m") -def test_is_importable_bad_arguments(pytester: Pytester) -> None: +def test_is_importable(pytester: Pytester) -> None: pytester.syspathinsert() + + # Module package. + path = pytester.path / "is_importable/foo.py" + path.parent.mkdir() + path.touch() + assert is_importable("is_importable.foo", path) is True + + # Standalone module. + path = pytester.path / "is_importable_module.py" + path.touch() + assert is_importable("is_importable_module", path) is True + + # Ensure that the module that can be imported points to the path we expect. + path = pytester.path / "some/other/path/is_importable_module.py" + assert is_importable("is_importable_module", path) is False + + # Paths containing "." cannot be imported. path = pytester.path / "bar.x" path.mkdir() assert is_importable("bar.x", path) is False + # Pass starting with "." denote relative imports and cannot be checked using is_importable. path = pytester.path / ".bar.x" path.mkdir() assert is_importable(".bar.x", path) is False