1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
Index: pymatgen/tests/io/qchem/test_inputs.py
===================================================================
--- pymatgen.orig/tests/io/qchem/test_inputs.py 2025-10-12 13:37:50.832331291 +0200
+++ pymatgen/tests/io/qchem/test_inputs.py 2025-10-12 13:41:17.152919258 +0200
@@ -20,6 +20,12 @@
__credits__ = "Xiaohui Qu"
+@pytest.fixture(scope="class")
+def tmp_path_write(request, tmp_path_factory):
+ tmp_path = tmp_path_factory.mktemp(request.cls.__name__ + "_write")
+ request.cls.tmp_path = tmp_path
+
+@pytest.mark.usefixtures("tmp_path_write")
class TestQCInput(MatSciTest):
def test_molecule_template(self):
species = ["C", "O"]
@@ -1229,8 +1235,14 @@
odd_dict = loadfn(f"{TEST_DIR}/odd.json")
odd_mol = odd_dict["spec"]["_tasks"][0]["molecule"]
qcinp = OptSet(odd_mol)
- qcinp.write_file(f"{TEST_DIR}/test.qin")
- test_path = f"{TEST_DIR}/test.qin"
+ try:
+ qcinp.write_file(f"{TEST_DIR}/test.qin")
+ test_path = f"{TEST_DIR}/test.qin"
+ except PermissionError:
+ # test files located in non-writable dir
+ # so use tmp_path instead
+ qcinp.write_file(f"{self.tmp_path}/test.qin")
+ test_path = f"{self.tmp_path}/test.qin"
ref_path = f"{TEST_DIR}/test_ref.qin"
with open(ref_path, encoding="utf-8") as ref_file, open(test_path, encoding="utf-8") as test_file:
@@ -1238,14 +1250,20 @@
# By default, if this statement fails the offending line will be printed
assert l_test == l_ref
- os.remove(f"{TEST_DIR}/test.qin")
+ os.remove(test_path)
def test_write_file_from_opt_set_with_vdw(self):
odd_dict = loadfn(f"{TEST_DIR}/odd.json")
odd_mol = odd_dict["spec"]["_tasks"][0]["molecule"]
qcinp = OptSet(odd_mol, overwrite_inputs={"van_der_waals": {"16": 3.14159}})
- qcinp.write_file(f"{TEST_DIR}/test_vdw.qin")
- test_path = f"{TEST_DIR}/test_vdw.qin"
+ try:
+ qcinp.write_file(f"{TEST_DIR}/test_vdw.qin")
+ test_path = f"{TEST_DIR}/test_vdw.qin"
+ except PermissionError:
+ # test files located in non-writable dir
+ # so use tmp_path instead
+ qcinp.write_file(f"{self.tmp_path}/test_vdw.qin")
+ test_path = f"{self.tmp_path}/test_vdw.qin"
ref_path = f"{TEST_DIR}/test_ref_vdw.qin"
with open(ref_path, encoding="utf-8") as ref_file, open(test_path, encoding="utf-8") as test_file:
@@ -1253,7 +1271,7 @@
# By default, if this statement fails the offending line will be printed
assert l_test == l_ref
- os.remove(f"{TEST_DIR}/test_vdw.qin")
+ os.remove(test_path)
def test_read_write_nbo7(self):
test_path = f"{TEST_DIR}/test_nbo7.qin"
|