Skip to content

Commit

Permalink
fix expected warning msg quote mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Jun 13, 2023
1 parent 1a78d68 commit 3b5e5b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
17 changes: 10 additions & 7 deletions pymatgen/entries/mixing_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def get_adjustments(self, entry, mixing_state_data: pd.DataFrame = None):

if run_type not in self.valid_rtypes_1 + self.valid_rtypes_2:
raise CompatibilityError(
f"WARNING! Invalid run_type {run_type} for entry {entry.entry_id}. Must be one of "
f"WARNING! Invalid {run_type=} for entry {entry.entry_id}. Must be one of "
f"{self.valid_rtypes_1 + self.valid_rtypes_2}. This entry will be ignored."
)

Expand Down Expand Up @@ -583,24 +583,27 @@ def _filter_and_sort_entries(self, entries, verbose=True):
filtered_entries = []

for entry in entries:
entry_id = entry.entry_id
if not entry.parameters.get("run_type"):
warnings.warn(
f"Entry {entry.entry_id} is missing parameters.run_type! This field"
f"Entry {entry_id} is missing parameters.run_type! This field"
"is required. This entry will be ignored."
)
continue

if entry.parameters.get("run_type") not in self.valid_rtypes_1 + self.valid_rtypes_2:
run_type = entry.parameters.get("run_type")
if run_type not in [*self.valid_rtypes_1, *self.valid_rtypes_2]:
warnings.warn(
f"Invalid run_type {entry.parameters.get('run_type')} for entry {entry.entry_id}. Must be one of "
f"Invalid {run_type=} for entry {entry_id}. Must be one of "
f"{self.valid_rtypes_1 + self.valid_rtypes_2}. This entry will be ignored."
)
continue

if entry.entry_id is None:
formula = entry.composition.reduced_formula
if entry_id is None:
warnings.warn(
f"Entry_id for {entry.composition.reduced_formula} entry {entry.entry_id} is invalid. "
"Unique entry_ids are required for every ComputedStructureEntry. This entry will be ignored."
f"{entry_id=} for {formula=}. Unique entry_ids are required for every ComputedStructureEntry."
" This entry will be ignored."
)
continue

Expand Down
21 changes: 6 additions & 15 deletions pymatgen/entries/tests/test_mixing_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,31 +1021,22 @@ def test_incompatible_run_type(self, mixing_scheme_no_compat):
Structure(
lattice,
["Sn", "Br", "Br", "Br", "Br"],
[
[0, 0, 0],
[0.2, 0.2, 0.2],
[0.4, 0.4, 0.4],
[0.7, 0.7, 0.7],
[1, 1, 1],
],
[[0, 0, 0], [0.2, 0.2, 0.2], [0.4, 0.4, 0.4], [0.7, 0.7, 0.7], [1, 1, 1]],
),
0,
parameters={"run_type": "GGA"},
entry_id="gga-4",
),
]

with pytest.warns(UserWarning, match="Invalid run_type LDA"):
with pytest.warns(UserWarning, match="Invalid run_type='LDA'"):
assert len(mixing_scheme_no_compat.process_entries(entries)) == 4

state_data = mixing_scheme_no_compat.get_mixing_state_data(entries)
with pytest.raises(CompatibilityError, match="Invalid run_type LDA"):
assert (
mixing_scheme_no_compat.get_adjustments(
[e for e in entries if e.parameters["run_type"] == "LDA"][0],
state_data,
)
== []
with pytest.raises(CompatibilityError, match="Invalid run_type='LDA'"):
mixing_scheme_no_compat.get_adjustments(
[e for e in entries if e.parameters["run_type"] == "LDA"][0],
state_data,
)

def test_no_single_entry(self, mixing_scheme_no_compat):
Expand Down

0 comments on commit 3b5e5b2

Please sign in to comment.