def test_recursive_adds_nested_numpy_array_to_h5file(): """Test that a numpy array nested in a dict is added to h5file.""" test_file = os.path.join(DATA_PATH, 'test_output', 'test.h5') test_array = np.arange(10) path = '/' good_dict = {'0': {1: test_array}} with h5py.File(test_file, 'w') as h5_test: metrics_io._recursively_save_dict_to_group(h5_test, path, good_dict) assert np.allclose(test_array, h5_test["0/1"][()]) os.remove(test_file)
def test_recursive_adds_nested_scalar_to_h5file(): """Test that a scalar nested in a dict is added to h5file.""" test_file = os.path.join(DATA_PATH, 'test_output', 'test.h5') test_scalar = 'hello world' good_dict = {'0': {'filestem': test_scalar}} path = '/' with h5py.File(test_file, 'w') as h5_test: metrics_io._recursively_save_dict_to_group(h5_test, path, good_dict) assert np.string_(test_scalar), h5_test["0/filestem"][()] os.remove(test_file)
def test_recursive_adds_numpy_array_to_h5file(): """Test that proper numpy arrays are added to h5file.""" test_file = os.path.join(DATA_PATH, 'test_output', 'test.h5') test_array = np.arange(10) path = '/' good_dict = {'0': test_array} with h5py.File(test_file, 'w') as h5_test: metrics_io._recursively_save_dict_to_group(h5_test, path, good_dict) nt.assert_true(np.allclose(test_array, h5_test["0"].value)) os.remove(test_file)
def test_recursive_adds_scalar_to_h5file(): """Test that a scalar type is added to h5file.""" test_file = os.path.join(DATA_PATH, 'test_output', 'test.h5') test_scalar = 'hello world' path = '/' good_dict = {'filestem': test_scalar} with h5py.File(test_file, 'w') as h5_test: metrics_io._recursively_save_dict_to_group(h5_test, path, good_dict) # we convert to np.string_ types so use that to compare assert np.string_(test_scalar), h5_test["filestem"][()] os.remove(test_file)
def test_recursive_adds_scalar_to_h5file(): """Test that a scalar type is added to h5file.""" test_file = os.path.join(DATA_PATH, 'test_output', 'test.h5') test_scalar = 'hello world' path = '/' good_dict = {'0': test_scalar} with h5py.File(test_file, 'w') as h5_test: metrics_io._recursively_save_dict_to_group(h5_test, path, good_dict) nt.assert_equal(test_scalar, h5_test["0"].value) os.remove(test_file)