Skip to content

Commit

Permalink
Fix UPath.as_uri() (#133)
Browse files Browse the repository at this point in the history
* tests: add uri test

* upath: fix as_uri
  • Loading branch information
ap-- authored Aug 23, 2023
1 parent 9ce4a9a commit bbc3c3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions upath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,9 @@ def parents(self) -> _UPathParents:
"""A sequence of this upath's logical parents."""
return _UPathParents(self)

def as_uri(self) -> str:
return str(self)


class _UPathParents(Sequence[UPath]):
"""This object provides sequence-like access to the logical ancestors
Expand Down
9 changes: 8 additions & 1 deletion upath/tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,11 @@ def test_private_url_attr_in_sync(self):
p1 = self.path.joinpath("c")
p2 = self.path / "c"
assert p1._url == p2._url
assert p1 != p._url
assert p1._url != p._url

def test_as_uri(self):
# test that we can reconstruct the path from the uri
p0 = self.path
uri = p0.as_uri()
p1 = UPath(uri, **p0.fs.storage_options)
assert p0 == p1

0 comments on commit bbc3c3d

Please sign in to comment.