def test_load_saved_dict_node_with_array(self): arr = np.arange(100) arr1 = np.arange(200) with temp_file() as filename: # Write data to new dict node and close. with open_h5file(filename, "w") as h5: h5dict = H5DictNode.add_to_h5file(h5, NODE) h5dict["arr"] = arr # Read dict node and make sure the data was saved. with open_h5file(filename, mode="r+") as h5: h5dict = h5[NODE] np.testing.assert_allclose(h5dict["arr"], arr) # Change data for next test h5dict["arr"] = arr1 h5dict["arr_old"] = arr # Check that data is modified by the previous write. with open_h5file(filename) as h5: h5dict = h5[NODE] np.testing.assert_allclose(h5dict["arr"], arr1) np.testing.assert_allclose(h5dict["arr_old"], arr) # Make sure that arrays come back as arrays assert isinstance(h5dict["arr"], np.ndarray) assert isinstance(h5dict["arr_old"], np.ndarray)
def test_create_with_array_data(self): foo = np.arange(100) bar = np.arange(150) with temp_h5_file() as h5: data = {"a": 10, "foo": foo, "bar": bar} h5dict = H5DictNode.add_to_h5file(h5, NODE, data) assert h5dict["a"] == 10 np.testing.assert_allclose(h5dict["foo"], foo) np.testing.assert_allclose(h5dict["bar"], bar)
def test_delete_array(self): with temp_h5_file() as h5: data = dict(a=np.arange(10)) h5dict = H5DictNode.add_to_h5file(h5, NODE, data) del h5dict["a"] assert "a" not in h5dict assert "a" not in h5[NODE]
def test_list_selection_of_numpy_array_items(self): data = numpy.arange(10) all_items = [data, data + 10, data + 30] selected = [all_items[0], all_items[2]] list_selection = ListSelection.from_available_items( provider_id="foo", selected=selected, all_items=all_items) self.assertEqual(list_selection.items, selected) self.assertEqual(list_selection.indices, [0, 2])
def test_list_selection_with_invalid_selected_items(self): data = numpy.arange(10) all_items = [data, data + 10, data + 30] selected = [ data - 10, ] with self.assertRaises(ValueError): ListSelection.from_available_items(provider_id="foo", selected=selected, all_items=all_items)