55import shutil
66import tarfile
77from glob import glob
8+ from pathlib import Path
89
910import pytest
11+ from monty .io import zopen
1012from monty .os .path import zpath
1113from pymatgen .io .vasp .inputs import Incar , Kpoints , Structure , VaspInput
12- from pymatgen .util .testing import PymatgenTest
14+ from pymatgen .util .testing import MatSciTest
1315
1416from custodian .utils import tracked_lru_cache
1517from custodian .vasp .handlers import (
3032 VaspErrorHandler ,
3133 WalltimeHandler ,
3234)
35+ from custodian .vasp .interpreter import VaspModder
3336from tests .conftest import TEST_FILES
3437
3538__author__ = "Shyue Ping Ong, Stephen Dacek, Janosh Riebesell"
4649@pytest .fixture (autouse = True )
4750def _clear_tracked_cache () -> None :
4851 """Clear the cache of the stored functions between the tests."""
49- from custodian .utils import tracked_lru_cache
5052
5153 tracked_lru_cache .tracked_cache_clear ()
5254
@@ -66,7 +68,7 @@ def copy_tmp_files(tmp_path: str, *file_paths: str) -> None:
6668 os .chdir (tmp_path )
6769
6870
69- class VaspErrorHandlerTest (PymatgenTest ):
71+ class VaspErrorHandlerTest (MatSciTest ):
7072 def setUp (self ) -> None :
7173 copy_tmp_files (self .tmp_path , * glob ("*" , root_dir = TEST_FILES ))
7274
@@ -618,7 +620,7 @@ def test_auto_nbands_bad_parallelization(self) -> None:
618620 assert dct ["actions" ] == [{"dict" : "INCAR" , "action" : {"_set" : {"NBANDS" : 64 }}}]
619621
620622
621- class AliasingErrorHandlerTest (PymatgenTest ):
623+ class AliasingErrorHandlerTest (MatSciTest ):
622624 def setUp (self ) -> None :
623625 copy_tmp_files (self .tmp_path , * glob ("aliasing/*" , root_dir = TEST_FILES ))
624626
@@ -655,7 +657,7 @@ def test_aliasing_incar(self) -> None:
655657 assert dct ["actions" ] == [{"action" : {"_unset" : {"NGY" : 1 , "NGZ" : 1 }}, "dict" : "INCAR" }]
656658
657659
658- class UnconvergedErrorHandlerTest (PymatgenTest ):
660+ class UnconvergedErrorHandlerTest (MatSciTest ):
659661 def setUp (self ) -> None :
660662 copy_tmp_files (self .tmp_path , * glob ("unconverged/*" , root_dir = TEST_FILES ))
661663
@@ -790,7 +792,7 @@ def test_uncorrectable(self) -> None:
790792 assert dct ["actions" ] is None
791793
792794
793- class IncorrectSmearingHandlerTest (PymatgenTest ):
795+ class IncorrectSmearingHandlerTest (MatSciTest ):
794796 def setUp (self ) -> None :
795797 copy_tmp_files (self .tmp_path , "scan_metal/INCAR" , "scan_metal/vasprun.xml" )
796798
@@ -804,7 +806,7 @@ def test_check_correct_scan_metal(self) -> None:
804806 assert incar ["SIGMA" ] == 0.2
805807
806808
807- class IncorrectSmearingHandlerStaticTest (PymatgenTest ):
809+ class IncorrectSmearingHandlerStaticTest (MatSciTest ):
808810 def setUp (self ) -> None :
809811 copy_tmp_files (self .tmp_path , "static_smearing/INCAR" , "static_smearing/vasprun.xml" )
810812
@@ -813,7 +815,7 @@ def test_check_correct_scan_metal(self) -> None:
813815 assert not handler .check ()
814816
815817
816- class IncorrectSmearingHandlerFermiTest (PymatgenTest ):
818+ class IncorrectSmearingHandlerFermiTest (MatSciTest ):
817819 def setUp (self ) -> None :
818820 copy_tmp_files (self .tmp_path , "fermi_smearing/INCAR" , "fermi_smearing/vasprun.xml" )
819821
@@ -822,7 +824,7 @@ def test_check_correct_scan_metal(self) -> None:
822824 assert not handler .check ()
823825
824826
825- class KspacingMetalHandlerTest (PymatgenTest ):
827+ class KspacingMetalHandlerTest (MatSciTest ):
826828 def setUp (self ) -> None :
827829 copy_tmp_files (self .tmp_path , "scan_metal/INCAR" , "scan_metal/vasprun.xml" )
828830
@@ -846,7 +848,7 @@ def test_check_with_non_kspacing_wf(self) -> None:
846848 assert isinstance (ScanMetalHandler (), KspacingMetalHandler )
847849
848850
849- class LargeSigmaHandlerTest (PymatgenTest ):
851+ class LargeSigmaHandlerTest (MatSciTest ):
850852 def setUp (self ) -> None :
851853 copy_tmp_files (self .tmp_path , * glob ("large_sigma/*" , root_dir = TEST_FILES ))
852854
@@ -863,9 +865,6 @@ def test_check_correct_large_sigma(self) -> None:
863865 assert not handler .check ()
864866
865867 def test_no_crash_on_partial_output (self ) -> None :
866- from pathlib import Path
867-
868- from monty .io import zopen
869868 # ensure that the handler doesn't crash when the OUTCAR isn't completely written
870869 # this prevents jobs from being killed when the handler itself crashes
871870
@@ -890,7 +889,7 @@ def test_no_crash_on_partial_output(self) -> None:
890889 assert not handler .check ()
891890
892891
893- class ZpotrfErrorHandlerTest (PymatgenTest ):
892+ class ZpotrfErrorHandlerTest (MatSciTest ):
894893 def setUp (self ) -> None :
895894 copy_tmp_files (
896895 self .tmp_path ,
@@ -945,7 +944,7 @@ def test_static_run_correction(self) -> None:
945944 assert Incar .from_file ("INCAR" )["ISYM" ] == 0
946945
947946
948- class ZpotrfErrorHandlerSmallTest (PymatgenTest ):
947+ class ZpotrfErrorHandlerSmallTest (MatSciTest ):
949948 def setUp (self ) -> None :
950949 copy_tmp_files (
951950 self .tmp_path ,
@@ -967,7 +966,7 @@ def test_small(self) -> None:
967966 ]
968967
969968
970- class WalltimeHandlerTest (PymatgenTest ):
969+ class WalltimeHandlerTest (MatSciTest ):
971970 def setUp (self ) -> None :
972971 os .chdir (f"{ TEST_FILES } /postprocess" )
973972 os .environ .pop ("CUSTODIAN_WALLTIME_START" , None )
@@ -1023,7 +1022,7 @@ def tearDown(cls) -> None:
10231022 os .chdir (CWD )
10241023
10251024
1026- class PositiveEnergyHandlerTest (PymatgenTest ):
1025+ class PositiveEnergyHandlerTest (MatSciTest ):
10271026 def setUp (self ) -> None :
10281027 copy_tmp_files (self .tmp_path , "positive_energy/INCAR" , "positive_energy/POSCAR" , "positive_energy/OSZICAR" )
10291028
@@ -1042,7 +1041,7 @@ def test_check_correct(self) -> None:
10421041 assert incar ["ALGO" ] == "Normal"
10431042
10441043
1045- class PotimHandlerTest (PymatgenTest ):
1044+ class PotimHandlerTest (MatSciTest ):
10461045 def setUp (self ) -> None :
10471046 copy_tmp_files (self .tmp_path , "potim/INCAR" , "potim/POSCAR" , "potim/OSZICAR" )
10481047
@@ -1064,7 +1063,7 @@ def test_check_correct(self) -> None:
10641063 assert incar ["IBRION" ] == 3
10651064
10661065
1067- class LrfCommHandlerTest (PymatgenTest ):
1066+ class LrfCommHandlerTest (MatSciTest ):
10681067 def setUp (self ) -> None :
10691068 copy_tmp_files (self .tmp_path , "lrf_comm/INCAR" , "lrf_comm/OUTCAR" , "lrf_comm/std_err.txt" )
10701069
@@ -1077,7 +1076,7 @@ def test_lrf_comm(self) -> None:
10771076 assert vi ["INCAR" ]["LPEAD" ] is True
10781077
10791078
1080- class KpointsTransHandlerTest (PymatgenTest ):
1079+ class KpointsTransHandlerTest (MatSciTest ):
10811080 def setUp (self ) -> None :
10821081 copy_tmp_files (self .tmp_path , "KPOINTS" , "std_err.txt.kpoints_trans" )
10831082
@@ -1094,13 +1093,12 @@ def test_kpoints_trans(self) -> None:
10941093 assert dct ["actions" ] == [] # don't correct twice
10951094
10961095
1097- class OutOfMemoryHandlerTest (PymatgenTest ):
1096+ class OutOfMemoryHandlerTest (MatSciTest ):
10981097 def setUp (self ) -> None :
10991098 copy_tmp_files (self .tmp_path , "INCAR" , "std_err.txt.oom" )
11001099
11011100 def test_oom (self ) -> None :
11021101 vi = VaspInput .from_directory ("." )
1103- from custodian .vasp .interpreter import VaspModder
11041102
11051103 VaspModder (vi = vi ).apply_actions ([{"dict" : "INCAR" , "action" : {"_set" : {"KPAR" : 4 }}}])
11061104 handler = StdErrHandler ("std_err.txt.oom" )
@@ -1110,7 +1108,7 @@ def test_oom(self) -> None:
11101108 assert dct ["actions" ] == [{"dict" : "INCAR" , "action" : {"_set" : {"KPAR" : 2 }}}]
11111109
11121110
1113- class DriftErrorHandlerTest (PymatgenTest ):
1111+ class DriftErrorHandlerTest (MatSciTest ):
11141112 def setUp (self ) -> None :
11151113 copy_tmp_files (self .tmp_path , "INCAR" , "drift/OUTCAR" , "drift/CONTCAR" )
11161114
@@ -1144,7 +1142,7 @@ def test_correct(self) -> None:
11441142 assert incar .get ("ENAUG" , 0 ) == incar .get ("ENCUT" , 2 ) * 2
11451143
11461144
1147- class NonConvergingErrorHandlerTest (PymatgenTest ):
1145+ class NonConvergingErrorHandlerTest (MatSciTest ):
11481146 n_ionic_steps : int = 3
11491147
11501148 def setUp (self ) -> None :
0 commit comments