|
| 1 | +"""Test reading HERD from files created with hdmf-common-schema 1.8.0. |
| 2 | +
|
| 3 | +In schema 1.8.0, HERD was defined in the hdmf-experimental namespace. |
| 4 | +These tests verify that HERD is read correctly and is resolved to the |
| 5 | +hdmf-common namespace when using the current schema. |
| 6 | +""" |
| 7 | + |
| 8 | +from hdmf.common import get_hdf5io, get_type_map, CORE_NAMESPACE, SimpleMultiContainer |
| 9 | +from hdmf.common.resources import HERD |
| 10 | +from hdmf.testing import TestCase |
| 11 | + |
| 12 | + |
| 13 | +class TestHERD_1_8_0(TestCase): |
| 14 | + """Test reading HERD from files written with hdmf-common-schema 1.8.0. |
| 15 | +
|
| 16 | + The test files were generated by make_test_files.py using hdmf 4.3.1 |
| 17 | + (hdmf-common-schema 1.8.0) where HERD was in the hdmf-experimental |
| 18 | + namespace. The HDF5 file contains a SimpleMultiContainer with a Data |
| 19 | + object, and the ZIP file contains the HERD tables. |
| 20 | + """ |
| 21 | + |
| 22 | + def setUp(self): |
| 23 | + self.path_h5 = "tests/unit/back_compat_tests/herd_1_8_0.h5" |
| 24 | + self.path_zip = "tests/unit/back_compat_tests/herd_1_8_0.zip" |
| 25 | + |
| 26 | + def test_read_container(self): |
| 27 | + """Test that the SimpleMultiContainer with data is read correctly.""" |
| 28 | + with get_hdf5io(path=self.path_h5, mode="r") as io: |
| 29 | + container = io.read() |
| 30 | + self.assertIsInstance(container, SimpleMultiContainer) |
| 31 | + self.assertIn("species", container.containers) |
| 32 | + |
| 33 | + def test_read_herd_from_zip(self): |
| 34 | + """Test that HERD written under hdmf-experimental is read correctly from ZIP.""" |
| 35 | + herd = HERD.from_zip(path=self.path_zip) |
| 36 | + self.assertIsInstance(herd, HERD) |
| 37 | + self.assertEqual(len(herd.keys.data), 1) |
| 38 | + self.assertEqual(herd.keys.data[0][0], "Homo sapiens") |
| 39 | + self.assertEqual(len(herd.entities.data), 1) |
| 40 | + self.assertEqual(herd.entities.data[0][0], "NCBI_TAXON:9606") |
| 41 | + |
| 42 | + def test_read_herd_with_hdf5io(self): |
| 43 | + """Test that HERD is loaded when reading HDF5 with herd_path.""" |
| 44 | + with get_hdf5io(path=self.path_h5, mode="r", herd_path=self.path_zip) as io: |
| 45 | + io.read() |
| 46 | + self.assertIsInstance(io.herd, HERD) |
| 47 | + |
| 48 | + def test_herd_namespace_is_common(self): |
| 49 | + """Test that HERD is resolved in the hdmf-common namespace.""" |
| 50 | + tm = get_type_map() |
| 51 | + dt = tm.namespace_catalog.get_spec(CORE_NAMESPACE, "HERD") |
| 52 | + self.assertIsNotNone(dt) |
0 commit comments