From 6648cc5079d7cff289f63ae403695358783e06bb Mon Sep 17 00:00:00 2001 From: Derrick Chambers Date: Thu, 27 Feb 2025 16:48:01 -0800 Subject: [PATCH] fix febus format issue --- dascore/io/febus/utils.py | 2 +- dascore/io/neubrex/core.py | 27 +---------------- tests/test_io/test_io_core.py | 14 +++++++++ .../test_io/test_neubrex/test_neubrex_rfs.py | 29 ------------------- 4 files changed, 16 insertions(+), 56 deletions(-) delete mode 100644 tests/test_io/test_neubrex/test_neubrex_rfs.py diff --git a/dascore/io/febus/utils.py b/dascore/io/febus/utils.py index 4d608800..03abf6f7 100644 --- a/dascore/io/febus/utils.py +++ b/dascore/io/febus/utils.py @@ -75,7 +75,7 @@ def _get_febus_version_str(hdf_fi) -> str: # Hopefully this is the file version... version = unbyte(source.attrs.get("Version", version)).split(".")[0] is_febus = is_febus and expected_source_attrs.issubset(set(source.attrs)) - if is_febus: + if inst_keys and is_febus: return version return "" diff --git a/dascore/io/neubrex/core.py b/dascore/io/neubrex/core.py index db03b370..211699fa 100644 --- a/dascore/io/neubrex/core.py +++ b/dascore/io/neubrex/core.py @@ -11,7 +11,7 @@ import dascore.io.neubrex.utils_rfs as rfs_utils from dascore.constants import SpoolType from dascore.io import FiberIO -from dascore.utils.hdf5 import H5Reader, H5Writer +from dascore.utils.hdf5 import H5Reader class NeubrexRFSPatchAttrs(dc.PatchAttrs): @@ -84,31 +84,6 @@ def scan(self, resource: H5Reader, snap=True, **kwargs) -> list[dc.PatchAttrs]: attrs["file_version"] = self.version return [dc.PatchAttrs(**attrs)] - def write( - self, - spool: SpoolType, - resource: H5Writer, - extra_attrs: dict[str, float | int | str] | None = None, - **kwargs, - ) -> None: - """ - Write a Neubrex Rayleigh Frequency Shift file. - - Parameters - ---------- - spool - The spool to write. - resource - The H5file to write to. - extra_attrs - A dict of basic types to write to the Acoustic dataset's - attributes. - **kwargs - Un-used, only here for compat with other write methods. - """ - if len(spool) > 1: - raise ValueError("NeubrexRFS only supports writing a single patch.") - class NeubrexDASV1(FiberIO): """ diff --git a/tests/test_io/test_io_core.py b/tests/test_io/test_io_core.py index 3c3a0e76..912915db 100644 --- a/tests/test_io/test_io_core.py +++ b/tests/test_io/test_io_core.py @@ -7,6 +7,7 @@ from pathlib import Path from typing import TypeVar +import h5py import numpy as np import pandas as pd import pytest @@ -260,6 +261,14 @@ def test_implements(self): class TestGetFormat: """Tests to ensure formats can be retrieved.""" + @pytest.fixture(scope="class") + def empty_h5_path(self, tmpdir_factory): + """Create an empty HDF5 file.""" + path = tmpdir_factory.mktemp("empty") / "empty.h5" + with h5py.File(path, "w"): + pass + return path + def test_not_known(self, dummy_text_file): """Ensure a non-path/str object raises.""" with pytest.raises(UnknownFiberFormatError): @@ -279,6 +288,11 @@ def test_fiberio_directory(self, tmp_path_factory): assert fiber_io.name == name assert fiber_io.version == version + def test_empty_hdf5_no_format(self, empty_h5_path): + """Ensure the empty hdf5 dorsen't have a format.""" + with pytest.raises(UnknownFiberFormatError): + dc.get_format(empty_h5_path) + class TestScan: """Tests for scanning fiber files.""" diff --git a/tests/test_io/test_neubrex/test_neubrex_rfs.py b/tests/test_io/test_neubrex/test_neubrex_rfs.py deleted file mode 100644 index a8ee06a2..00000000 --- a/tests/test_io/test_neubrex/test_neubrex_rfs.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -Tests for Rayleigh Frequency Shift format. -""" - -import pytest - -import dascore as dc - - -class TestWrite: - """Tests for writing to the NeubrexRFS format.""" - - @pytest.fixture(scope="class") - def written_rfs(self, random_patch, tmp_path_factory): - """Write the random patch, return path.""" - path = tmp_path_factory.mktemp("rfs") / "random_rfs.h5" - random_patch.io.write(path, "NeubrexRFS") - return path - - def test_multi_patch_raises(self, random_spool, tmp_path): - """Trying to save multiple patch should raise.""" - msg = "only supports writing a single patch" - with pytest.raises(ValueError, match=msg): - dc.write(random_spool, tmp_path / "bad_file.h5", "NeubrexRFS") - - def test_format(self, written_rfs): - """Ensure the returned format type is correct.""" - format_name = dc.get_format(written_rfs) - assert "NeubrexRFS" in format_name