@@ -1181,15 +1181,14 @@ def test_write_file_from_OptSet(self):
1181
1181
odd_mol = odd_dict ["spec" ]["_tasks" ][0 ]["molecule" ]
1182
1182
qcinp = OptSet (odd_mol )
1183
1183
qcinp .write_file (os .path .join (os .path .dirname (__file__ ), "test.qin" ))
1184
- test_file = open ( os .path .join (os .path .dirname (__file__ ), "test.qin" ) )
1185
- ref_file = open ( os .path .join (os .path .dirname (__file__ ), "test_ref.qin" ) )
1184
+ test_path = os .path .join (os .path .dirname (__file__ ), "test.qin" )
1185
+ ref_path = os .path .join (os .path .dirname (__file__ ), "test_ref.qin" )
1186
1186
1187
- for l_test , l_ref in zip (test_file , ref_file ):
1188
- # By default, if this statement fails the offending line will be printed
1189
- assert l_test == l_ref
1187
+ with open (ref_path ) as ref_file , open (test_path ) as test_file :
1188
+ for l_test , l_ref in zip (test_file , ref_file ):
1189
+ # By default, if this statement fails the offending line will be printed
1190
+ assert l_test == l_ref
1190
1191
1191
- test_file .close ()
1192
- ref_file .close ()
1193
1192
os .remove (os .path .join (os .path .dirname (__file__ ), "test.qin" ))
1194
1193
1195
1194
def test_write_file_from_OptSet_with_vdw (self ):
@@ -1199,59 +1198,55 @@ def test_write_file_from_OptSet_with_vdw(self):
1199
1198
odd_mol = odd_dict ["spec" ]["_tasks" ][0 ]["molecule" ]
1200
1199
qcinp = OptSet (odd_mol , overwrite_inputs = {"van_der_waals" : {"16" : 3.14159 }})
1201
1200
qcinp .write_file (os .path .join (os .path .dirname (__file__ ), "test_vdw.qin" ))
1202
- test_file = open ( os .path .join (os .path .dirname (__file__ ), "test_vdw.qin" ) )
1203
- ref_file = open ( os .path .join (os .path .dirname (__file__ ), "test_ref_vdw.qin" ) )
1201
+ test_path = os .path .join (os .path .dirname (__file__ ), "test_vdw.qin" )
1202
+ ref_path = os .path .join (os .path .dirname (__file__ ), "test_ref_vdw.qin" )
1204
1203
1205
- for l_test , l_ref in zip (test_file , ref_file ):
1206
- # By default, if this statement fails the offending line will be printed
1207
- assert l_test == l_ref
1204
+ with open (ref_path ) as ref_file , open (test_path ) as test_file :
1205
+ for l_test , l_ref in zip (test_file , ref_file ):
1206
+ # By default, if this statement fails the offending line will be printed
1207
+ assert l_test == l_ref
1208
1208
1209
- test_file .close ()
1210
- ref_file .close ()
1211
1209
os .remove (os .path .join (os .path .dirname (__file__ ), "test_vdw.qin" ))
1212
1210
1213
1211
def test_read_write_nbo7 (self ):
1214
1212
qcinp = QCInput .from_file (os .path .join (PymatgenTest .TEST_FILES_DIR , "molecules" , "new_qchem_files" , "nbo7.qin" ))
1215
1213
qcinp .write_file (os .path .join (os .path .dirname (__file__ ), "test_nbo7.qin" ))
1216
- test_file = open ( os .path .join (PymatgenTest .TEST_FILES_DIR , "molecules" , "new_qchem_files" , "nbo7.qin" ) )
1217
- ref_file = open ( os .path .join (os .path .dirname (__file__ ), "test_nbo7.qin" ) )
1214
+ test_path = os .path .join (PymatgenTest .TEST_FILES_DIR , "molecules" , "new_qchem_files" , "nbo7.qin" )
1215
+ ref_path = os .path .join (os .path .dirname (__file__ ), "test_nbo7.qin" )
1218
1216
1219
- for l_test , l_ref in zip (test_file , ref_file ):
1220
- # By default, if this statement fails the offending line will be printed
1221
- assert l_test == l_ref
1217
+ with open (ref_path ) as ref_file , open (test_path ) as test_file :
1218
+ for l_test , l_ref in zip (test_file , ref_file ):
1219
+ # By default, if this statement fails the offending line will be printed
1220
+ assert l_test == l_ref
1222
1221
1223
- test_file .close ()
1224
- ref_file .close ()
1225
1222
os .remove (os .path .join (os .path .dirname (__file__ ), "test_nbo7.qin" ))
1226
1223
1227
1224
def test_read_write_nbo_e2pert (self ):
1228
1225
qcinp = QCInput .from_file (
1229
1226
os .path .join (PymatgenTest .TEST_FILES_DIR , "molecules" , "new_qchem_files" , "e2pert.qin" )
1230
1227
)
1231
1228
qcinp .write_file (os .path .join (os .path .dirname (__file__ ), "test_e2pert.qin" ))
1232
- test_file = open ( os .path .join (PymatgenTest .TEST_FILES_DIR , "molecules" , "new_qchem_files" , "e2pert.qin" ) )
1233
- ref_file = open ( os .path .join (os .path .dirname (__file__ ), "test_e2pert.qin" ) )
1229
+ test_path = os .path .join (PymatgenTest .TEST_FILES_DIR , "molecules" , "new_qchem_files" , "e2pert.qin" )
1230
+ ref_path = os .path .join (os .path .dirname (__file__ ), "test_e2pert.qin" )
1234
1231
1235
- for l_test , l_ref in zip (test_file , ref_file ):
1236
- assert l_test == l_ref
1232
+ with open (ref_path ) as ref_file , open (test_path ) as test_file :
1233
+ for l_test , l_ref in zip (test_file , ref_file ):
1234
+ assert l_test == l_ref
1237
1235
1238
- test_file .close ()
1239
- ref_file .close ()
1240
1236
os .remove (os .path .join (os .path .dirname (__file__ ), "test_e2pert.qin" ))
1241
1237
1242
1238
def test_read_write_custom_smd (self ):
1243
1239
qcinp = QCInput .from_file (
1244
1240
os .path .join (PymatgenTest .TEST_FILES_DIR , "molecules" , "new_qchem_files" , "custom_smd.qin" )
1245
1241
)
1246
1242
qcinp .write_file (os .path .join (os .path .dirname (__file__ ), "test_custom_smd.qin" ))
1247
- test_file = open ( os .path .join (PymatgenTest .TEST_FILES_DIR , "molecules" , "new_qchem_files" , "custom_smd.qin" ) )
1248
- ref_file = open ( os .path .join (os .path .dirname (__file__ ), "test_custom_smd.qin" ) )
1243
+ test_path = os .path .join (PymatgenTest .TEST_FILES_DIR , "molecules" , "new_qchem_files" , "custom_smd.qin" )
1244
+ ref_path = os .path .join (os .path .dirname (__file__ ), "test_custom_smd.qin" )
1249
1245
1250
- for l_test , l_ref in zip (test_file , ref_file ):
1251
- assert l_test == l_ref
1246
+ with open (ref_path ) as ref_file , open (test_path ) as test_file :
1247
+ for l_test , l_ref in zip (test_file , ref_file ):
1248
+ assert l_test == l_ref
1252
1249
1253
- test_file .close ()
1254
- ref_file .close ()
1255
1250
os .remove (os .path .join (os .path .dirname (__file__ ), "test_custom_smd.qin" ))
1256
1251
1257
1252
0 commit comments