def test_clients_set_client_params():
    register_client("test", BucketClientTest)
    with pytest.raises(TypeError):
        get_client("test")

    set_client_params("test", required_arg=True)
    client = get_client("test")
    assert isinstance(client, BucketClientTest)
Beispiel #2
0
def test_s3_bucket_client_list_blobs(with_adapter: str, bucket: str) -> None:
    """Test corner-case in S3 client that isn't easily reachable from Pathy"""
    from pathy.s3 import BucketClientS3

    client: BucketClientS3 = get_client("s3")
    root = Pathy("s3://invalid_h3gE_ds5daEf_Sdf15487t2n4")
    assert len(list(client.list_blobs(root))) == 0
Beispiel #3
0
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_clients_set_client_params_recreates_client():
    register_client("test", BucketClientTest)
    set_client_params("test", required_arg=False)
    client: BucketClientTest = get_client("test")
    assert client.required_arg is False
    set_client_params("test", required_arg=True)
    assert client.required_arg is True
    assert isinstance(client, BucketClientTest)
Beispiel #5
0
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
Beispiel #6
0
def test_file_bucket_client_fs_make_uri(with_adapter: str) -> None:
    client: BucketClientFS = get_client("gs")
    blob = Pathy("gs://foo/bar")
    actual = client.make_uri(blob)
    expected = f"file://{client.root}/foo/bar"
    assert actual == expected

    # Invalid root
    other = Pathy("")
    with pytest.raises(ValueError):
        client.make_uri(other)
Beispiel #7
0
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
Beispiel #8
0
def test_file_bucket_client_fs_create_bucket(with_adapter: str) -> None:
    client: BucketClientFS = get_client("gs")
    # Invalid root
    invalid = Pathy("")
    with pytest.raises(ValueError):
        client.create_bucket(invalid)

    # Can create a bucket with a valid path
    root = Pathy("gs://bucket_name")
    assert client.create_bucket(root) is not None

    # Bucket already exists error
    with pytest.raises(FileExistsError):
        client.create_bucket(root)
Beispiel #9
0
def test_file_bucket_client_fs_get_bucket(with_adapter: str) -> None:
    client: BucketClientFS = get_client("gs")
    # Invalid root
    invalid = Pathy("")
    with pytest.raises(ValueError):
        client.get_bucket(invalid)

    # Can create a bucket with a valid path
    root = Pathy("gs://bucket_name")

    # Bucket doesn't exist error
    with pytest.raises(FileNotFoundError):
        client.get_bucket(root)

    # Create the bucket
    client.create_bucket(root)

    # Now it's found
    assert client.get_bucket(root) is not None
Beispiel #10
0
def test_clients_get_client_errors_with_unknown_scheme():
    with pytest.raises(ValueError):
        get_client("foo")
Beispiel #11
0
def test_clients_get_client_works_with_builtin_schems():
    assert isinstance(get_client("gs"), BucketClientGCS)
    assert isinstance(get_client("file"), BucketClientFS)
Beispiel #12
0
def test_s3_import_error_missing_deps() -> None:
    use_fs(False)
    with pytest.raises(ImportError):
        get_client("s3")
def test_clients_get_client_respects_use_fs_override():
    use_fs(True)
    assert isinstance(get_client("gs"), BucketClientFS)
    use_fs(False)
Beispiel #14
0
def test_gcs_import_error_missing_deps() -> None:
    with pytest.raises(ImportError):
        get_client("gs")
Beispiel #15
0
def test_clients_get_client_works_with_optional_builtin_schems() -> None:
    from pathy.gcs import BucketClientGCS

    assert isinstance(get_client("gs"), BucketClientGCS)