forked from opencobra/cobrapy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_yaml.py
34 lines (27 loc) · 1.08 KB
/
test_yaml.py
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
"""Test functionalities of I/O in YAML format."""
import json
from os.path import join
from typing import Callable
import pytest
from ruamel.yaml import YAML
from cobra import Model
from cobra import io as cio
def test_load_yaml_model(
compare_models: Callable, data_directory: str, mini_model: Model
) -> None:
"""Test the reading of YAML model."""
yaml_model = cio.load_yaml_model(join(data_directory, "mini.yml"))
assert compare_models(mini_model, yaml_model) is None
@pytest.mark.xfail(reason="schema outdated")
def test_save_yaml_model(tmpdir: str, mini_model: Model) -> None:
"""Test the writing of YAML model."""
jsonschema = pytest.importorskip("jsonschema")
output_file = tmpdir.join("mini.yml")
cio.save_yaml_model(mini_model, output_file.strpath, sort=True)
# validate against JSONSchema
yaml = YAML(typ="unsafe")
with open(output_file.strpath, "r") as infile:
yaml_to_dict = yaml.load(infile)
dict_to_json = json.dumps(yaml_to_dict)
loaded = json.loads(dict_to_json)
assert jsonschema.validate(loaded, cio.json.json_schema)