diff --git a/dvc/fs/path.py b/dvc/fs/path.py index b0c02db8c7..7545fb7a88 100644 --- a/dvc/fs/path.py +++ b/dvc/fs/path.py @@ -15,7 +15,7 @@ def join(self, *parts): return self.flavour.join(*parts) def parts(self, path): - drive, path = self.flavour.splitdrive(path) + drive, path = self.flavour.splitdrive(path.rstrip(self.flavour.sep)) ret = [] while True: diff --git a/tests/unit/fs/test_path.py b/tests/unit/fs/test_path.py new file mode 100644 index 0000000000..caf41342c6 --- /dev/null +++ b/tests/unit/fs/test_path.py @@ -0,0 +1,29 @@ +import pytest + +from dvc.fs.path import Path + + +@pytest.mark.parametrize("prefix", ["", "/"]) +@pytest.mark.parametrize("postfix", ["", "/"]) +@pytest.mark.parametrize( + "path,expected", + [ + ("path", ("path",)), + ("some/path", ("some", "path")), + ], +) +def test_parts_posix(prefix, postfix, path, expected): + assert Path("/").parts(prefix + path + postfix) == tuple(prefix) + expected + + +@pytest.mark.parametrize("postfix", ["", "\\"]) +@pytest.mark.parametrize( + "path,expected", + [ + ("path", ("path",)), + ("c:\\path", ("c:", "\\", "path")), + ("some\\path", ("some", "path")), + ], +) +def test_parts_nt(postfix, path, expected): + assert Path("\\").parts(path + postfix) == expected