Skip to content

Commit 378eea9

Browse files
committed
Write better tests.
1 parent 33f16ba commit 378eea9

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

tests/analysis/test_phase_diagram.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def test_get_critical_compositions(self):
574574
gppd = GrandPotentialPhaseDiagram(self.pd.all_entries, {"Xe": 1}, [*self.pd.elements, Element("Xe")])
575575
with pytest.raises(
576576
ValueError,
577-
match="Li3 Fe1 O4 Xe1 has elements not in the phase diagram O, Fe, Li",
577+
match="Li3 Fe1 O4 Xe1 has elements not in the phase diagram",
578578
):
579579
gppd.get_critical_compositions(Composition("Fe2O3"), Composition("Li3FeO4Xe"))
580580

@@ -854,8 +854,6 @@ def test_getitem(self):
854854
pd = self.ppd[chem_space]
855855
assert isinstance(pd, PhaseDiagram)
856856
assert chem_space in pd._qhull_spaces
857-
assert len(str(pd)) == 186
858-
assert str(pd).startswith("V-H-C-O phase diagram\n25 stable phases:")
859857

860858
with pytest.raises(KeyError, match="frozenset"):
861859
self.ppd[frozenset(map(Element, "HBCNOFPS"))]

tests/analysis/test_reaction_calculator.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ def test_scientific_notation(self):
155155
assert rxn == Reaction.from_str(str(rxn))
156156

157157
rxn2 = Reaction.from_str("FePO4 + 20 CO -> 1e1 O2 + Fe1P1O4 + 20 C")
158-
assert str(rxn2) == "20 CO -> 20 C + 10 O2"
158+
rxn2str = str(rxn2)
159+
assert rxn2str.startswith("20 CO ->")
160+
assert "20 C" in rxn2str
161+
assert "10 O2" in rxn2str
159162

160163
def test_equals(self):
161164
reactants = [Composition("Fe"), Composition("O2")]
@@ -293,7 +296,10 @@ def setup_method(self) -> None:
293296
self.rxn = BalancedReaction(rct, prod)
294297

295298
def test_init(self):
296-
assert str(self.rxn) == "24 Li + Na2S + 3 K2SO4 -> 2 KNaS + 2 K2S + 12 Li2O"
299+
rxnstr = str(self.rxn)
300+
reactants, products = rxnstr.split(" -> ")
301+
assert set(reactants.split(" + ")) == {"24 Li", "Na2S", "3 K2SO4"}
302+
assert set(products.split(" + ")) == {"2 KNaS", "2 K2S", "12 Li2O"}
297303

298304
# Test unbalanced exception
299305
rct = {"K2SO4": 1, "Na2S": 1, "Li": 24}
@@ -329,9 +335,6 @@ def test_remove_spectator_species(self):
329335

330336
assert "Na" not in rxn.all_comp
331337

332-
def test_hash(self):
333-
assert hash(self.rxn) == 4774511606373046513
334-
335338

336339
class TestComputedReaction:
337340
def setup_method(self):

0 commit comments

Comments
 (0)