Skip to content
Snippets Groups Projects
Commit cb37a085 authored by florian's avatar florian
Browse files

WIP: Extend h5 test

parent 94d4e55e
No related branches found
No related tags found
2 merge requests!160STY: styling,!143ENH: HDF5 Converter
...@@ -2,16 +2,33 @@ ...@@ -2,16 +2,33 @@
metadata: metadata:
crawler-version: 0.6.1 crawler-version: 0.6.1
--- ---
Converters:
H5Dataset:
converter: H5DatasetConverter
package: caoscrawler.hdf5_converter
H5File:
converter: H5FileConverter
package: caoscrawler.hdf5_converter
H5Group:
converter: H5GroupConverter
package: caoscrawler.hdf5_converter
H5Ndarray:
converter: H5NdarrayConverter
package: caoscrawler.hdf5_converter
# Top-level, we have just the HDF5 file. # Top-level, we have just the HDF5 file.
ParentDirectory:
type: Directory
match: (.*)
subtree:
H5FileElement: H5FileElement:
type: H5File type: H5File
match: (.*)\.(hdf5|h5)$ match: (.*)\.(hdf5|h5)$
subtree: subtree:
# Here, we have the groups, the top-level dataset, and possible attributes # Here, we have the groups, the top-level dataset, and possible
# (empty for now). # attributes (empty for now).
RootIntegerElement: RootIntegerElement:
type: H5Dataset type: H5Dataset
match: ^root_integers$ match_name: ^root_integers$
records: records:
H5Dataset: H5Dataset:
parents: parents:
...@@ -20,14 +37,14 @@ H5FileElement: ...@@ -20,14 +37,14 @@ H5FileElement:
# included NDArray in this dataset # included NDArray in this dataset
TopLevelIntNDElement: TopLevelIntNDElement:
type: H5Ndarray type: H5Ndarray
match: (.*) match_name: (.*)
recordname: this recordname: this
records: records:
H5Dataset: +$this H5Dataset: +$this
# There is one more list-valued attribute to this dataset. # There is one more list-valued attribute to this dataset.
TopLevelDataAttribute: TopLevelDataAttribute:
type: ListElement type: ListElement
match: ^attr_data_root$ match_name: ^attr_data_root$
subtree: subtree:
AttributeListEntries: AttributeListEntries:
type: FloatElement type: FloatElement
......
...@@ -19,14 +19,16 @@ ...@@ -19,14 +19,16 @@
# #
import numpy as np import numpy as np
from pathlib import Path
from pytest import fixture, importorskip
from caoscrawler.hdf5_converter import (__convert_basic_element_with_nd_array, from caoscrawler.debug_tree import DebugTree
__convert_h5_element, H5GroupElement, from caoscrawler.hdf5_converter import (convert_basic_element_with_nd_array,
convert_h5_element, H5GroupElement,
H5DatasetElement, H5NdarrayElement) H5DatasetElement, H5NdarrayElement)
from caoscrawler.scanner import scan_directory
from caoscrawler.structure_elements import (FloatElement, ListElement, from caoscrawler.structure_elements import (FloatElement, ListElement,
TextElement) TextElement)
from pathlib import Path
from pytest import fixture, importorskip
# Skip the whole module if h5py hasn't been installed # Skip the whole module if h5py hasn't been installed
h5py = importorskip("h5py") h5py = importorskip("h5py")
...@@ -45,10 +47,10 @@ def h5_dummy_file(): ...@@ -45,10 +47,10 @@ def h5_dummy_file():
def test_h5_elements(h5_dummy_file): def test_h5_elements(h5_dummy_file):
elt = __convert_h5_element(h5_dummy_file["group_level1_a"], "test") elt = convert_h5_element(h5_dummy_file["group_level1_a"], "test")
assert isinstance(elt, H5GroupElement) assert isinstance(elt, H5GroupElement)
elt = __convert_h5_element(h5_dummy_file["root_integers"], "test") elt = convert_h5_element(h5_dummy_file["root_integers"], "test")
assert isinstance(elt, H5DatasetElement) assert isinstance(elt, H5DatasetElement)
...@@ -57,30 +59,38 @@ def test_nd_array_conversion(): ...@@ -57,30 +59,38 @@ def test_nd_array_conversion():
# Only test array handling here, `convert_basic_element` is tested # Only test array handling here, `convert_basic_element` is tested
# elsewhere. # elsewhere.
arr = np.array([[["something"]]]) arr = np.array([[["something"]]])
elt = __convert_basic_element_with_nd_array(arr) elt = convert_basic_element_with_nd_array(arr)
assert isinstance(elt, TextElement) assert isinstance(elt, TextElement)
assert elt.value == "something" assert elt.value == "something"
arr = np.zeros((1, 1)) arr = np.zeros((1, 1))
elt = __convert_basic_element_with_nd_array(arr) elt = convert_basic_element_with_nd_array(arr)
assert isinstance(elt, FloatElement) assert isinstance(elt, FloatElement)
assert elt.value == 0 assert elt.value == 0
arr = np.zeros((1, 3, 1)) arr = np.zeros((1, 3, 1))
elt = __convert_basic_element_with_nd_array(arr) elt = convert_basic_element_with_nd_array(arr)
assert isinstance(elt, ListElement) assert isinstance(elt, ListElement)
assert elt.value == [0, 0, 0] assert elt.value == [0, 0, 0]
arr = np.array([[1, 2, 3], [4, 5, 6]]) arr = np.array([[1, 2, 3], [4, 5, 6]])
elt = __convert_basic_element_with_nd_array(arr, internal_path="some/path") elt = convert_basic_element_with_nd_array(arr, internal_path="some/path")
assert isinstance(elt, H5NdarrayElement) assert isinstance(elt, H5NdarrayElement)
assert elt.internal_path == "some/path" assert elt.internal_path == "some/path"
# Non-arrays should be forwarded correctly # Non-arrays should be forwarded correctly
elt = __convert_basic_element_with_nd_array("something") elt = convert_basic_element_with_nd_array("something")
assert isinstance(elt, TextElement) assert isinstance(elt, TextElement)
assert elt.value == "something" assert elt.value == "something"
elt = __convert_basic_element_with_nd_array([0, 0, 0]) elt = convert_basic_element_with_nd_array([0, 0, 0])
assert isinstance(elt, ListElement) assert isinstance(elt, ListElement)
assert elt.value == [0, 0, 0] assert elt.value == [0, 0, 0]
def test_record_creation():
dbtr = DebugTree()
records = scan_directory(UNITTESTDIR, UNITTESTDIR / "h5_cfood.yml", debug_tree=dbtr)
print(dbtr.debug_tree)
print(dbtr.debug_metadata)
assert False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment