def test_basic_storage_and_retrieval(): x = np.arange(3) y = np.repeat(np.linspace(0, 1, 5).reshape(1, -1), 3, 0) z = np.arange(y.size).reshape(y.shape) data = dd.DataDict( x=dict(values=x, unit='A', __info__='careful!', __moreinfo__='more words in here'), y=dict(values=y, unit='B'), z=dict(values=z, axes=['x', 'y'], unit='C'), __desc__='some description', ) assert data.validate() dds.datadict_to_hdf5(data, str(FILEPATH), append_mode=dds.AppendMode.none) datafromfile = dds.datadict_from_hdf5(str(FILEPATH)) # hdf5 saving added a few extra metas that we need to ignore when # comparing datafromfile = _clean_from_file(datafromfile) assert (data == datafromfile) FILEPATH.unlink()
def test_loader_node(qtbot): dds.DDH5Loader.useUi = False x = np.arange(3) y = np.repeat(np.linspace(0, 1, 5).reshape(1, -1), 3, 0) z = np.arange(y.size).reshape(y.shape) data = dd.DataDict( x=dict(values=x, unit='A', __info__='careful!', __moreinfo__='more words in here'), y=dict(values=y, unit='B'), z=dict(values=z, axes=['x', 'y'], unit='C'), __desc__='some description', ) assert data.validate() dds.datadict_to_hdf5(data, str(FILEPATH), append_mode=dds.AppendMode.new) assert _clean_from_file(dds.datadict_from_hdf5(str(FILEPATH))) == data fc = linearFlowchart(('loader', dds.DDH5Loader)) node = fc.nodes()['loader'] assert fc.outputValues()['dataOut'] is None with qtbot.waitSignal(node.loadingWorker.dataLoaded, timeout=1000) as blocker: node.filepath = str(FILEPATH) out = fc.outputValues()['dataOut'].copy() out.pop('__title__') assert _clean_from_file(out) == data data.add_data(x=[3], y=np.linspace(0, 1, 5).reshape(1, -1), z=np.arange(5).reshape(1, -1)) dds.datadict_to_hdf5(data, str(FILEPATH), append_mode=dds.AppendMode.new) assert _clean_from_file(dds.datadict_from_hdf5(str(FILEPATH))) == data out = fc.outputValues()['dataOut'].copy() out.pop('__title__') assert not _clean_from_file(out) == data with qtbot.waitSignal(node.loadingWorker.dataLoaded, timeout=1000) as blocker: node.update() out = fc.outputValues()['dataOut'].copy() out.pop('__title__') assert _clean_from_file(out) == data FILEPATH.unlink()
def test_appending(): x = np.arange(3) y = np.repeat(np.linspace(0, 1, 5).reshape(1, -1), 3, 0) z = np.arange(y.size).reshape(y.shape) data = dd.DataDict( x=dict(values=x, unit='A', __info__='careful!', __moreinfo__='more words in here'), y=dict(values=y, unit='B'), z=dict(values=z, axes=['x', 'y'], unit='C'), __desc__='some description', ) assert data.validate() dds.datadict_to_hdf5(data, FN, append_mode=dds.AppendMode.none) assert _clean_from_file(dds.datadict_from_hdf5(FN)) == data data.add_data(x=[4], y=np.linspace(0, 1, 5).reshape(1, -1), z=np.arange(5).reshape(1, -1)) assert data.validate() dds.datadict_to_hdf5(data, FN, append_mode=dds.AppendMode.new) assert _clean_from_file(dds.datadict_from_hdf5(FN)) == data dds.datadict_to_hdf5(data, FN, append_mode=dds.AppendMode.all) ret = _clean_from_file(dds.datadict_from_hdf5(FN)) assert ret == (data + data)