Skip to content

Commit 3161068

Browse files
committed
clean up TestMITMPRelaxSet.test_write_input
1 parent 0dca5b1 commit 3161068

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

tests/io/test_lmto.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import os
4-
import unittest
54

65
import numpy as np
76
from numpy.testing import assert_array_equal
@@ -24,7 +23,7 @@
2423
this_dir = os.path.dirname(os.path.abspath(__file__))
2524

2625

27-
class TestCtrl(unittest.TestCase):
26+
class TestCtrl(PymatgenTest):
2827
def setUp(self):
2928
os.chdir(test_dir)
3029
self.ctrl_bise = LMTOCtrl.from_file(filename="CTRL.BiSe")
@@ -42,10 +41,10 @@ def test_structure(self):
4241
assert self.ctrl_bise == LMTOCtrl(self.ctrl_bise.structure, header="Bi6Se6, hexagonal")
4342

4443
def test_read_write(self):
45-
self.ctrl_bise.write_file(filename="CTRL.tmp")
46-
ctrl_tmp = LMTOCtrl.from_file(filename="CTRL.tmp")
47-
assert self.ctrl_bise.structure.matches(ctrl_tmp.structure)
48-
os.remove("CTRL.tmp")
44+
ctrl_path = f"{self.tmp_path}/CTRL.tmp"
45+
self.ctrl_bise.write_file(filename=ctrl_path)
46+
ctrl_file = LMTOCtrl.from_file(filename=ctrl_path)
47+
assert self.ctrl_bise.structure.matches(ctrl_file.structure)
4948

5049

5150
class TestCopl(PymatgenTest):

tests/io/test_shengbte.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_from_dict(self):
9999
@unittest.skipIf(f90nml is None, "No f90nml")
100100
def test_MSONable_implementation(self):
101101
# tests as dict and from dict methods
102-
Controlinfromfile = Control.from_file(self.filename)
103-
newControlin = Control.from_dict(Controlinfromfile.as_dict())
104-
assert newControlin == Controlinfromfile
105-
newControlin.to_json()
102+
ctrl_from_file = Control.from_file(self.filename)
103+
control_from_dict = Control.from_dict(ctrl_from_file.as_dict())
104+
assert control_from_dict == ctrl_from_file
105+
assert control_from_dict.to_json() == ctrl_from_file.to_json()

tests/io/vasp/test_sets.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ def test_get_kpoints(self):
455455
assert kpoints.kpts == [[25]]
456456
assert kpoints.style == Kpoints.supported_modes.Automatic
457457

458-
recip_paramset = MPRelaxSet(self.structure, force_gamma=True)
459-
recip_paramset.kpoints_settings = {"reciprocal_density": 40}
460-
kpoints = recip_paramset.kpoints
458+
recip_param_set = MPRelaxSet(self.structure, force_gamma=True)
459+
recip_param_set.kpoints_settings = {"reciprocal_density": 40}
460+
kpoints = recip_param_set.kpoints
461461
assert kpoints.kpts == [[2, 4, 5]]
462462
assert kpoints.style == Kpoints.supported_modes.Gamma
463463

@@ -540,24 +540,17 @@ def test_incar_lmaxmix(self):
540540

541541
@skip_if_no_psp_dir
542542
def test_write_input(self):
543-
self.mit_set.write_input(".", make_dir_if_not_present=True)
544-
for file in ["INCAR", "KPOINTS", "POSCAR", "POTCAR"]:
545-
assert os.path.isfile(file)
546-
assert not os.path.isfile("Fe4P4O16.cif")
547-
548-
self.mit_set.write_input(".", make_dir_if_not_present=True, include_cif=True)
549-
assert os.path.isfile("Fe4P4O16.cif")
550-
for file in ["INCAR", "KPOINTS", "POSCAR", "POTCAR", "Fe4P4O16.cif"]:
551-
os.remove(file)
552-
553-
self.mit_set.write_input(".", make_dir_if_not_present=True, potcar_spec=True)
554-
555-
for file in ["INCAR", "KPOINTS", "POSCAR"]:
556-
assert os.path.isfile(file)
557-
assert not os.path.isfile("POTCAR")
558-
assert os.path.isfile("POTCAR.spec")
559-
for file in ["INCAR", "KPOINTS", "POSCAR", "POTCAR.spec"]:
560-
os.remove(file)
543+
vasp_files = {"INCAR", "KPOINTS", "POSCAR", "POTCAR"}
544+
self.mit_set.write_input(self.tmp_path)
545+
assert {*os.listdir(self.tmp_path)} == vasp_files
546+
547+
self.mit_set.write_input(self.tmp_path, include_cif=True)
548+
assert {*os.listdir(self.tmp_path)} == {*vasp_files, "Fe4P4O16.cif"}
549+
550+
@skip_if_no_psp_dir
551+
def test_write_input_potcar_spec(self):
552+
self.mit_set.write_input(self.tmp_path, potcar_spec=True)
553+
assert {*os.listdir(self.tmp_path)} == {"INCAR", "KPOINTS", "POSCAR", "POTCAR.spec"}
561554

562555
@skip_if_no_psp_dir
563556
def test_user_potcar_settings(self):

0 commit comments

Comments
 (0)