def test_extension(tmpdir): file = tmpdir / 'file' pb.save(mock_data, file) assert mock_data == pb.load(tmpdir / 'file.pbz') file = tmpdir / 'file.ext' pb.save(mock_data, file) assert mock_data == pb.load(tmpdir / 'file.ext')
def test_pickle_round_trip(lattice, tmpdir): file_name = str(tmpdir.join('file.npz')) pb.save(lattice, file_name) from_file = pb.load(file_name) assert lattice.sub_name_map == from_file.sub_name_map assert lattice.hop_name_map == from_file.hop_name_map assert pytest.fuzzy_equal(lattice, from_file)
def get_expected(result, group=''): file = path_from_fixture(request, prefix='baseline_data', ext='.pbz', override_group=group) if not request.config.getoption("--savebaseline") and file.exists(): return pb.load(file) elif not request.config.getoption("--readonly"): if not file.parent.exists(): file.parent.mkdir(parents=True) pb.save(result, file) return result else: raise RuntimeError("Missing baseline data: {}".format(file))
def test_path_type(tmpdir): # str file = str(tmpdir / 'file') assert round_trip(mock_data, file) # py.path.local object file = tmpdir / 'file' assert round_trip(mock_data, file) # pathlib object file = pathlib.Path(str(tmpdir)) / 'file' assert round_trip(mock_data, file) # file object file = str(tmpdir / 'file') with open(file, 'wb') as f: pb.save(mock_data, f) with open(file, 'rb') as f: assert mock_data == pb.load(f)
def round_trip(obj, file): pb.save(obj, file) return pb.load(file) == obj
def test_pickle_round_trip(solver, tmpdir): file_name = str(tmpdir.join('file.npz')) pb.save(solver, file_name) from_file = pb.load(file_name) assert pytest.fuzzy_equal(solver, from_file)
def test_pickle_round_trip(model, tmpdir): file_name = str(tmpdir.join('file.npz')) pb.save(model.system, file_name) from_file = pb.load(file_name) assert pytest.fuzzy_equal(model.system, from_file)