1import math
2from chempy import Reaction
3from chempy.units import allclose, default_units as u
4from ..testing import requires
5from ..rendering import eval_template
6from ..parsing import get_parsing_context
7from chempy.units import units_library
8
9
10@requires(units_library)
11def test_eval_template():
12    rendered = eval_template("${2*pi*arg*m**2}", arg=1 / math.pi)
13    val = eval(rendered, get_parsing_context())
14    assert allclose(val, 2 * u.m ** 2)
15
16
17@requires(units_library)
18def test_eval_template__Reaction():
19    rendered = eval_template("2 OH -> H2O2; ${6*pi*arg}/M/s", arg=1 / math.pi)
20    assert allclose(
21        Reaction.from_string(rendered).param,
22        Reaction.from_string("2 OH -> H2O2; 6.0/M/s").param,
23    )
24