Skip to content

Commit 2a47ce0

Browse files
esoteric-ephemeraesoteric-ephemera
authored andcommitted
Refactor tests/io/vasp/test_outputs.py
1 parent 8a45af8 commit 2a47ce0

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

tests/files/test_io_vasp_update_potcar_1.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/files/test_io_vasp_update_potcar_2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/files/~$asprun.xml

162 Bytes
Binary file not shown.

tests/io/vasp/test_outputs.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import numpy as np
1212
import pytest
13-
from monty.serialization import loadfn
1413
from numpy.testing import assert_allclose
1514
from pytest import approx
1615

@@ -19,7 +18,7 @@
1918
from pymatgen.core.structure import Structure
2019
from pymatgen.electronic_structure.core import Magmom, Orbital, OrbitalType, Spin
2120
from pymatgen.entries.compatibility import MaterialsProjectCompatibility
22-
from pymatgen.io.vasp.inputs import Kpoints, Poscar
21+
from pymatgen.io.vasp.inputs import Kpoints, Poscar, Potcar
2322
from pymatgen.io.vasp.outputs import (
2423
WSWQ,
2524
BSVasprun,
@@ -591,23 +590,27 @@ def test_update_potcar(self):
591590
filepath = f"{TEST_FILES_DIR}/vasprun.xml"
592591
potcar_path = f"{TEST_FILES_DIR}/POTCAR.LiFePO4.gz"
593592
potcar_path2 = f"{TEST_FILES_DIR}/POTCAR2.LiFePO4.gz"
593+
594594
vasp_run = Vasprun(filepath, parse_potcar_file=False)
595-
assert vasp_run.potcar_spec == [
596-
{"titel": "PAW_PBE Li 17Jan2003", "hash": None, "summary_stats": {}},
597-
{"titel": "PAW_PBE Fe 06Sep2000", "hash": None, "summary_stats": {}},
598-
{"titel": "PAW_PBE Fe 06Sep2000", "hash": None, "summary_stats": {}},
599-
{"titel": "PAW_PBE P 17Jan2003", "hash": None, "summary_stats": {}},
600-
{"titel": "PAW_PBE O 08Apr2002", "hash": None, "summary_stats": {}},
601-
]
595+
potcars = Potcar.from_file(potcar_path)
596+
expected_spec = [{"titel": titel, "hash": None, "summary_stats": {}} for titel in vasp_run.potcar_symbols]
597+
assert vasp_run.potcar_spec == expected_spec
598+
602599
vasp_run.update_potcar_spec(potcar_path)
603-
assert vasp_run.potcar_spec == loadfn(f"{TEST_FILES_DIR}/test_io_vasp_update_potcar_1.json")
600+
potcars = Potcar.from_file(potcar_path)
601+
expected_spec = []
602+
for titel in vasp_run.potcar_symbols:
603+
for potcar in potcars:
604+
if titel == potcar.TITEL:
605+
break
606+
expected_spec += [{"titel": titel, "hash": potcar.md5_header_hash, "summary_stats": potcar._summary_stats}]
607+
assert vasp_run.potcar_spec == expected_spec
604608

605-
vasprun2 = Vasprun(filepath, parse_potcar_file=False)
606609
with pytest.raises(ValueError, match="Potcar TITELs do not match Vasprun"):
607-
vasprun2.update_potcar_spec(potcar_path2)
608-
vasp_run = Vasprun(filepath, parse_potcar_file=potcar_path)
610+
Vasprun(filepath, parse_potcar_file=potcar_path2)
609611

610-
assert vasp_run.potcar_spec == loadfn(f"{TEST_FILES_DIR}/test_io_vasp_update_potcar_2.json")
612+
vasp_run = Vasprun(filepath, parse_potcar_file=potcar_path)
613+
assert vasp_run.potcar_spec == expected_spec
611614

612615
with pytest.raises(ValueError, match="Potcar TITELs do not match Vasprun"):
613616
Vasprun(filepath, parse_potcar_file=potcar_path2)

0 commit comments

Comments
 (0)