def test_import_from_datadir(fn):
    print("import ", fn)
    filename = os.path.join(io_test.datadir, fn)
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=FutureWarning)
        with open(filename, 'rb') as f:
            data = pickle.load(f)
    if 'version' in data:
        data_expected = io_test.gen_example_data(data['version'])
    else:
        data_expected = io_test.gen_example_data('0.4.0')
    io_test.assert_equal_data(data, data_expected)
Exemple #2
0
def test_import_from_datadir(fn):
    print("import ", fn)
    filename = os.path.join(io_test.datadir, fn)
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=FutureWarning)
        with h5py.File(filename, 'r') as f:
            data = hdf5_io.load_from_hdf5(f)
    if 'version' in data:
        data_expected = io_test.gen_example_data(data['version'])
    else:
        data_expected = io_test.gen_example_data('0.4.0')
    io_test.assert_equal_data(data, data_expected)
    io_test.assert_event_handler_example_works(data)
def test_pickle():
    """Try subsequent export and import to pickle."""
    data = io_test.gen_example_data()
    with tempfile.TemporaryDirectory() as tdir:
        filename = 'test.pkl'
        with open(os.path.join(tdir, filename), 'wb') as f:
            pickle.dump(data, f)
        with open(os.path.join(tdir, filename), 'rb') as f:
            data_imported = pickle.load(f)
    io_test.assert_equal_data(data_imported, data)
Exemple #4
0
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)
Exemple #5
0
def test_pickle(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.pkl'
    with filename.open('wb') as f:
        pickle.dump(data, f)
    with filename.open('rb') as f:
        data_imported = pickle.load(f)
    io_test.assert_equal_data(data_imported, data)
    io_test.assert_event_handler_example_works(data_imported)
Exemple #6
0
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)
Exemple #7
0
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}.pkl")
    data = io_test.gen_example_data()
    with open(filename, 'wb') as f:
        pickle.dump(data, f, protocol=pickle.HIGHEST_PROTOCOL)
Exemple #9
0
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)