Skip to content

Commit

Permalink
make warning assertion more robust
Browse files Browse the repository at this point in the history
Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz committed Aug 5, 2024
1 parent 2e0940c commit 23e62f1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/analysis/elasticity/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def test_new(self):
UserWarning, match="Input elastic tensor does not satisfy standard Voigt symmetries"
) as warns:
ElasticTensor(non_symm)
assert len(warns) == 1
assert sum("Input elastic tensor does not satisfy standard Voigt symmetries" in str(warn) for warn in warns) == 1

bad_tensor1 = np.zeros((3, 3, 3))
bad_tensor2 = np.zeros((3, 3, 3, 2))
Expand Down Expand Up @@ -220,7 +220,8 @@ def test_from_independent_strains(self):
stresses = self.toec_dict["stresses"]
with pytest.warns(UserWarning, match="No eq state found, returning zero voigt stress") as warns:
et = ElasticTensor.from_independent_strains(strains, stresses)
assert len(warns) == 2
assert sum("No eq state found" in str(warn) for warn in warns) == 1
assert sum("Extra strain states in strain-" in str(warn) for warn in warns) == 1
assert_allclose(et.voigt, self.toec_dict["C2_raw"], atol=1e1)

def test_energy_density(self):
Expand Down

0 comments on commit 23e62f1

Please sign in to comment.