Skip to content

Commit

Permalink
fix: path.scheme would error with schemeless paths (#37)
Browse files Browse the repository at this point in the history
- return "" from file paths as expected rather than error
  • Loading branch information
justindujardin authored Nov 12, 2020
1 parent 7a0bd66 commit 80f0036
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pathy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ def scheme(self) -> str:
```python
assert Pathy("gs://foo/bar").scheme == "gs"
assert Pathy("file:///tmp/foo/bar").scheme == "file"
assert Pathy("/dev/null").scheme == ""
"""
# If there is no drive, return nothing
if self.drive == "":
return ""
# This is an assumption of mine. I think it's fine, but let's
# cause an error if it's not the case.
assert self.drive[-1] == ":", "drive should end with :"
Expand Down
1 change: 1 addition & 0 deletions pathy/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# hardcode it (atleast the base schemes) to get nice types flowing
# in cases where they would otherwise be lost.
_client_registry: Dict[str, Type[BucketClient]] = {
"": BucketClientFS,
"file": BucketClientFS,
"gs": BucketClientGCS,
}
Expand Down
7 changes: 7 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def test_base_repr():
assert bytes(PurePathy("fake_file.txt")) == b"fake_file.txt"


def test_base_scheme_extraction():
assert PurePathy("gs://var/tests/fake").scheme == "gs"
assert PurePathy("s3://var/tests/fake").scheme == "s3"
assert PurePathy("file://var/tests/fake").scheme == "file"
assert PurePathy("/var/tests/fake").scheme == ""


@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6 or higher")
def test_base_fspath():
assert os.fspath(PurePathy("/var/tests/fake")) == "/var/tests/fake"
Expand Down
1 change: 1 addition & 0 deletions tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
def test_clients_get_client_works_with_builtin_schems():
assert isinstance(get_client("gs"), BucketClientGCS)
assert isinstance(get_client("file"), BucketClientFS)
assert isinstance(get_client(""), BucketClientFS)


def test_clients_get_client_errors_with_unknown_scheme():
Expand Down

0 comments on commit 80f0036

Please sign in to comment.