diff --git a/pathy/base.py b/pathy/base.py index 6848bd5..0d5c2c5 100644 --- a/pathy/base.py +++ b/pathy/base.py @@ -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 :" diff --git a/pathy/clients.py b/pathy/clients.py index bd61141..f55f7ee 100644 --- a/pathy/clients.py +++ b/pathy/clients.py @@ -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, } diff --git a/tests/test_base.py b/tests/test_base.py index 22c3dc3..188d095 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -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" diff --git a/tests/test_clients.py b/tests/test_clients.py index 972b97b..4676473 100644 --- a/tests/test_clients.py +++ b/tests/test_clients.py @@ -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():