Skip to content

Commit

Permalink
tests: add missing fixtures for S3FileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Oct 20, 2023
1 parent dd01276 commit 267e6fe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
39 changes: 26 additions & 13 deletions tests/test_rtdc_fmt_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

from dclab.rtdc_dataset.fmt_s3 import is_s3_url, is_s3_object_available

try:
from s3fs import S3FileSystem
except ImportError:
S3FileSystem = None


pytest.importorskip("s3fs")

Expand All @@ -22,6 +27,14 @@
allow_module_level=True)


@pytest.fixture(autouse=True)
def s3fs_cleanup():
# Clear the cache so we get a clean slate every time we instantiate
# an S3FileSystem.
yield
S3FileSystem.cachable = False


def test_cache_features():
# This is the calibration beads measurement.
# https://dcor.mpl.mpg.de/dataset/figshare-7771184-v2/
Expand All @@ -30,14 +43,14 @@ def test_cache_features():
"circle-5a7a053d-55fb-4f99-960c-f478d0bd418f/"
"resource/fb7/19f/b2-bd9f-817a-7d70-f4002af916f0")

ds = dclab.new_dataset(s3_url)
t0 = time.perf_counter()
_ = ds["deform"][:]
t1 = time.perf_counter()
for ii in range(50):
with dclab.new_dataset(s3_url) as ds:
t0 = time.perf_counter()
_ = ds["deform"][:]
t2 = time.perf_counter()
assert t2 - t1 < t1 - t0
t1 = time.perf_counter()
for ii in range(50):
_ = ds["deform"][:]
t2 = time.perf_counter()
assert t2 - t1 < t1 - t0


@pytest.mark.parametrize("url, avail", [
Expand Down Expand Up @@ -67,12 +80,12 @@ def test_open_public_s3_dataset():
"circle-5a7a053d-55fb-4f99-960c-f478d0bd418f/"
"resource/fb7/19f/b2-bd9f-817a-7d70-f4002af916f0")

ds = dclab.new_dataset(s3_url)
assert ds.config["experiment"]["sample"] == "calibration_beads"
assert len(ds) == 5000
assert np.allclose(ds["deform"][100], 0.013640802,
atol=0,
rtol=1e-5)
with dclab.new_dataset(s3_url) as ds:
assert ds.config["experiment"]["sample"] == "calibration_beads"
assert len(ds) == 5000
assert np.allclose(ds["deform"][100], 0.013640802,
atol=0,
rtol=1e-5)


@pytest.mark.parametrize("url", [
Expand Down
13 changes: 13 additions & 0 deletions tests/test_rtdc_fmt_s3_basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from dclab import new_dataset, RTDCWriter
from dclab.rtdc_dataset.fmt_s3 import S3Basin

try:
from s3fs import S3FileSystem
except ImportError:
S3FileSystem = None


from helper_methods import retrieve_data

Expand All @@ -30,6 +35,14 @@
allow_module_level=True)


@pytest.fixture()
def s3fs_cleanup():
# Clear the cache so we get a clean slate every time we instantiate
# an S3FileSystem.
yield
S3FileSystem.cachable = False


def test_basin_as_dict(tmp_path):
tmp_path = tmp_path.resolve()
h5path = tmp_path / "test_basin_s3.rtdc"
Expand Down

0 comments on commit 267e6fe

Please sign in to comment.