From 5632f264ed5d22b54b1c284ca1d79d2e248c5fd3 Mon Sep 17 00:00:00 2001 From: justindujardin Date: Fri, 21 Aug 2020 14:24:34 -0700 Subject: [PATCH] refactor: rename PureGCSPath to PurePathy Be more consistent with the Pathy naming. BREAKING CHANGE: PureGCSPath is now PurePathy --- pathy/__init__.py | 2 +- pathy/api.py | 4 +- pathy/base.py | 18 +--- pathy/client.py | 24 ++--- pathy/file.py | 28 +++--- pathy/gcs.py | 16 ++-- tests/test_api.py | 4 +- tests/test_base.py | 203 +++++++++++++++++++++--------------------- tests/test_cli.py | 3 + tests/test_client.py | 4 +- tests/test_package.py | 5 -- 11 files changed, 149 insertions(+), 162 deletions(-) delete mode 100644 tests/test_package.py diff --git a/pathy/__init__.py b/pathy/__init__.py index 4d76302..ddaa244 100644 --- a/pathy/__init__.py +++ b/pathy/__init__.py @@ -5,7 +5,7 @@ ClientBucket, ClientError, Pathy, - PureGCSPath, + PurePathy, FluidPath, clear_fs_cache, get_fs_cache, diff --git a/pathy/api.py b/pathy/api.py index 2c93908..7809722 100644 --- a/pathy/api.py +++ b/pathy/api.py @@ -13,7 +13,7 @@ from google.cloud import storage from . import gcs -from .base import PureGCSPath, PathType +from .base import PurePathy, PathType from .client import ( BucketClient, BucketEntry, @@ -112,7 +112,7 @@ def clear_fs_cache(force: bool = False) -> None: FluidPath = Union["Pathy", Path] -class Pathy(Path, PureGCSPath): +class Pathy(Path, PurePathy): """Path subclass for GCS service. Write files to and read files from the GCS service using pathlib.Path diff --git a/pathy/base.py b/pathy/base.py index 97455c9..feef3e2 100644 --- a/pathy/base.py +++ b/pathy/base.py @@ -39,31 +39,21 @@ def make_uri(self, path): _gcs_flavour = _GCSFlavour() -class PureGCSPath(PurePath): - """ - PurePath subclass for GCS service. - - GCS is not a file-system but we can look at it like a POSIX system. - """ +class PurePathy(PurePath): + """PurePath subclass for bucket storage.""" _flavour = _gcs_flavour __slots__ = () @property def bucket(self): - """ - bucket property - return a new instance of only the bucket path - """ + """Return a new instance of only the bucket path.""" self._absolute_path_validation() return type(self)(f"{self.drive}//{self.root}") @property def key(self): - """ - key property - return a new instance of only the key path - """ + """Return a new instance of only the key path.""" self._absolute_path_validation() key = self._flavour.sep.join(self.parts[2:]) if not key or len(self.parts) < 2: diff --git a/pathy/client.py b/pathy/client.py index f0b1649..cfd625a 100644 --- a/pathy/client.py +++ b/pathy/client.py @@ -3,7 +3,7 @@ import smart_open -from .base import PureGCSPath +from .base import PurePathy __all__ = ( "BucketStat", @@ -118,16 +118,16 @@ def delete_blobs(self, blobs: List[ClientBlob]) -> None: class BucketClient: """Base class for a client that interacts with a bucket-based storage system.""" - def make_uri(self, path: PureGCSPath) -> str: + def make_uri(self, path: PurePathy) -> str: return path.as_uri() - def is_dir(self, path: PureGCSPath) -> bool: + def is_dir(self, path: PurePathy) -> bool: return any(self.list_blobs(path, prefix=path.prefix)) - def rmdir(self, path: PureGCSPath) -> None: + def rmdir(self, path: PurePathy) -> None: return None - def exists(self, path: PureGCSPath) -> bool: + def exists(self, path: PurePathy) -> bool: # Because we want all the parents of a valid blob (e.g. "directory" in # "directory/foo.file") to return True, we enumerate the blobs with a prefix # and compare the object names to see if they match a substring of the path @@ -141,7 +141,7 @@ def exists(self, path: PureGCSPath) -> bool: def open( self, - path: PureGCSPath, + path: PurePathy, *, mode="r", buffering=-1, @@ -160,10 +160,10 @@ def open( ignore_ext=True, ) - def lookup_bucket(self, path: PureGCSPath) -> Optional[ClientBucket]: + def lookup_bucket(self, path: PurePathy) -> Optional[ClientBucket]: raise NotImplementedError(_SUBCLASS_MUST_IMPLEMENT) - def get_bucket(self, path: PureGCSPath) -> ClientBucket: + def get_bucket(self, path: PurePathy) -> ClientBucket: raise NotImplementedError(_SUBCLASS_MUST_IMPLEMENT) def list_buckets(self) -> Generator[ClientBucket, None, None]: @@ -171,7 +171,7 @@ def list_buckets(self) -> Generator[ClientBucket, None, None]: def list_blobs( self, - path: PureGCSPath, + path: PurePathy, prefix: Optional[str] = None, delimiter: Optional[str] = None, include_dirs: bool = False, @@ -180,14 +180,14 @@ def list_blobs( def scandir( self, - path: PureGCSPath = None, + path: PurePathy = None, prefix: Optional[str] = None, delimiter: Optional[str] = None, ) -> Generator[BucketEntry[BucketType, BucketBlobType], None, None]: raise NotImplementedError(_SUBCLASS_MUST_IMPLEMENT) - def create_bucket(self, path: PureGCSPath) -> ClientBucket: + def create_bucket(self, path: PurePathy) -> ClientBucket: raise NotImplementedError(_SUBCLASS_MUST_IMPLEMENT) - def delete_bucket(self, path: PureGCSPath) -> None: + def delete_bucket(self, path: PurePathy) -> None: raise NotImplementedError(_SUBCLASS_MUST_IMPLEMENT) diff --git a/pathy/file.py b/pathy/file.py index 59d6acf..48c1091 100644 --- a/pathy/file.py +++ b/pathy/file.py @@ -1,7 +1,7 @@ from dataclasses import dataclass, field from typing import Optional, List, Generator, cast from .client import BucketClient, ClientBucket, ClientBlob, ClientError, BucketEntry -from .base import PureGCSPath +from .base import PurePathy import pathlib import shutil import os @@ -79,11 +79,11 @@ class BucketClientFS(BucketClient): # Root to store file-system buckets as children of root: pathlib.Path - def make_uri(self, path: PureGCSPath): + def make_uri(self, path: PurePathy): uri = super().make_uri(path) return uri.replace("gs://", "file:///") - def full_path(self, path: PureGCSPath) -> pathlib.Path: + def full_path(self, path: PurePathy) -> pathlib.Path: if path.root is None: raise ValueError(f"Invalid bucket name for path: {path}") full_path = self.root.absolute() / path.root @@ -91,20 +91,20 @@ def full_path(self, path: PureGCSPath) -> pathlib.Path: full_path = full_path / path.key return full_path - def exists(self, path: PureGCSPath) -> bool: + def exists(self, path: PurePathy) -> bool: """Return True if the path exists as a file or folder on disk""" return self.full_path(path).exists() - def is_dir(self, path: PureGCSPath) -> bool: + def is_dir(self, path: PurePathy) -> bool: return self.full_path(path).is_dir() - def rmdir(self, path: PureGCSPath) -> None: + def rmdir(self, path: PurePathy) -> None: full_path = self.full_path(path) return shutil.rmtree(str(full_path)) def open( self, - path: PureGCSPath, + path: PurePathy, *, mode="r", buffering=-1, @@ -129,13 +129,13 @@ def open( newline=newline, ) - def make_uri(self, path: PureGCSPath) -> str: + def make_uri(self, path: PurePathy) -> str: if not path.root: raise ValueError(f"cannot make a URI to an invalid bucket: {path.root}") result = f"file://{self.root.absolute() / path.root / path.key}" return result - def create_bucket(self, path: PureGCSPath) -> ClientBucket: + def create_bucket(self, path: PurePathy) -> ClientBucket: if not path.root: raise ValueError(f"Invalid bucket name: {path.root}") bucket_path: pathlib.Path = self.root / path.root @@ -144,19 +144,19 @@ def create_bucket(self, path: PureGCSPath) -> ClientBucket: bucket_path.mkdir(parents=True, exist_ok=True) return ClientBucketFS(str(path.root), bucket=bucket_path) - def delete_bucket(self, path: PureGCSPath) -> None: + def delete_bucket(self, path: PurePathy) -> None: bucket_path: pathlib.Path = self.root / str(path.root) if bucket_path.exists(): shutil.rmtree(bucket_path) - def lookup_bucket(self, path: PureGCSPath) -> Optional[ClientBucketFS]: + def lookup_bucket(self, path: PurePathy) -> Optional[ClientBucketFS]: if path.root: bucket_path: pathlib.Path = self.root / path.root if bucket_path.exists(): return ClientBucketFS(str(path.root), bucket=bucket_path) return None - def get_bucket(self, path: PureGCSPath) -> ClientBucketFS: + def get_bucket(self, path: PurePathy) -> ClientBucketFS: if not path.root: raise ValueError(f"path has an invalid bucket_name: {path.root}") bucket_path: pathlib.Path = self.root / path.root @@ -171,7 +171,7 @@ def list_buckets(self, **kwargs) -> Generator[ClientBucketFS, None, None]: def scandir( self, - path: Optional[PureGCSPath] = None, + path: Optional[PurePathy] = None, prefix: Optional[str] = None, delimiter: Optional[str] = None, ) -> Generator[BucketEntryFS, None, None]: @@ -210,7 +210,7 @@ def scandir( def list_blobs( self, - path: PureGCSPath, + path: PurePathy, prefix: Optional[str] = None, delimiter: Optional[str] = None, include_dirs: bool = False, diff --git a/pathy/gcs.py b/pathy/gcs.py index 363d49b..3822be9 100644 --- a/pathy/gcs.py +++ b/pathy/gcs.py @@ -1,7 +1,7 @@ from dataclasses import dataclass, field from typing import Optional, List, Generator from .client import BucketClient, ClientBucket, ClientBlob, ClientError, BucketEntry -from .base import PureGCSPath +from .base import PurePathy try: from google.cloud import storage @@ -71,17 +71,17 @@ def delete_blobs(self, blobs: List[ClientBlobGCS]) -> None: class BucketClientGCS(BucketClient): client: storage.Client = field(default_factory=lambda: storage.Client()) - def make_uri(self, path: PureGCSPath): + def make_uri(self, path: PurePathy): return str(path) - def create_bucket(self, path: PureGCSPath) -> ClientBucket: + def create_bucket(self, path: PurePathy) -> ClientBucket: return self.client.create_bucket(path.root) - def delete_bucket(self, path: PureGCSPath) -> None: + def delete_bucket(self, path: PurePathy) -> None: bucket = self.client.get_bucket(path.root) bucket.delete() - def lookup_bucket(self, path: PureGCSPath) -> Optional[ClientBucketGCS]: + def lookup_bucket(self, path: PurePathy) -> Optional[ClientBucketGCS]: try: native_bucket = self.client.lookup_bucket(path.root) if native_bucket is not None: @@ -90,7 +90,7 @@ def lookup_bucket(self, path: PureGCSPath) -> Optional[ClientBucketGCS]: pass return None - def get_bucket(self, path: PureGCSPath) -> ClientBucketGCS: + def get_bucket(self, path: PurePathy) -> ClientBucketGCS: try: native_bucket = self.client.lookup_bucket(path.root) if native_bucket is not None: @@ -104,7 +104,7 @@ def list_buckets(self, **kwargs) -> Generator[ClientBucket, None, None]: def scandir( self, - path: Optional[PureGCSPath] = None, + path: Optional[PurePathy] = None, prefix: Optional[str] = None, delimiter: Optional[str] = None, include_raw: bool = False, @@ -152,7 +152,7 @@ def scandir( def list_blobs( self, - path: PureGCSPath, + path: PurePathy, prefix: Optional[str] = None, delimiter: Optional[str] = None, include_dirs: bool = False, diff --git a/tests/test_api.py b/tests/test_api.py index fe38aea..9263762 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -15,7 +15,7 @@ BucketStat, FluidPath, Pathy, - PureGCSPath, + PurePathy, clear_fs_cache, get_fs_client, use_fs, @@ -29,7 +29,7 @@ def test_api_path_support(): - assert PureGCSPath in Pathy.mro() # type: ignore + assert PurePathy in Pathy.mro() # type: ignore assert Path in Pathy.mro() # type: ignore diff --git a/tests/test_base.py b/tests/test_base.py index 336e9d5..9637284 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -4,7 +4,7 @@ import pytest -from pathy import Pathy, PureGCSPath +from pathy import Pathy, PurePathy def test_base_not_supported(monkeypatch): @@ -83,201 +83,200 @@ def test_base_symlink_to(): def test_base_paths_of_a_different_flavour(): with pytest.raises(TypeError): - PureGCSPath("/bucket/key") < PurePosixPath("/bucket/key") + PurePathy("/bucket/key") < PurePosixPath("/bucket/key") with pytest.raises(TypeError): - PureWindowsPath("/bucket/key") > PureGCSPath("/bucket/key") + PureWindowsPath("/bucket/key") > PurePathy("/bucket/key") def test_base_repr(): - a = PureGCSPath("/var/tests/fake") - f = a.prefix + a = PurePathy("/var/tests/fake") assert a.as_posix() == "/var/tests/fake" - assert repr(PureGCSPath("fake_file.txt")) == "PureGCSPath('fake_file.txt')" - assert str(PureGCSPath("fake_file.txt")) == "fake_file.txt" - assert bytes(PureGCSPath("fake_file.txt")) == b"fake_file.txt" + assert repr(PurePathy("fake_file.txt")) == "PurePathy('fake_file.txt')" + assert str(PurePathy("fake_file.txt")) == "fake_file.txt" + assert bytes(PurePathy("fake_file.txt")) == b"fake_file.txt" @pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6 or higher") def test_base_fspath(): - assert os.fspath(PureGCSPath("/var/tests/fake")) == "/var/tests/fake" + assert os.fspath(PurePathy("/var/tests/fake")) == "/var/tests/fake" def test_base_join_strs(): - assert PureGCSPath("foo", "some/path", "bar") == PureGCSPath("foo/some/path/bar") + assert PurePathy("foo", "some/path", "bar") == PurePathy("foo/some/path/bar") def test_base_join_paths(): - assert PureGCSPath(Path("foo"), Path("bar")) == PureGCSPath("foo/bar") + assert PurePathy(Path("foo"), Path("bar")) == PurePathy("foo/bar") def test_base_empty(): - assert PureGCSPath() == PureGCSPath(".") + assert PurePathy() == PurePathy(".") def test_base_absolute_paths(): - assert PureGCSPath("/etc", "/usr", "lib64") == PureGCSPath("/usr/lib64") + assert PurePathy("/etc", "/usr", "lib64") == PurePathy("/usr/lib64") def test_base_slashes_single_double_dots(): - assert PureGCSPath("foo//bar") == PureGCSPath("foo/bar") - assert PureGCSPath("foo/./bar") == PureGCSPath("foo/bar") - assert PureGCSPath("foo/../bar") == PureGCSPath("bar") - assert PureGCSPath("../bar") == PureGCSPath("../bar") - assert PureGCSPath("foo", "../bar") == PureGCSPath("bar") + assert PurePathy("foo//bar") == PurePathy("foo/bar") + assert PurePathy("foo/./bar") == PurePathy("foo/bar") + assert PurePathy("foo/../bar") == PurePathy("bar") + assert PurePathy("../bar") == PurePathy("../bar") + assert PurePathy("foo", "../bar") == PurePathy("bar") def test_base_operators(): - assert PureGCSPath("/etc") / "init.d" / "apache2" == PureGCSPath( + assert PurePathy("/etc") / "init.d" / "apache2" == PurePathy( "/etc/init.d/apache2" ) - assert "/var" / PureGCSPath("tests") / "fake" == PureGCSPath("/var/tests/fake") + assert "/var" / PurePathy("tests") / "fake" == PurePathy("/var/tests/fake") def test_base_parts(): - assert PureGCSPath("../bar").parts == ("..", "bar") - assert PureGCSPath("foo//bar").parts == ("foo", "bar") - assert PureGCSPath("foo/./bar").parts == ("foo", "bar") - assert PureGCSPath("foo/../bar").parts == ("bar",) - assert PureGCSPath("foo", "../bar").parts == ("bar",) - assert PureGCSPath("/foo/bar").parts == ("/", "foo", "bar") + assert PurePathy("../bar").parts == ("..", "bar") + assert PurePathy("foo//bar").parts == ("foo", "bar") + assert PurePathy("foo/./bar").parts == ("foo", "bar") + assert PurePathy("foo/../bar").parts == ("bar",) + assert PurePathy("foo", "../bar").parts == ("bar",) + assert PurePathy("/foo/bar").parts == ("/", "foo", "bar") def test_base_drive(): - assert PureGCSPath("foo//bar").drive == "" - assert PureGCSPath("foo/./bar").drive == "" - assert PureGCSPath("foo/../bar").drive == "" - assert PureGCSPath("../bar").drive == "" - assert PureGCSPath("foo", "../bar").drive == "" - assert PureGCSPath("/foo/bar").drive == "" + assert PurePathy("foo//bar").drive == "" + assert PurePathy("foo/./bar").drive == "" + assert PurePathy("foo/../bar").drive == "" + assert PurePathy("../bar").drive == "" + assert PurePathy("foo", "../bar").drive == "" + assert PurePathy("/foo/bar").drive == "" def test_base_root(): - assert PureGCSPath("foo//bar").root == "" - assert PureGCSPath("foo/./bar").root == "" - assert PureGCSPath("foo/../bar").root == "" - assert PureGCSPath("../bar").root == "" - assert PureGCSPath("foo", "../bar").root == "" - assert PureGCSPath("/foo/bar").root == "/" + assert PurePathy("foo//bar").root == "" + assert PurePathy("foo/./bar").root == "" + assert PurePathy("foo/../bar").root == "" + assert PurePathy("../bar").root == "" + assert PurePathy("foo", "../bar").root == "" + assert PurePathy("/foo/bar").root == "/" def test_base_anchor(): - assert PureGCSPath("foo//bar").anchor == "" - assert PureGCSPath("foo/./bar").anchor == "" - assert PureGCSPath("foo/../bar").anchor == "" - assert PureGCSPath("../bar").anchor == "" - assert PureGCSPath("foo", "../bar").anchor == "" - assert PureGCSPath("/foo/bar").anchor == "/" + assert PurePathy("foo//bar").anchor == "" + assert PurePathy("foo/./bar").anchor == "" + assert PurePathy("foo/../bar").anchor == "" + assert PurePathy("../bar").anchor == "" + assert PurePathy("foo", "../bar").anchor == "" + assert PurePathy("/foo/bar").anchor == "/" def test_base_parents(): - assert tuple(PureGCSPath("foo//bar").parents) == ( - PureGCSPath("foo"), - PureGCSPath("."), + assert tuple(PurePathy("foo//bar").parents) == ( + PurePathy("foo"), + PurePathy("."), ) - assert tuple(PureGCSPath("foo/./bar").parents) == ( - PureGCSPath("foo"), - PureGCSPath("."), + assert tuple(PurePathy("foo/./bar").parents) == ( + PurePathy("foo"), + PurePathy("."), ) - assert tuple(PureGCSPath("foo/../bar").parents) == (PureGCSPath("."),) - assert tuple(PureGCSPath("../bar").parents) == (PureGCSPath(".."), PureGCSPath(".")) - assert tuple(PureGCSPath("foo", "../bar").parents) == (PureGCSPath("."),) - assert tuple(PureGCSPath("/foo/bar").parents) == ( - PureGCSPath("/foo"), - PureGCSPath("/"), + assert tuple(PurePathy("foo/../bar").parents) == (PurePathy("."),) + assert tuple(PurePathy("../bar").parents) == (PurePathy(".."), PurePathy(".")) + assert tuple(PurePathy("foo", "../bar").parents) == (PurePathy("."),) + assert tuple(PurePathy("/foo/bar").parents) == ( + PurePathy("/foo"), + PurePathy("/"), ) def test_base_parent(): - assert PureGCSPath("foo//bar").parent == PureGCSPath("foo") - assert PureGCSPath("foo/./bar").parent == PureGCSPath("foo") - assert PureGCSPath("foo/../bar").parent == PureGCSPath(".") - assert PureGCSPath("../bar").parent == PureGCSPath("..") - assert PureGCSPath("foo", "../bar").parent == PureGCSPath(".") - assert PureGCSPath("/foo/bar").parent == PureGCSPath("/foo") - assert PureGCSPath(".").parent == PureGCSPath(".") - assert PureGCSPath("/").parent == PureGCSPath("/") + assert PurePathy("foo//bar").parent == PurePathy("foo") + assert PurePathy("foo/./bar").parent == PurePathy("foo") + assert PurePathy("foo/../bar").parent == PurePathy(".") + assert PurePathy("../bar").parent == PurePathy("..") + assert PurePathy("foo", "../bar").parent == PurePathy(".") + assert PurePathy("/foo/bar").parent == PurePathy("/foo") + assert PurePathy(".").parent == PurePathy(".") + assert PurePathy("/").parent == PurePathy("/") def test_base_name(): - assert PureGCSPath("my/library/fake_file.txt").name == "fake_file.txt" + assert PurePathy("my/library/fake_file.txt").name == "fake_file.txt" def test_base_suffix(): - assert PureGCSPath("my/library/fake_file.txt").suffix == ".txt" - assert PureGCSPath("my/library.tar.gz").suffix == ".gz" - assert PureGCSPath("my/library").suffix == "" + assert PurePathy("my/library/fake_file.txt").suffix == ".txt" + assert PurePathy("my/library.tar.gz").suffix == ".gz" + assert PurePathy("my/library").suffix == "" def test_base_suffixes(): - assert PureGCSPath("my/library.tar.gar").suffixes == [".tar", ".gar"] - assert PureGCSPath("my/library.tar.gz").suffixes == [".tar", ".gz"] - assert PureGCSPath("my/library").suffixes == [] + assert PurePathy("my/library.tar.gar").suffixes == [".tar", ".gar"] + assert PurePathy("my/library.tar.gz").suffixes == [".tar", ".gz"] + assert PurePathy("my/library").suffixes == [] def test_base_stem(): - assert PureGCSPath("my/library.tar.gar").stem == "library.tar" - assert PureGCSPath("my/library.tar").stem == "library" - assert PureGCSPath("my/library").stem == "library" + assert PurePathy("my/library.tar.gar").stem == "library.tar" + assert PurePathy("my/library.tar").stem == "library" + assert PurePathy("my/library").stem == "library" def test_base_uri(): - assert PureGCSPath("/etc/passwd").as_uri() == "gs://etc/passwd" - assert PureGCSPath("/etc/init.d/apache2").as_uri() == "gs://etc/init.d/apache2" - assert PureGCSPath("/bucket/key").as_uri() == "gs://bucket/key" + assert PurePathy("/etc/passwd").as_uri() == "gs://etc/passwd" + assert PurePathy("/etc/init.d/apache2").as_uri() == "gs://etc/init.d/apache2" + assert PurePathy("/bucket/key").as_uri() == "gs://bucket/key" def test_base_absolute(): - assert PureGCSPath("/a/b").is_absolute() - assert not PureGCSPath("a/b").is_absolute() + assert PurePathy("/a/b").is_absolute() + assert not PurePathy("a/b").is_absolute() def test_base_reserved(): - assert not PureGCSPath("/a/b").is_reserved() - assert not PureGCSPath("a/b").is_reserved() + assert not PurePathy("/a/b").is_reserved() + assert not PurePathy("a/b").is_reserved() def test_base_joinpath(): - assert PureGCSPath("/etc").joinpath("passwd") == PureGCSPath("/etc/passwd") - assert PureGCSPath("/etc").joinpath(PureGCSPath("passwd")) == PureGCSPath( + assert PurePathy("/etc").joinpath("passwd") == PurePathy("/etc/passwd") + assert PurePathy("/etc").joinpath(PurePathy("passwd")) == PurePathy( "/etc/passwd" ) - assert PureGCSPath("/etc").joinpath("init.d", "apache2") == PureGCSPath( + assert PurePathy("/etc").joinpath("init.d", "apache2") == PurePathy( "/etc/init.d/apache2" ) def test_base_match(): - assert PureGCSPath("a/b.py").match("*.py") - assert PureGCSPath("/a/b/c.py").match("b/*.py") - assert not PureGCSPath("/a/b/c.py").match("a/*.py") - assert PureGCSPath("/a.py").match("/*.py") - assert not PureGCSPath("a/b.py").match("/*.py") - assert not PureGCSPath("a/b.py").match("*.Py") + assert PurePathy("a/b.py").match("*.py") + assert PurePathy("/a/b/c.py").match("b/*.py") + assert not PurePathy("/a/b/c.py").match("a/*.py") + assert PurePathy("/a.py").match("/*.py") + assert not PurePathy("a/b.py").match("/*.py") + assert not PurePathy("a/b.py").match("*.Py") def test_base_relative_to(): - gcs_path = PureGCSPath("/etc/passwd") - assert gcs_path.relative_to("/") == PureGCSPath("etc/passwd") - assert gcs_path.relative_to("/etc") == PureGCSPath("passwd") + gcs_path = PurePathy("/etc/passwd") + assert gcs_path.relative_to("/") == PurePathy("etc/passwd") + assert gcs_path.relative_to("/etc") == PurePathy("passwd") with pytest.raises(ValueError): gcs_path.relative_to("/usr") def test_base_with_name(): - gcs_path = PureGCSPath("/Downloads/pathlib.tar.gz") - assert gcs_path.with_name("fake_file.txt") == PureGCSPath( + gcs_path = PurePathy("/Downloads/pathlib.tar.gz") + assert gcs_path.with_name("fake_file.txt") == PurePathy( "/Downloads/fake_file.txt" ) - gcs_path = PureGCSPath("/") + gcs_path = PurePathy("/") with pytest.raises(ValueError): gcs_path.with_name("fake_file.txt") def test_base_with_suffix(): - gcs_path = PureGCSPath("/Downloads/pathlib.tar.gz") - assert gcs_path.with_suffix(".bz2") == PureGCSPath("/Downloads/pathlib.tar.bz2") - gcs_path = PureGCSPath("README") - assert gcs_path.with_suffix(".txt") == PureGCSPath("README.txt") - gcs_path = PureGCSPath("README.txt") - assert gcs_path.with_suffix("") == PureGCSPath("README") + gcs_path = PurePathy("/Downloads/pathlib.tar.gz") + assert gcs_path.with_suffix(".bz2") == PurePathy("/Downloads/pathlib.tar.bz2") + gcs_path = PurePathy("README") + assert gcs_path.with_suffix(".txt") == PurePathy("README.txt") + gcs_path = PurePathy("README.txt") + assert gcs_path.with_suffix("") == PurePathy("README") diff --git a/tests/test_cli.py b/tests/test_cli.py index 35b90d7..b9b3ab6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -8,6 +8,9 @@ runner = CliRunner() +# TODO: add a test for wildcard cp/mv/rm/ls paths (e.g. "pathy cp gs://my-bucket/*.file ./") +# TODO: add a test for streaming in/out sources (e.g. "pathy cp - gs://my-bucket/my.file") + @pytest.mark.parametrize("adapter", TEST_ADAPTERS) def test_cli_cp_file(with_adapter, bucket: str): diff --git a/tests/test_client.py b/tests/test_client.py index ba526a4..cb8bbe5 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,7 +1,7 @@ from pathlib import Path -from pathy import PureGCSPath +from pathy import PurePathy from pathy.file import BucketClientFS @@ -9,5 +9,5 @@ def test_client_create_bucket(temp_folder: Path): bucket_target = temp_folder / "foo" assert bucket_target.exists() is False cl = BucketClientFS(temp_folder) - cl.create_bucket(PureGCSPath("gs://foo/")) + cl.create_bucket(PurePathy("gs://foo/")) assert bucket_target.exists() is True diff --git a/tests/test_package.py b/tests/test_package.py deleted file mode 100644 index 9404621..0000000 --- a/tests/test_package.py +++ /dev/null @@ -1,5 +0,0 @@ -from pathy.about import __version__ - - -def test_package_defines_version(): - assert isinstance(__version__, str)