def test_file_bucket_client_fs_open(with_adapter: str) -> None: client: BucketClientFS = get_client("gs") blob = Pathy("gs://foo/bar") with pytest.raises(ClientError): client.open(blob) blob.mkdir() blob.touch() assert client.open(blob) is not None
def test_file_get_blob_owner_key_error_protection(with_adapter: str) -> None: gs_bucket = Pathy("gs://my_bucket") gs_bucket.mkdir() path = gs_bucket / "blob.txt" path.write_text("hello world!") gcs_client: BucketClientFS = get_client("gs") bucket: BucketFS = gcs_client.get_bucket(gs_bucket) blob: Optional[BlobFS] = bucket.get_blob("blob.txt") assert blob is not None and blob.owner is None
def test_file_bucket_client_fs_list_blobs(with_adapter: str) -> None: client: BucketClientFS = get_client("gs") root = Pathy("gs://bucket") root.mkdir(exist_ok=True) blob = Pathy("gs://bucket/foo/bar/baz") blob.touch() blobs = [b.name for b in client.list_blobs(root, prefix="foo/bar/")] assert blobs == ["foo/bar/baz"] blobs = [b.name for b in client.list_blobs(root, prefix="foo/bar/baz")] assert len(blobs) == 1
def pathy_fixture(): import tempfile import shutil from pathy import use_fs, Pathy temp_folder = tempfile.mkdtemp(prefix="thinc-pathy") use_fs(temp_folder) root = Pathy("gs://test-bucket") root.mkdir(exist_ok=True) yield root use_fs(False) shutil.rmtree(temp_folder)
def test_api_export_spacy_model(temp_folder: Path) -> None: """spaCy model loading is one of the things we need to support""" use_fs(temp_folder) bucket = Pathy("gs://my-bucket/") bucket.mkdir(exist_ok=True) model = spacy.blank("en") output_path = Pathy("gs://my-bucket/models/my_model") model.to_disk(output_path) sorted_entries = sorted([str(p) for p in output_path.glob("*")]) expected_entries = [ "gs://my-bucket/models/my_model/meta.json", "gs://my-bucket/models/my_model/tokenizer", "gs://my-bucket/models/my_model/vocab", ] assert sorted_entries == expected_entries
def test_api_mkdir(with_adapter: str, bucket: str) -> None: bucket_name = f"pathy-e2e-test-{uuid4().hex}" # Create a bucket path = Pathy(f"gs://{bucket_name}/") path.mkdir() assert path.exists() # Does not assert if it already exists path.mkdir(exist_ok=True) with pytest.raises(FileExistsError): path.mkdir(exist_ok=False) # with pytest.raises(FileNotFoundError): # Pathy("/test-second-bucket/test-directory/file.name").mkdir() # Pathy("/test-second-bucket/test-directory/file.name").mkdir(parents=True) assert path.exists() # remove the bucket # client = storage.Client() # bucket = client.lookup_bucket(bucket_name) # bucket.delete() path.rmdir() assert not path.exists()