Skip to content

Commit

Permalink
better tests + formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvergnaud committed Oct 10, 2024
1 parent 0264afe commit b03ab9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/databricks/labs/blueprint/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,16 +520,17 @@ def resolve(self: P, strict: bool = False) -> P:
if strict and not absolute.exists():
msg = f"Path does not exist: {self}"
raise FileNotFoundError(msg)
return absolute._normalize()
return absolute.normalize()

def _normalize(self) -> P:
def normalize(self: P) -> P:
for index, part in enumerate(self._path_parts):
if part != '..':
# we can't normalize '/../stuff' so let's ignore such scenarios
if index == 0 or part != "..":
continue
segments = list(self._path_parts)
segments.pop(index)
segments.pop(index - 1)
return self.with_segments(self.anchor, *segments)._normalize()
return self.with_segments(self.anchor, *segments).normalize()
return self

def absolute(self: P) -> P:
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ def test_replace_file(ws, make_random, cls):
tmp_dir.rmdir(recursive=True)


def test_resolve_is_consistent(ws):
path = WorkspacePath(ws, "/a/b/c") / Path("../../d")
@pytest.mark.parametrize("cls", DATABRICKS_PATHLIKE)
def test_resolve_is_consistent(ws, cls):
path = cls(ws, "/a/b/c") / Path("../../d")
resolved = path.resolve()
assert resolved == WorkspacePath(ws,"/a/d")
assert resolved == cls(ws, "/a/d")


def test_workspace_as_fuse(ws):
Expand Down

0 comments on commit b03ab9e

Please sign in to comment.