File: test_formula.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 (28 lines) | stat: -rw-r--r-- 731 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
"""Test functions of formula.py ."""

import pytest

from cobra.core.formula import Formula


def test_formula_init() -> None:
    """Test initialization."""
    f = Formula("H2O")
    assert "Formula H2O" in repr(f)
    f = Formula("H2O", name="Water")
    assert f.name == "Water"


@pytest.mark.parametrize(
    ["formula", "weight"], [["H2O", 18.01528], ["C6H12O6", 180.15588], ["NO3", 62.0049]]
)
def test_formula_weight(formula, weight) -> None:
    """Test molecular weight calculation."""
    assert Formula(formula).weight == pytest.approx(weight)


def test_formula_wrong() -> None:
    """Test incorrect formula elements."""
    with pytest.warns(UserWarning):
        w = Formula("NOX").weight
        assert w is None