File: test_validate.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 (31 lines) | stat: -rw-r--r-- 1,150 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
"""Test functionalities of cobra component validation functions."""

import pytest

from cobra.core import Metabolite, Model, Reaction
from cobra.manipulation import check_mass_balance, check_metabolite_compartment_formula


def test_validate_mass_balance(model: Model) -> None:
    """Test reaction mass balance validation."""
    assert len(check_mass_balance(model)) == 0
    # if we remove the SBO term which marks the reaction as
    # mass balanced, then the reaction should be detected as
    # no longer mass balanced
    EX_rxn = model.reactions.query(lambda r: r.boundary)[0]
    EX_rxn.annotation.pop("sbo")
    balance = check_mass_balance(model)
    assert len(balance) == 1
    assert EX_rxn in balance
    m1 = Metabolite("m1", formula="()")
    r1 = Reaction("r1")
    r1.add_metabolites({m1: 1})
    with pytest.raises(ValueError), pytest.warns(UserWarning):
        r1.check_mass_balance()


def test_validate_formula_compartment(model: Model) -> None:
    """Test metabolite formulae validation."""
    model.metabolites[1].formula = "(a*.bcde)"
    errors = check_metabolite_compartment_formula(model)
    assert len(errors) == 1