Skip to content

Commit 55e01b4

Browse files
committed
PathPlus.iterchildren: Only make path absolute if self is absolute
1 parent 283c3af commit 55e01b4

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

domdf_python_tools/paths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ def iterchildren(
777777
if exclude_dirs is None:
778778
exclude_dirs = ()
779779

780-
if match and not os.path.isabs(match):
780+
if match and not os.path.isabs(match) and self.is_absolute():
781781
match = (self / match).as_posix()
782782

783783
file: _PP

tests/test_paths.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -686,23 +686,31 @@ def test_iterchildren_exclusions():
686686
assert directory.parts[0] not in paths.unwanted_dirs
687687

688688

689-
def test_iterchildren_match(data_regression: DataRegressionFixture):
689+
@pytest.mark.parametrize("absolute", [True, False])
690+
def test_iterchildren_match(data_regression: DataRegressionFixture, absolute: bool):
690691
repo_path = PathPlus(__file__).parent.parent
691-
assert repo_path.is_dir()
692+
with in_directory(repo_path.parent):
692693

693-
if (repo_path / "build").is_dir():
694-
shutil.rmtree(repo_path / "build")
694+
assert repo_path.is_dir()
695695

696-
children = list(repo_path.iterchildren(match="**/*.py"))
697-
assert children
696+
if not absolute:
697+
repo_path = repo_path.relative_to(repo_path.parent)
698+
699+
if (repo_path / "build").is_dir():
700+
shutil.rmtree(repo_path / "build")
701+
702+
children = list(repo_path.iterchildren(match="**/*.py"))
703+
assert children
698704

699-
child_paths = sorted(p.relative_to(repo_path).as_posix() for p in children)
705+
child_paths = sorted(p.relative_to(repo_path).as_posix() for p in children)
700706

701-
for exclude_filename in {".coverage", "pathtype_demo.py", "dist", "htmlcov", "conda", ".idea", "mutdef.py"}:
702-
if exclude_filename in child_paths:
703-
child_paths.remove(exclude_filename)
707+
for exclude_filename in {
708+
".coverage", "pathtype_demo.py", "dist", "htmlcov", "conda", ".idea", "mutdef.py"
709+
}:
710+
if exclude_filename in child_paths:
711+
child_paths.remove(exclude_filename)
704712

705-
data_regression.check(child_paths)
713+
data_regression.check(child_paths, basename="test_iterchildren_match")
706714

707715

708716
def test_iterchildren_no_exclusions(tmp_pathplus: PathPlus):

0 commit comments

Comments
 (0)