def test_hdf5_export_import(): """Try subsequent export and import to pickle.""" data = io_test.gen_example_data() with tempfile.TemporaryDirectory() as tdir: filename = 'test.hdf5' with h5py.File(os.path.join(tdir, filename), 'w') as f: hdf5_io.save_to_hdf5(f, data) with h5py.File(os.path.join(tdir, filename), 'r') as f: data_imported = hdf5_io.load_from_hdf5(f) io_test.assert_equal_data(data_imported, data)
def test_hdf5_export_import(tmp_path): """Try subsequent export and import to pickle.""" data = io_test.gen_example_data() io_test.assert_event_handler_example_works( data) #if this fails, it's not import/export filename = tmp_path / 'test.hdf5' with h5py.File(str(filename), 'w') as f: hdf5_io.save_to_hdf5(f, data) with h5py.File(str(filename), 'r') as f: data_imported = hdf5_io.load_from_hdf5(f) io_test.assert_equal_data(data_imported, data) io_test.assert_event_handler_example_works(data_imported)
def wrapper(*args, **kwargs): # if there is no such folder, create another one; if exists, doesn't matter Path(folder_prefix).mkdir(parents=True, exist_ok=True) file_name = full_path(prefix=folder_prefix, **kwargs) # if the file already existed then don't do the computation again if os.path.isfile(file_name): print("This file already existed. Pass.") return 0 else: result = run(*args, **kwargs) with h5py.File(file_name, 'w') as f: hdf5_io.save_to_hdf5(f, result) return result
def export_to_datadir(): filename = io_test.get_datadir_filename("exported_from_tenpy_{0}.hdf5") data = io_test.gen_example_data() with warnings.catch_warnings(record=True) as caught: #warnings.filterwarnings("ignore", category=UserWarning) with h5py.File(filename, 'w') as f: hdf5_io.save_to_hdf5(f, data) for w in caught: msg = str(w.message) expected = "without explicit HDF5 format" in msg if expected: expected = any(t in msg for t in [ 'io_test.DummyClass', 'tenpy.tools.events.EventHandler', 'tenpy.tools.events.Listener', 'method' ]) if not expected: warnings.showwarning(w.message, w.category, w.filename, w.lineno, w.file, w.line)
def export_to_datadir(): filename = io_test.get_datadir_filename("exported_from_tenpy_{0}.hdf5") data = io_test.gen_example_data() with h5py.File(filename, 'w') as f: hdf5_io.save_to_hdf5(f, data)