From 90642e6191e7dff848772226aa09e36b8fe40406 Mon Sep 17 00:00:00 2001 From: montmorillonite Date: Wed, 20 Sep 2023 22:27:28 +0800 Subject: [PATCH 1/2] Test Reaction_check_integral --- chempy/tests/test_chemistry.py | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/chempy/tests/test_chemistry.py b/chempy/tests/test_chemistry.py index 8c5aa811..22dffbd7 100644 --- a/chempy/tests/test_chemistry.py +++ b/chempy/tests/test_chemistry.py @@ -205,6 +205,47 @@ def test_Reaction_from_string__units(): Reaction.from_string("H2O -> H+ + OH-; 1e-4/M/s", "H2O H+ OH-".split()) +@requires(parsing_library, units_library) +def test_Reaction_check_integral(): + + # this could be sympy.core.numbers.Integer + Reaction(*balance_stoichiometry({"H2", "O2"}, {"H2O"})) + + class MyInt: + def __init__(self, __data): + self.__data = __data + + def __eq__(self, other): + return self.__data == other + + def __lt__(self, other): + return self.__data < other + + def __int__(self): + return self.__data + + def __rsub__(self, other): + return other - self.__data + + class MyOne: + def __eq__(self, other): + return 1 == other + + def __lt__(self, other): + return 1 < other + + def __int__(self): + return 1 + + def __rsub__(self, other): + return other - 1 + + Reaction({"H2": MyInt(2), "O2": MyOne()}, {"H2O": 2}) + + with pytest.raises(ValueError): + Reaction({"H2": 1, "O2": 0.5}, {"H2O": 1}) + + @requires(parsing_library, units_library) def test_Substance__molar_mass(): mw_water = Substance.from_formula("H2O").molar_mass(default_units) From eff946ec8d85ae67bdebb726c79ab7c1f8966b83 Mon Sep 17 00:00:00 2001 From: montmorillonite Date: Wed, 20 Sep 2023 22:52:34 +0800 Subject: [PATCH 2/2] Rename test function name --- chempy/tests/test_chemistry.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chempy/tests/test_chemistry.py b/chempy/tests/test_chemistry.py index 22dffbd7..af32c1b6 100644 --- a/chempy/tests/test_chemistry.py +++ b/chempy/tests/test_chemistry.py @@ -206,9 +206,8 @@ def test_Reaction_from_string__units(): @requires(parsing_library, units_library) -def test_Reaction_check_integral(): +def test_Reaction__check_integral(): - # this could be sympy.core.numbers.Integer Reaction(*balance_stoichiometry({"H2", "O2"}, {"H2O"})) class MyInt: @@ -266,7 +265,7 @@ def test_Equilibrium__as_reactions(): @requires(parsing_library) -def test_ReactioN__latex(): +def test_Reaction__latex(): keys = "H2O H2 O2".split() subst = {k: Substance.from_formula(k) for k in keys} r2 = Reaction.from_string("2 H2O -> 2 H2 + O2", subst)