Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: path.scheme would error with scheme-less paths #37

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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