Skip to content

Commit 9892654

Browse files
committed
Add additional tests
1 parent d7c516c commit 9892654

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/lint/unittest_expand_modules.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,28 @@ def test_discover_package_path_no_source_root_overlap(tmp_path):
321321

322322
expected = source_roots
323323
assert package_paths == expected
324+
325+
def test_discover_package_path_legacy():
326+
"""Test for legacy path discovery when source_roots is empty
327+
"""
328+
source_roots = []
329+
package_paths = discover_package_path(__file__, source_roots)
330+
331+
# First ancestor directory without __init__.py
332+
expected = [str(Path(__file__).parent.parent.absolute())]
333+
334+
assert package_paths == expected
335+
336+
def test_discover_package_path_legacy_no_parent_without_init_py(tmp_path, monkeypatch):
337+
"""Test to return current directory if no parent directory without
338+
__init__.py is found"""
339+
source_roots = []
340+
341+
monkeypatch.setattr(os.path, "exists", lambda path: True)
342+
monkeypatch.setattr(os.path, "dirname", lambda path: path)
343+
344+
package_paths = discover_package_path(tmp_path, source_roots)
345+
346+
expected = [os.getcwd()]
347+
348+
assert package_paths == expected

0 commit comments

Comments
 (0)