Пример #1
0
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')
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
    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))
Пример #5
0
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)
Пример #6
0
def round_trip(obj, file):
    pb.save(obj, file)
    return pb.load(file) == obj
Пример #7
0
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)
Пример #8
0
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)
Пример #9
0
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)