Skip to content

Commit

Permalink
Add logging to test_datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Mar 26, 2024
1 parent bd6fdc3 commit 481a059
Showing 1 changed file with 4 additions and 30 deletions.
34 changes: 4 additions & 30 deletions test/hl/test_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import numpy as np
import math

import logging
import config

if config.get("use_h5py"):
Expand All @@ -23,39 +23,11 @@
from common import ut, TestCase


def read_dtypes(dataset_dtype, names):
""" Returns a 2-tuple containing:
1. Output dataset dtype
2. Dtype containing HDF5-appropriate description of destination
"""

if len(names) == 0: # Not compound, or all fields needed
format_dtype = dataset_dtype

elif dataset_dtype.names is None:
raise ValueError("Field names only allowed for compound types")

elif any(x not in dataset_dtype.names for x in names):
raise ValueError("Field does not appear in this type.")

else:
format_dtype = np.dtype([(name, dataset_dtype.fields[name][0]) for name in names])

if len(names) == 1:
# We don't preserve the field information if only one explicitly selected.
output_dtype = format_dtype.fields[names[0]][0]

else:
output_dtype = format_dtype

return output_dtype, format_dtype


class TestScalarCompound(TestCase):

def setUp(self):
filename = self.getFileName("scalar_compound_dset")
print("filename:", filename)
self.f = h5py.File(filename, "w")
self.data = np.array((42.5, -118, "Hello"), dtype=[('a', 'f'), ('b', 'i'), ('c', '|S10')])
self.dset = self.f.create_dataset('x', data=self.data)
Expand Down Expand Up @@ -180,4 +152,6 @@ def test_nested_compound_vlen(self):


if __name__ == '__main__':
loglevel = logging.ERROR
logging.basicConfig(format='%(asctime)s %(message)s', level=loglevel)
ut.main()

0 comments on commit 481a059

Please sign in to comment.