From 4a5e674924399616afd723533cb7d1d63d065a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Sat, 6 Jan 2024 01:08:35 +0100 Subject: [PATCH] tests: avoid segmentation fault --- tests/test_rtdc_fmt_http_basin.py | 38 +++++++++++++++++-------------- tests/test_rtdc_fmt_s3_basin.py | 3 ++- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/tests/test_rtdc_fmt_http_basin.py b/tests/test_rtdc_fmt_http_basin.py index ba79f0cb..40a65458 100644 --- a/tests/test_rtdc_fmt_http_basin.py +++ b/tests/test_rtdc_fmt_http_basin.py @@ -166,7 +166,8 @@ def test_create_basin_file_non_matching_identifier(tmp_path): assert ds.features_basin == ["deform"] # ...but it is actually not, since the run identifier does not match # and therefore dclab does not allow the user to access it. - with pytest.raises(KeyError, match="deform"): + with (pytest.warns(UserWarning, match="but I cannot get its data"), + pytest.raises(KeyError, match="deform")): _ = ds["deform"] @@ -241,10 +242,10 @@ def test_trace_availability(tmp_path): meta = src.config.as_dict(pop_filtering=True) hw.store_metadata(meta) - ds = dclab.new_dataset(h5path) - ds.filter.manual[0] = False - ds2 = dclab.new_dataset(ds) - assert "trace" in ds2 + with dclab.new_dataset(h5path) as ds: + ds.filter.manual[0] = False + with dclab.new_dataset(ds) as ds2: + assert "trace" in ds2 def test_trace_availability_invalid(tmp_path): @@ -265,15 +266,18 @@ def test_trace_availability_invalid(tmp_path): meta = src.config.as_dict(pop_filtering=True) hw.store_metadata(meta) - ds = dclab.new_dataset(h5path) - ds.filter.manual[:] = False - ds.filter.manual[:2] = True - ds.apply_filter() - assert "trace" in ds - # Until a workaround is found for invalid basin URLs that return a - # status code of 200, do this test which should raise a warning, - # because `__contains__` returns True for "trace", but the trace data - # are nowhere to find. - with (pytest.warns(UserWarning, match="but I cannot get its data"), - pytest.raises(KeyError, match="trace")): - dclab.new_dataset(ds) + with dclab.new_dataset(h5path) as ds: + ds.filter.manual[:] = False + ds.filter.manual[:2] = True + ds.apply_filter() + assert "trace" in ds + # Until a workaround is found for invalid basin URLs that return a + # status code of 200, do this test which should raise a warning, + # because `__contains__` returns True for "trace", but the trace data + # are nowhere to find. + with (pytest.warns(UserWarning, match="but I cannot get its data"), + pytest.raises(KeyError, match="trace")): + _ = ds["trace"] + with (pytest.warns(UserWarning, match="but I cannot get its data"), + pytest.raises(KeyError, match="trace")): + dclab.new_dataset(ds) diff --git a/tests/test_rtdc_fmt_s3_basin.py b/tests/test_rtdc_fmt_s3_basin.py index e50d0490..30d0e055 100644 --- a/tests/test_rtdc_fmt_s3_basin.py +++ b/tests/test_rtdc_fmt_s3_basin.py @@ -135,7 +135,8 @@ def test_create_basin_file_non_matching_identifier(tmp_path): assert ds.features_basin == ["deform"] # ...but it is actually not, since the run identifier does not match # and therefore dclab does not allow the user to access it. - with pytest.raises(KeyError, match="deform"): + with (pytest.warns(UserWarning, match="but I cannot get its data"), + pytest.raises(KeyError, match="deform")): _ = ds["deform"]