diff --git a/upath/core.py b/upath/core.py index 9e07e8db..e35425d4 100644 --- a/upath/core.py +++ b/upath/core.py @@ -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 diff --git a/upath/tests/cases.py b/upath/tests/cases.py index ba0fbcb8..b48499c4 100644 --- a/upath/tests/cases.py +++ b/upath/tests/cases.py @@ -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