File: test_pickle.py

package info (click to toggle)
python-cobra 0.29.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,512 kB
  • sloc: python: 14,703; xml: 12,841; makefile: 137; sh: 32
file content (39 lines) | stat: -rw-r--r-- 1,051 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Test data storage and recovery using pickle."""

from pathlib import Path
from pickle import dump, load
from typing import Callable

import pytest

from cobra import Model


@pytest.mark.parametrize("load_function", [load])
def test_read_pickle(
    compare_models: Callable,
    data_directory: Path,
    mini_model: Model,
    load_function: Callable,
):
    """Test the reading of model from pickle."""
    if load_function is None:
        pytest.skip()

    with open(data_directory.joinpath("mini.pickle"), "rb") as infile:
        pickle_model = load_function(infile)

    assert compare_models(mini_model, pickle_model) is None


@pytest.mark.parametrize("dump_function", [dump])
def test_write_pickle(tmp_path: Path, mini_model: Model, dump_function: Callable):
    """Test the writing of model to pickle."""
    if dump_function is None:
        pytest.skip()

    output_file = tmp_path.joinpath("mini.pickle")
    with open(str(output_file), "wb") as outfile:
        dump_function(mini_model, outfile)

    assert output_file.exists()