Пример #1
0
    def test_valid_abs_path_with_dots(self, tmp_path):
        rel_path = pathlib.PurePath("e/./f/g/h/../i/..")
        abs_path = (tmp_path / rel_path).resolve()
        abs_path.mkdir(parents=True)

        path = Path("/" / rel_path, None)
        path.resolve_path(tmp_path)

        assert pathlib.PurePath("e/f/g") == path.data
Пример #2
0
    def test_valid_dir_path(self, tmp_path):
        rel_path = pathlib.PurePath("some/folder")
        abs_path = tmp_path / rel_path
        abs_path.mkdir(parents=True)

        path = Path(rel_path, None)
        path.resolve_path(tmp_path)

        assert rel_path == path.data
Пример #3
0
    def test_valid_rel_path_with_dots(self, tmp_path):
        rel_path = pathlib.PurePath("a/././b/../c/../d")
        abs_path = (tmp_path / rel_path).resolve()
        abs_path.mkdir(parents=True)

        path = Path(rel_path, None)
        path.resolve_path(tmp_path)

        assert pathlib.PurePath("a/d") == path.data
Пример #4
0
    def test_valid_file_path(self, tmp_path):
        rel_path = pathlib.PurePath("some/file.txt")
        abs_path = tmp_path / rel_path
        abs_path.parent.mkdir(parents=True)
        abs_path.write_text("sample_text")

        path = Path(rel_path, None)
        path.resolve_path(tmp_path)

        assert rel_path == path.data
Пример #5
0
    def test_symlink(self, tmp_path):
        file = tmp_path / "file.txt"
        file.write_text("file")
        symlink = tmp_path / "symlink"
        symlink.symlink_to(file)

        with pytest.raises(ParseError):
            Path(pathlib.PurePath("symlink"), None).resolve_path(tmp_path)
Пример #6
0
 def test_escape_csar(self, tmp_path, path):
     with pytest.raises(ParseError):
         Path(pathlib.PurePath(path), None).resolve_path(tmp_path)
Пример #7
0
 def test_missing_file(self, tmp_path):
     with pytest.raises(ParseError):
         Path(pathlib.PurePath("missing"), None).resolve_path(tmp_path)
Пример #8
0
    def test_prefix_relative_path(self, input, prefix, output):
        path = Path(pathlib.PurePath(input), None)
        path.prefix_path(pathlib.PurePath(prefix))

        assert str(path.data) == output
Пример #9
0
    def test_prefix_absolute_path(self, input, prefix):
        path = Path(pathlib.PurePath(input), None)
        path.prefix_path(pathlib.PurePath(prefix))

        assert str(path.data) == input
Пример #10
0
 def test_csar_root(self, tmp_path):
     with pytest.raises(ParseError):
         Path(pathlib.PurePath("/c/.."), None).resolve_path(tmp_path)
Пример #11
0
 def test_build(self):
     assert isinstance(Path.build(Node("/")).data, pathlib.PurePath)