Skip to content

Commit

Permalink
tests: switch to lighter-weight custom scheme tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kujenga committed Sep 3, 2024
1 parent 1b3f153 commit 672f724
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 43 deletions.
45 changes: 3 additions & 42 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
S3Path,
)
from cloudpathlib.azure.azblobclient import _hns_rmtree
from cloudpathlib.client import register_client_class
from cloudpathlib.cloudpath import implementation_registry, register_path_class
from cloudpathlib.cloudpath import implementation_registry
from cloudpathlib.local import (
LocalAzureBlobClient,
LocalAzureBlobPath,
Expand Down Expand Up @@ -317,7 +316,8 @@ def s3_rig(request, monkeypatch, assets_dir):
bucket.objects.filter(Prefix=test_dir).delete()


def _custom_s3_rig_helper(request, monkeypatch, assets_dir, path_class, client_class):
@fixture()
def custom_s3_rig(request, monkeypatch, assets_dir):
"""
Custom S3 rig used to test the integrations with non-AWS S3-compatible object storages like
- MinIO (https://min.io/)
Expand Down Expand Up @@ -402,43 +402,6 @@ def _spin_up_bucket():
bucket.objects.filter(Prefix=test_dir).delete()


@fixture()
def custom_s3_rig(request, monkeypatch, assets_dir):
"""
Custom S3 rig used to test the integrations with non-AWS S3-compatible object storages like
- MinIO (https://min.io/)
- CEPH (https://ceph.io/ceph-storage/object-storage/)
- others
"""
yield from _custom_s3_rig_helper(request, monkeypatch, assets_dir, S3Path, S3Client)


@register_path_class("mys3")
class MyS3Path(S3Path):
cloud_prefix: str = "mys3://"


@register_client_class("mys3")
class MyS3Client(S3Client):
pass


# Mirrors the definition of the S3Client class
MyS3Client.MyS3Path = MyS3Client.CloudPath # type: ignore


@fixture()
def custom_scheme_s3_rig(request, monkeypatch, assets_dir):
"""
Custom S3 rig used to test the integrations with non-AWS S3-compatible object storages like
- MinIO (https://min.io/)
- CEPH (https://ceph.io/ceph-storage/object-storage/)
- others
with the addition of a custom scheme being used.
"""
yield from _custom_s3_rig_helper(request, monkeypatch, assets_dir, MyS3Path, MyS3Client)


@fixture()
def local_azure_rig(request, monkeypatch, assets_dir):
drive = os.getenv("LIVE_AZURE_CONTAINER", DEFAULT_CONTAINER_NAME)
Expand Down Expand Up @@ -532,7 +495,6 @@ def local_s3_rig(request, monkeypatch, assets_dir):
gs_rig,
s3_rig,
custom_s3_rig,
custom_scheme_s3_rig,
local_azure_rig,
local_s3_rig,
local_gs_rig,
Expand All @@ -545,6 +507,5 @@ def local_s3_rig(request, monkeypatch, assets_dir):
[
s3_rig,
custom_s3_rig,
custom_scheme_s3_rig,
],
)
36 changes: 35 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import mimetypes
import os
from pathlib import Path
import random
import string
from pathlib import Path

from cloudpathlib import CloudPath
from cloudpathlib.client import register_client_class
from cloudpathlib.cloudpath import register_path_class
from cloudpathlib.s3.s3client import S3Client
from cloudpathlib.s3.s3path import S3Path


def test_default_client_instantiation(rig):
Expand Down Expand Up @@ -116,3 +119,34 @@ def my_content_type(path):

for suffix, content_type in mimes:
_test_write_content_type(suffix, content_type, rig)


@register_path_class("mys3")
class MyS3Path(S3Path):
cloud_prefix: str = "mys3://"


@register_client_class("mys3")
class MyS3Client(S3Client):
pass


def test_custom_mys3path_instantiation():
path = MyS3Path("mys3://bucket/dir/file.txt")
assert isinstance(path, MyS3Path)
assert path.cloud_prefix == "mys3://"
assert path.bucket == "bucket"
assert path.key == "dir/file.txt"


def test_custom_mys3client_instantiation():
client = MyS3Client()
assert isinstance(client, MyS3Client)
assert client.CloudPath("mys3://bucket/dir/file.txt").cloud_prefix == "mys3://"


def test_custom_mys3client_default_client():
MyS3Client().set_as_default_client()
path = CloudPath("mys3://bucket/dir/file.txt")
assert isinstance(path.client, MyS3Client)
assert path.cloud_prefix == "mys3://"

0 comments on commit 672f724

Please sign in to comment.