|
21 | 21 |
|
22 | 22 | # this package
|
23 | 23 | from domdf_python_tools import paths
|
24 |
| -from domdf_python_tools.paths import PathPlus, clean_writer, copytree, in_directory |
| 24 | +from domdf_python_tools.paths import PathPlus, clean_writer, copytree, in_directory, traverse_to_file |
25 | 25 | from domdf_python_tools.testing import not_pypy, not_windows
|
26 | 26 |
|
27 | 27 |
|
@@ -614,3 +614,36 @@ def test_in_directory(tmp_pathplus):
|
614 | 614 | assert str(os.getcwd()) == str(tmpdir)
|
615 | 615 |
|
616 | 616 | assert os.getcwd() == cwd
|
| 617 | + |
| 618 | + |
| 619 | +@pytest.mark.parametrize( |
| 620 | + "location, expected", |
| 621 | + [ |
| 622 | + ("foo.yml", ''), |
| 623 | + ("foo/foo.yml", "foo"), |
| 624 | + ("foo/bar/foo.yml", "foo/bar"), |
| 625 | + ("foo/bar/baz/foo.yml", "foo/bar/baz"), |
| 626 | + ] |
| 627 | + ) |
| 628 | +def test_traverse_to_file(tmp_pathplus, location, expected): |
| 629 | + (tmp_pathplus / location).parent.maybe_make(parents=True) |
| 630 | + (tmp_pathplus / location).touch() |
| 631 | + assert traverse_to_file(tmp_pathplus / "foo" / "bar" / "baz", "foo.yml") == tmp_pathplus / expected |
| 632 | + |
| 633 | + |
| 634 | +# TODO: height |
| 635 | + |
| 636 | + |
| 637 | +def test_traverse_to_file_errors(tmp_pathplus): |
| 638 | + (tmp_pathplus / "foo/bar/baz").parent.maybe_make(parents=True) |
| 639 | + if os.sep == '/': |
| 640 | + with pytest.raises(FileNotFoundError, match="'foo.yml' not found in .*/foo/bar/baz"): |
| 641 | + traverse_to_file(tmp_pathplus / "foo" / "bar" / "baz", "foo.yml") |
| 642 | + elif os.sep == '\\': |
| 643 | + with pytest.raises(FileNotFoundError, match=r"'foo.yml' not found in .*\\foo\\bar\\baz"): |
| 644 | + traverse_to_file(tmp_pathplus / "foo" / "bar" / "baz", "foo.yml") |
| 645 | + else: |
| 646 | + raise NotImplementedError |
| 647 | + |
| 648 | + with pytest.raises(TypeError, match="traverse_to_file expected 2 or more arguments, got 1"): |
| 649 | + traverse_to_file(tmp_pathplus) |
0 commit comments