diff --git a/tests/test_generation.py b/tests/test_generation.py index b1fbe3aa..61d653b3 100644 --- a/tests/test_generation.py +++ b/tests/test_generation.py @@ -59,6 +59,12 @@ def _potcars_available() -> bool: class DefectsGeneratorTest(unittest.TestCase): def setUp(self): + if not _potcars_available() and random.randint(1, 10) != 1: + # on GH Actions, only run the heavy tests 10% of times: + self.heavy_tests = False + else: + self.heavy_tests = True + self.data_dir = os.path.join(os.path.dirname(__file__), "data") self.cdte_data_dir = os.path.join(self.data_dir, "CdTe") self.example_dir = os.path.join(os.path.dirname(__file__), "..", "examples") @@ -1998,6 +2004,9 @@ def test_ytos_supercell_input(self): ) # for testing in test_vasp.py def test_ytos_no_generate_supercell(self): + if not self.heavy_tests: # skip one of the YTOS tests if on GH Actions + return + # tests the case of an input structure which is >10 Å in each direction, has # more atoms (198) than the pmg supercell (99), but generate_supercell = False, # so the _input_ supercell is used @@ -2119,6 +2128,9 @@ def lmno_defect_gen_check(self, lmno_defect_gen, generate_supercell=True): ) def test_lmno(self): + if not self.heavy_tests: # skip one of the LMNO tests if on GH Actions + return + # battery material with a variety of important Wyckoff sites (and the terminology mainly # used in this field). Tough to find suitable supercell, goes to 448-atom supercell. lmno_defect_gen, output = self._generate_and_test_no_warnings(self.lmno_primitive) @@ -2593,6 +2605,9 @@ def cd_i_cdte_supercell_defect_gen_check(self, cd_i_defect_gen): ) def test_supercell_w_defect_cd_i_cdte(self): + if not self.heavy_tests: + return + # test inputting a defective supercell cdte_defect_gen = DefectsGenerator(self.prim_cdte) diff --git a/tests/test_vasp.py b/tests/test_vasp.py index 627732ca..999d7723 100644 --- a/tests/test_vasp.py +++ b/tests/test_vasp.py @@ -88,6 +88,12 @@ def _check_nupdown_neutral_cell_warning(message): class DefectDictSetTest(unittest.TestCase): def setUp(self): + if not _potcars_available() and random.randint(1, 10) != 1: + # on GH Actions, only run the heavy tests 10% of times: + self.heavy_tests = False + else: + self.heavy_tests = True + self.data_dir = os.path.join(os.path.dirname(__file__), "data") self.cdte_data_dir = os.path.join(self.data_dir, "CdTe") self.example_dir = os.path.join(os.path.dirname(__file__), "..", "examples") @@ -640,6 +646,15 @@ def test_initialisation_and_writing(self): Test the initialisation of DefectRelaxSet for a range of `DefectEntry`s. """ + if not self.heavy_tests: + return + + def _check_drs_defect_entry_attribute_transfer(parent_drs, input_defect_entry): + assert parent_drs.defect_entry == input_defect_entry + assert parent_drs.defect_supercell == input_defect_entry.defect_supercell + assert parent_drs.charge_state == input_defect_entry.charge_state + assert parent_drs.bulk_supercell == input_defect_entry.bulk_supercell + # test initialising DefectRelaxSet with our generation-tests materials, and writing files to disk defect_gen_test_list = [ (self.cdte_defect_gen, "CdTe defect_gen"), @@ -661,32 +676,25 @@ def test_initialisation_and_writing(self): for defect_gen, defect_gen_name in defect_gen_test_list: print(f"Initialising and testing: {defect_gen_name}") - # randomly choose 3 defect entries from the defect_gen dict: - defect_entries = random.sample(list(defect_gen.values()), 3) + # randomly choose a defect entry from the defect_gen dict: + defect_entry = random.choice(list(defect_gen.values())) - for defect_entry in defect_entries: - print(f"Randomly testing {defect_entry.name}") - drs = DefectRelaxSet(defect_entry) - self._general_defect_relax_set_check(drs) - - def _check_drs_defect_entry_attribute_transfer(parent_drs, input_defect_entry): - assert parent_drs.defect_entry == input_defect_entry - assert parent_drs.defect_supercell == input_defect_entry.defect_supercell - assert parent_drs.charge_state == input_defect_entry.charge_state - assert parent_drs.bulk_supercell == input_defect_entry.bulk_supercell - - _check_drs_defect_entry_attribute_transfer(drs, defect_entry) - - custom_drs = DefectRelaxSet( - defect_entry, - user_incar_settings={"ENCUT": 350}, - user_potcar_functional="PBE_52", - user_potcar_settings={"Cu": "Cu_pv"}, - user_kpoints_settings={"reciprocal_density": 200}, - poscar_comment="Test pop", - ) - self._general_defect_relax_set_check(custom_drs) - _check_drs_defect_entry_attribute_transfer(custom_drs, defect_entry) + print(f"Randomly testing {defect_entry.name}") + drs = DefectRelaxSet(defect_entry) + self._general_defect_relax_set_check(drs) + + _check_drs_defect_entry_attribute_transfer(drs, defect_entry) + + custom_drs = DefectRelaxSet( + defect_entry, + user_incar_settings={"ENCUT": 350}, + user_potcar_functional="PBE_52", + user_potcar_settings={"Cu": "Cu_pv"}, + user_kpoints_settings={"reciprocal_density": 200}, + poscar_comment="Test pop", + ) + self._general_defect_relax_set_check(custom_drs) + _check_drs_defect_entry_attribute_transfer(custom_drs, defect_entry) # TODO: Test file writing, default folder naming # TODO: Explicitly check some poscar comments? For DS, DRS and DDS @@ -936,6 +944,9 @@ def _general_defects_set_check(self, defects_set, **kwargs): ) def test_cdte_files(self): + if not self.heavy_tests: + return + cdte_se_defect_gen = DefectsGenerator(self.prim_cdte, extrinsic="Se") defects_set = DefectsSet( cdte_se_defect_gen,