Skip to content

Commit

Permalink
test err msg in TestBVAnalyzer.test_get_valences()
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Aug 5, 2023
1 parent 546b690 commit 294f033
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions tests/analysis/test_bond_valence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os

import pytest
from pytest import approx

from pymatgen.analysis.bond_valence import BVAnalyzer, calculate_bv_sum, calculate_bv_sum_unordered
Expand All @@ -15,7 +16,7 @@ class TestBVAnalyzer(PymatgenTest):
def setUp(self):
self.analyzer = BVAnalyzer()

def test_get_valence(self):
def test_get_valences(self):
struct = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "LiMn2O4.json"))
ans = [1, 1, 3, 3, 4, 4, -2, -2, -2, -2, -2, -2, -2, -2]
assert self.analyzer.get_valences(struct) == ans
Expand All @@ -31,11 +32,15 @@ def test_get_valence(self):
struct = self.get_structure("NaFePO4")
assert self.analyzer.get_valences(struct) == ans

# trigger ValueError Structure contains elements not in set of BV parameters
with pytest.raises(ValueError, match="Structure contains elements not in set of BV parameters: {Element Xe}"):
self.analyzer.get_valences(self.get_structure("Li10GeP2S12").replace_species({"Li": "Xe"}, in_place=False))

def test_get_oxi_state_structure(self):
struct = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "LiMn2O4.json"))
news = self.analyzer.get_oxi_state_decorated_structure(struct)
assert Species("Mn", 3) in news.composition.elements
assert Species("Mn", 4) in news.composition.elements
oxi_struct = self.analyzer.get_oxi_state_decorated_structure(struct)
assert Species("Mn", 3) in oxi_struct.composition.elements
assert Species("Mn", 4) in oxi_struct.composition.elements


class TestBondValenceSum(PymatgenTest):
Expand Down
2 changes: 1 addition & 1 deletion tests/files/.pytest-split-durations
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
"tests/analysis/test_bond_dissociation.py::TestBondDissociation::test_pc_neutral_pcm_65": 0.0004544589319266379,
"tests/analysis/test_bond_dissociation.py::TestBondDissociation::test_tfsi_neg_no_pcm": 0.0004278330015949905,
"tests/analysis/test_bond_valence.py::TestBVAnalyzer::test_get_oxi_state_structure": 0.005586749990470707,
"tests/analysis/test_bond_valence.py::TestBVAnalyzer::test_get_valence": 0.05632162501569837,
"tests/analysis/test_bond_valence.py::TestBVAnalyzer::test_get_valences": 0.05632162501569837,
"tests/analysis/test_bond_valence.py::TestBondValenceSum::test_calculate_bv_sum": 0.0013919160119257867,
"tests/analysis/test_bond_valence.py::TestBondValenceSum::test_calculate_bv_sum_unordered": 0.0008953339420258999,
"tests/analysis/test_chempot_diagram.py::TestChemicalPotentialDiagram::test_border_hyperplanes": 0.07804387499345466,
Expand Down

0 comments on commit 294f033

Please sign in to comment.