Skip to content

Commit

Permalink
parametrize to reduce code repetition
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Nov 8, 2024
1 parent bd53015 commit eba026d
Showing 1 changed file with 13 additions and 38 deletions.
51 changes: 13 additions & 38 deletions tests/io/vasp/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,13 +833,20 @@ def test_parse_potcar_cwd_relative(self):
assert vrun.potcar_spec[ipot]["summary_stats"] == potcar[ipot]._summary_stats


class TestOutcar(PymatgenTest):
def test_init_from_compressed(self):
"""Test for both compressed and uncomressed versions,
because there was a bug in monty causing different
behaviour.
class TestOutcar:
@pytest.mark.parametrize("compressed", [True, False])
def test_init(self, compressed: bool):
"""Test from both compressed and uncompressed versions,
as there was a bug in monty causing different behaviours.
"""
outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz")
with ScratchDir("."):
if compressed:
copyfile(f"{VASP_OUT_DIR}/OUTCAR.gz", "./OUTCAR.gz")
decompress_file("./OUTCAR.gz")
outcar = Outcar("./OUTCAR")
else:
outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz")

expected_mag = (
{"d": 0.0, "p": 0.003, "s": 0.002, "tot": 0.005},
{"d": 0.798, "p": 0.008, "s": 0.007, "tot": 0.813},
Expand Down Expand Up @@ -884,38 +891,6 @@ def test_init_from_compressed(self):
toten += outcar.final_energy_contribs[k]
assert toten == approx(outcar.final_energy, abs=1e-6)

def test_init_from_uncompressed(self):
"""Test for both compressed and uncomressed versions,
because there was a bug in monty causing different
behaviour.
"""
with ScratchDir("."):
copyfile(f"{VASP_OUT_DIR}/OUTCAR.gz", "./OUTCAR.gz")
decompress_file("./OUTCAR.gz")
outcar = Outcar("./OUTCAR")

expected_mag = (
{"d": 0.0, "p": 0.003, "s": 0.002, "tot": 0.005},
{"d": 0.798, "p": 0.008, "s": 0.007, "tot": 0.813},
{"d": 0.798, "p": 0.008, "s": 0.007, "tot": 0.813},
{"d": 0.0, "p": -0.117, "s": 0.005, "tot": -0.112},
{"d": 0.0, "p": -0.165, "s": 0.004, "tot": -0.162},
{"d": 0.0, "p": -0.117, "s": 0.005, "tot": -0.112},
{"d": 0.0, "p": -0.165, "s": 0.004, "tot": -0.162},
)
expected_chg = (
{"p": 0.154, "s": 0.078, "d": 0.0, "tot": 0.232},
{"p": 0.707, "s": 0.463, "d": 8.316, "tot": 9.486},
{"p": 0.707, "s": 0.463, "d": 8.316, "tot": 9.486},
{"p": 3.388, "s": 1.576, "d": 0.0, "tot": 4.964},
{"p": 3.365, "s": 1.582, "d": 0.0, "tot": 4.947},
{"p": 3.388, "s": 1.576, "d": 0.0, "tot": 4.964},
{"p": 3.365, "s": 1.582, "d": 0.0, "tot": 4.947},
)

assert outcar.magnetization == approx(expected_mag, abs=1e-5), "Wrong magnetization read from Outcar"
assert outcar.charge == approx(expected_chg, abs=1e-5), "Wrong charge read from Outcar"

def test_stopped_old(self):
filepath = f"{VASP_OUT_DIR}/OUTCAR.stopped.gz"
outcar = Outcar(filepath)
Expand Down

0 comments on commit eba026d

Please sign in to comment.