From 2020ad41d9e83115bbc99dddcbf0a7a6a4367bd3 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Wed, 15 Nov 2023 14:36:23 -0800 Subject: [PATCH] refactor test file copying (#306) --- tests/qchem/test_handlers.py | 239 +++++--------------- tests/qchem/test_job_handler_interaction.py | 65 ++---- tests/qchem/test_jobs.py | 177 ++++----------- 3 files changed, 113 insertions(+), 368 deletions(-) diff --git a/tests/qchem/test_handlers.py b/tests/qchem/test_handlers.py index 6d3a7ba7..f733cd19 100644 --- a/tests/qchem/test_handlers.py +++ b/tests/qchem/test_handlers.py @@ -46,12 +46,12 @@ def _check_equivalent_inputs(self, input1, input2): def test_unable_to_determine_lamda(self): for ii in range(2): shutil.copyfile( - os.path.join(TEST_DIR, "unable_to_determine_lamda.qin." + str(ii)), - os.path.join(SCR_DIR, "unable_to_determine_lamda.qin." + str(ii)), + f"{TEST_DIR}/unable_to_determine_lamda.qin.{ii}", + f"{SCR_DIR}/unable_to_determine_lamda.qin.{ii}", ) shutil.copyfile( - os.path.join(TEST_DIR, "unable_to_determine_lamda.qout." + str(ii)), - os.path.join(SCR_DIR, "unable_to_determine_lamda.qout." + str(ii)), + f"{TEST_DIR}/unable_to_determine_lamda.qout.{ii}", + f"{SCR_DIR}/unable_to_determine_lamda.qout.{ii}", ) handler = QChemErrorHandler( @@ -72,12 +72,12 @@ def test_unable_to_determine_lamda(self): def test_linear_dependent_basis_and_FileMan(self): for ii in range(1, 3): shutil.copyfile( - os.path.join(TEST_DIR, "unable_to_determine_lamda.qin." + str(ii)), - os.path.join(SCR_DIR, "unable_to_determine_lamda.qin." + str(ii)), + f"{TEST_DIR}/unable_to_determine_lamda.qin.{ii}", + f"{SCR_DIR}/unable_to_determine_lamda.qin.{ii}", ) shutil.copyfile( - os.path.join(TEST_DIR, "unable_to_determine_lamda.qout." + str(ii)), - os.path.join(SCR_DIR, "unable_to_determine_lamda.qout." + str(ii)), + f"{TEST_DIR}/unable_to_determine_lamda.qout.{ii}", + f"{SCR_DIR}/unable_to_determine_lamda.qout.{ii}", ) handler = QChemErrorHandler( @@ -92,14 +92,8 @@ def test_linear_dependent_basis_and_FileMan(self): def test_failed_to_transform(self): for ii in range(2): - shutil.copyfile( - os.path.join(TEST_DIR, "qunino_vinyl.qin." + str(ii)), - os.path.join(SCR_DIR, "qunino_vinyl.qin." + str(ii)), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "qunino_vinyl.qout." + str(ii)), - os.path.join(SCR_DIR, "qunino_vinyl.qout." + str(ii)), - ) + shutil.copyfile(f"{TEST_DIR}/qunino_vinyl.qin.{ii}", f"{SCR_DIR}/qunino_vinyl.qin.{ii}") + shutil.copyfile(f"{TEST_DIR}/qunino_vinyl.qout.{ii}", f"{SCR_DIR}/qunino_vinyl.qout.{ii}") handler = QChemErrorHandler(input_file="qunino_vinyl.qin.0", output_file="qunino_vinyl.qout.0") handler.check() @@ -113,14 +107,8 @@ def test_failed_to_transform(self): def test_scf_failed_to_converge(self): for ii in range(3): - shutil.copyfile( - os.path.join(TEST_DIR, "crowd_gradient.qin." + str(ii)), - os.path.join(SCR_DIR, "crowd_gradient.qin." + str(ii)), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "crowd_gradient.qout." + str(ii)), - os.path.join(SCR_DIR, "crowd_gradient.qout." + str(ii)), - ) + shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qin.{ii}", f"{SCR_DIR}/crowd_gradient.qin.{ii}") + shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qout.{ii}", f"{SCR_DIR}/crowd_gradient.qout.{ii}") handler = QChemErrorHandler(input_file="crowd_gradient.qin.0", output_file="crowd_gradient.qout.0") handler.check() @@ -130,9 +118,9 @@ def test_scf_failed_to_converge(self): self._check_equivalent_inputs("crowd_gradient.qin.0", "crowd_gradient.qin.1") def test_scf_failed_to_converge_gdm_add_cycles(self): - shutil.copyfile(os.path.join(TEST_DIR, "gdm_add_cycles/mol.qin"), os.path.join(SCR_DIR, "mol.qin")) - shutil.copyfile(os.path.join(TEST_DIR, "gdm_add_cycles/mol.qin.1"), os.path.join(SCR_DIR, "mol.qin.1")) - shutil.copyfile(os.path.join(TEST_DIR, "gdm_add_cycles/mol.qout"), os.path.join(SCR_DIR, "mol.qout")) + shutil.copyfile(f"{TEST_DIR}/gdm_add_cycles/mol.qin", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/gdm_add_cycles/mol.qin.1", f"{SCR_DIR}/mol.qin.1") + shutil.copyfile(f"{TEST_DIR}/gdm_add_cycles/mol.qout", f"{SCR_DIR}/mol.qout") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() @@ -142,18 +130,9 @@ def test_scf_failed_to_converge_gdm_add_cycles(self): self._check_equivalent_inputs("mol.qin", "mol.qin.1") def test_advanced_scf_failed_to_converge_1(self): - shutil.copyfile( - os.path.join(TEST_DIR, "diis_guess_always/mol.qin.0"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "diis_guess_always/mol.qout.0"), - os.path.join(SCR_DIR, "mol.qout"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "diis_guess_always/mol.qin.1"), - os.path.join(SCR_DIR, "mol.qin.1"), - ) + shutil.copyfile(f"{TEST_DIR}/diis_guess_always/mol.qin.0", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/diis_guess_always/mol.qout.0", f"{SCR_DIR}/mol.qout") + shutil.copyfile(f"{TEST_DIR}/diis_guess_always/mol.qin.1", f"{SCR_DIR}/mol.qin.1") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() @@ -163,18 +142,9 @@ def test_advanced_scf_failed_to_converge_1(self): self._check_equivalent_inputs("mol.qin", "mol.qin.1") def test_scf_into_opt(self): - shutil.copyfile( - os.path.join(TEST_DIR, "scf_into_opt/mol.qin.0"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "scf_into_opt/mol.qout.0"), - os.path.join(SCR_DIR, "mol.qout"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "scf_into_opt/mol.qin.1"), - os.path.join(SCR_DIR, "mol.qin.1"), - ) + shutil.copyfile(f"{TEST_DIR}/scf_into_opt/mol.qin.0", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/scf_into_opt/mol.qout.0", f"{SCR_DIR}/mol.qout") + shutil.copyfile(f"{TEST_DIR}/scf_into_opt/mol.qin.1", f"{SCR_DIR}/mol.qin.1") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() @@ -183,10 +153,7 @@ def test_scf_into_opt(self): assert dct["actions"] == [{"scf_algorithm": "gdm"}, {"max_scf_cycles": "500"}] self._check_equivalent_inputs("mol.qin", "mol.qin.1") - shutil.copyfile( - os.path.join(TEST_DIR, "scf_into_opt/mol.qout.1"), - os.path.join(SCR_DIR, "mol.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/scf_into_opt/mol.qout.1", f"{SCR_DIR}/mol.qout") handler.check() dct = handler.correct() @@ -194,18 +161,9 @@ def test_scf_into_opt(self): assert dct["actions"] == [{"molecule": "molecule_from_last_geometry"}] def test_custom_smd(self): - shutil.copyfile( - os.path.join(TEST_DIR, "custom_smd/mol.qin.0"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "custom_smd/mol.qout.0"), - os.path.join(SCR_DIR, "mol.qout"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "custom_smd/mol.qin.1"), - os.path.join(SCR_DIR, "mol.qin.1"), - ) + shutil.copyfile(f"{TEST_DIR}/custom_smd/mol.qin.0", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/custom_smd/mol.qout.0", f"{SCR_DIR}/mol.qout") + shutil.copyfile(f"{TEST_DIR}/custom_smd/mol.qin.1", f"{SCR_DIR}/mol.qin.1") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() @@ -214,10 +172,7 @@ def test_custom_smd(self): assert dct["actions"] == [{"scf_algorithm": "gdm"}, {"max_scf_cycles": "500"}] self._check_equivalent_inputs("mol.qin", "mol.qin.1") - shutil.copyfile( - os.path.join(TEST_DIR, "custom_smd/mol.qout.1"), - os.path.join(SCR_DIR, "mol.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/custom_smd/mol.qout.1", f"{SCR_DIR}/mol.qout") handler.check() dct = handler.correct() @@ -225,18 +180,9 @@ def test_custom_smd(self): assert dct["actions"] is None def test_out_of_opt_cycles(self): - shutil.copyfile( - os.path.join(TEST_DIR, "crowd_gradient.qin.2"), - os.path.join(SCR_DIR, "crowd_gradient.qin.2"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "crowd_gradient.qout.2"), - os.path.join(SCR_DIR, "crowd_gradient.qout.2"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "crowd_gradient.qin.3"), - os.path.join(SCR_DIR, "crowd_gradient.qin.3"), - ) + shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qin.2", f"{SCR_DIR}/crowd_gradient.qin.2") + shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qout.2", f"{SCR_DIR}/crowd_gradient.qout.2") + shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qin.3", f"{SCR_DIR}/crowd_gradient.qin.3") handler = QChemErrorHandler(input_file="crowd_gradient.qin.2", output_file="crowd_gradient.qout.2") handler.check() @@ -246,18 +192,9 @@ def test_out_of_opt_cycles(self): self._check_equivalent_inputs("crowd_gradient.qin.2", "crowd_gradient.qin.3") def test_advanced_out_of_opt_cycles(self): - shutil.copyfile( - os.path.join(TEST_DIR, "2564_complete/error1/mol.qin"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "2564_complete/error1/mol.qout"), - os.path.join(SCR_DIR, "mol.qout"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "2564_complete/mol.qin.opt_0"), - os.path.join(SCR_DIR, "mol.qin.opt_0"), - ) + shutil.copyfile(f"{TEST_DIR}/2564_complete/error1/mol.qin", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/2564_complete/error1/mol.qout", f"{SCR_DIR}/mol.qout") + shutil.copyfile(f"{TEST_DIR}/2564_complete/mol.qin.opt_0", f"{SCR_DIR}/mol.qin.opt_0") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() dct = handler.correct() @@ -265,38 +202,20 @@ def test_advanced_out_of_opt_cycles(self): assert dct["actions"] == [{"s2thresh": "16"}, {"molecule": "molecule_from_last_geometry"}] self._check_equivalent_inputs("mol.qin.opt_0", "mol.qin") assert handler.opt_error_history[0] == "more_bonds" - shutil.copyfile( - os.path.join(TEST_DIR, "2564_complete/mol.qin.opt_0"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "2564_complete/mol.qout.opt_0"), - os.path.join(SCR_DIR, "mol.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/2564_complete/mol.qin.opt_0", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/2564_complete/mol.qout.opt_0", f"{SCR_DIR}/mol.qout") handler.check() assert handler.opt_error_history == [] def test_advanced_out_of_opt_cycles1(self): - shutil.copyfile( - os.path.join(TEST_DIR, "2620_complete/mol.qin.opt_0"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "2620_complete/mol.qout.opt_0"), - os.path.join(SCR_DIR, "mol.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/2620_complete/mol.qin.opt_0", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/2620_complete/mol.qout.opt_0", f"{SCR_DIR}/mol.qout") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") assert handler.check() is False def test_failed_to_read_input(self): - shutil.copyfile( - os.path.join(TEST_DIR, "unable_lamda_weird.qin"), - os.path.join(SCR_DIR, "unable_lamda_weird.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "unable_lamda_weird.qout"), - os.path.join(SCR_DIR, "unable_lamda_weird.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/unable_lamda_weird.qin", f"{SCR_DIR}/unable_lamda_weird.qin") + shutil.copyfile(f"{TEST_DIR}/unable_lamda_weird.qout", f"{SCR_DIR}/unable_lamda_weird.qout") handler = QChemErrorHandler(input_file="unable_lamda_weird.qin", output_file="unable_lamda_weird.qout") handler.check() dct = handler.correct() @@ -305,14 +224,8 @@ def test_failed_to_read_input(self): self._check_equivalent_inputs("unable_lamda_weird.qin.last", "unable_lamda_weird.qin") def test_input_file_error(self): - shutil.copyfile( - os.path.join(TEST_DIR, "bad_input.qin"), - os.path.join(SCR_DIR, "bad_input.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "bad_input.qout"), - os.path.join(SCR_DIR, "bad_input.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/bad_input.qin", f"{SCR_DIR}/bad_input.qin") + shutil.copyfile(f"{TEST_DIR}/bad_input.qout", f"{SCR_DIR}/bad_input.qout") handler = QChemErrorHandler(input_file="bad_input.qin", output_file="bad_input.qout") handler.check() dct = handler.correct() @@ -320,14 +233,8 @@ def test_input_file_error(self): assert dct["actions"] is None def test_basis_not_supported(self): - shutil.copyfile( - os.path.join(TEST_DIR, "basis_not_supported.qin"), - os.path.join(SCR_DIR, "basis_not_supported.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "basis_not_supported.qout"), - os.path.join(SCR_DIR, "basis_not_supported.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/basis_not_supported.qin", f"{SCR_DIR}/basis_not_supported.qin") + shutil.copyfile(f"{TEST_DIR}/basis_not_supported.qout", f"{SCR_DIR}/basis_not_supported.qout") handler = QChemErrorHandler(input_file="basis_not_supported.qin", output_file="basis_not_supported.qout") handler.check() dct = handler.correct() @@ -335,14 +242,8 @@ def test_basis_not_supported(self): assert dct["actions"] is None def test_NLebdevPts(self): - shutil.copyfile( - os.path.join(TEST_DIR, "lebdevpts.qin"), - os.path.join(SCR_DIR, "lebdevpts.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "lebdevpts.qout"), - os.path.join(SCR_DIR, "lebdevpts.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/lebdevpts.qin", f"{SCR_DIR}/lebdevpts.qin") + shutil.copyfile(f"{TEST_DIR}/lebdevpts.qout", f"{SCR_DIR}/lebdevpts.qout") handler = QChemErrorHandler(input_file="lebdevpts.qin", output_file="lebdevpts.qout") handler.check() dct = handler.correct() @@ -350,14 +251,8 @@ def test_NLebdevPts(self): assert dct["actions"] == [{"esp_surface_density": "250"}] def test_read_error(self): - shutil.copyfile( - os.path.join(TEST_DIR, "molecule_read_error/mol.qin"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "molecule_read_error/mol.qout"), - os.path.join(SCR_DIR, "mol.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/molecule_read_error/mol.qin", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/molecule_read_error/mol.qout", f"{SCR_DIR}/mol.qout") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() dct = handler.correct() @@ -366,14 +261,8 @@ def test_read_error(self): self._check_equivalent_inputs("mol.qin.last", "mol.qin") def test_never_called_qchem_error(self): - shutil.copyfile( - os.path.join(TEST_DIR, "mpi_error/mol.qin"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "mpi_error/mol.qout"), - os.path.join(SCR_DIR, "mol.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/mpi_error/mol.qin", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/mpi_error/mol.qout", f"{SCR_DIR}/mol.qout") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() dct = handler.correct() @@ -382,14 +271,8 @@ def test_never_called_qchem_error(self): self._check_equivalent_inputs("mol.qin.last", "mol.qin") def test_OOS_read_hess(self): - shutil.copyfile( - os.path.join(TEST_DIR, "OOS_read_hess.qin"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "OOS_read_hess.qout"), - os.path.join(SCR_DIR, "mol.qout"), - ) + shutil.copyfile(f"{TEST_DIR}/OOS_read_hess.qin", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/OOS_read_hess.qout", f"{SCR_DIR}/mol.qout") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() dct = handler.correct() @@ -399,17 +282,11 @@ def test_OOS_read_hess(self): {"molecule": "molecule_from_last_geometry"}, {"geom_opt_hessian": "deleted"}, ] - self._check_equivalent_inputs(os.path.join(TEST_DIR, "OOS_read_hess_next.qin"), "mol.qin") + self._check_equivalent_inputs(f"{TEST_DIR}/OOS_read_hess_next.qin", "mol.qin") def test_gdm_neg_precon_error(self): - shutil.copyfile( - os.path.join(TEST_DIR, "gdm_neg_precon_error.qin.gz"), - os.path.join(SCR_DIR, "mol.qin.gz"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "gdm_neg_precon_error.qout.gz"), - os.path.join(SCR_DIR, "mol.qout.gz"), - ) + shutil.copyfile(f"{TEST_DIR}/gdm_neg_precon_error.qin.gz", f"{SCR_DIR}/mol.qin.gz") + shutil.copyfile(f"{TEST_DIR}/gdm_neg_precon_error.qout.gz", f"{SCR_DIR}/mol.qout.gz") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() dct = handler.correct() @@ -417,14 +294,8 @@ def test_gdm_neg_precon_error(self): assert dct["actions"] == [{"molecule": "molecule_from_last_geometry"}] def test_fileman_cpscf_nseg_error(self): - shutil.copyfile( - os.path.join(TEST_DIR, "fileman_cpscf.qin.gz"), - os.path.join(SCR_DIR, "mol.qin.gz"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fileman_cpscf.qout.gz"), - os.path.join(SCR_DIR, "mol.qout.gz"), - ) + shutil.copyfile(f"{TEST_DIR}/fileman_cpscf.qin.gz", f"{SCR_DIR}/mol.qin.gz") + shutil.copyfile(f"{TEST_DIR}/fileman_cpscf.qout.gz", f"{SCR_DIR}/mol.qout.gz") handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout") handler.check() dct = handler.correct() diff --git a/tests/qchem/test_job_handler_interaction.py b/tests/qchem/test_job_handler_interaction.py index de41021e..2f60a9ce 100644 --- a/tests/qchem/test_job_handler_interaction.py +++ b/tests/qchem/test_job_handler_interaction.py @@ -40,58 +40,19 @@ def _check_equivalent_inputs(self, input1, input2): def setUp(self): os.makedirs(f"{SCR_DIR}/scratch", exist_ok=True) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/mol.qin.orig"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/error.1/mol.qout"), - os.path.join(SCR_DIR, "mol.qout.error1"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/error.2/mol.qin"), - os.path.join(SCR_DIR, "mol.qin.error2"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/error.2/mol.qout"), - os.path.join(SCR_DIR, "mol.qout.error2"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/error.3/mol.qin"), - os.path.join(SCR_DIR, "mol.qin.error3"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/error.3/mol.qout"), - os.path.join(SCR_DIR, "mol.qout.error3"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/mol.qin.opt_0"), - os.path.join(SCR_DIR, "mol.qin.opt_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/mol.qout.opt_0"), - os.path.join(SCR_DIR, "mol.qout.opt_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/error.5/mol.qin"), - os.path.join(SCR_DIR, "mol.qin.error5"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/error.5/mol.qout"), - os.path.join(SCR_DIR, "mol.qout.error5"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/mol.qin.freq_0"), - os.path.join(SCR_DIR, "mol.qin.freq_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/mol.qout.freq_0"), - os.path.join(SCR_DIR, "mol.qout.freq_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "job_handler_interaction/mol.qin.opt_1"), - os.path.join(SCR_DIR, "mol.qin.opt_1"), - ) + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/mol.qin.orig", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/error.1/mol.qout", f"{SCR_DIR}/mol.qout.error1") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/error.2/mol.qin", f"{SCR_DIR}/mol.qin.error2") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/error.2/mol.qout", f"{SCR_DIR}/mol.qout.error2") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/error.3/mol.qin", f"{SCR_DIR}/mol.qin.error3") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/error.3/mol.qout", f"{SCR_DIR}/mol.qout.error3") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/mol.qin.opt_0", f"{SCR_DIR}/mol.qin.opt_0") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/mol.qout.opt_0", f"{SCR_DIR}/mol.qout.opt_0") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/error.5/mol.qin", f"{SCR_DIR}/mol.qin.error5") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/error.5/mol.qout", f"{SCR_DIR}/mol.qout.error5") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/mol.qin.freq_0", f"{SCR_DIR}/mol.qin.freq_0") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/mol.qout.freq_0", f"{SCR_DIR}/mol.qout.freq_0") + shutil.copyfile(f"{TEST_DIR}/job_handler_interaction/mol.qin.opt_1", f"{SCR_DIR}/mol.qin.opt_1") os.chdir(SCR_DIR) def tearDown(self): diff --git a/tests/qchem/test_jobs.py b/tests/qchem/test_jobs.py index 80803512..3bb40517 100644 --- a/tests/qchem/test_jobs.py +++ b/tests/qchem/test_jobs.py @@ -33,14 +33,8 @@ class QCJobTest(TestCase): def setUp(self): os.makedirs(SCR_DIR) - shutil.copyfile( - os.path.join(TEST_DIR, "no_nbo.qin"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "nbo7.qin"), - os.path.join(SCR_DIR, "different.qin"), - ) + shutil.copyfile(f"{TEST_DIR}/no_nbo.qin", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/nbo7.qin", f"{SCR_DIR}/different.qin") os.chdir(SCR_DIR) def tearDown(self): @@ -98,22 +92,10 @@ def test_save_scratch(self): class OptFFComplexUnlinkedTest(TestCase): def setUp(self): os.makedirs(SCR_DIR) - shutil.copyfile( - os.path.join(TEST_DIR, "FF_complex/mol.qin.opt_0"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "FF_complex/mol.qout.opt_0"), - os.path.join(SCR_DIR, "mol.qout.opt_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "FF_complex/mol.qout.freq_0"), - os.path.join(SCR_DIR, "mol.qout.freq_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "FF_complex/mol.qin.freq_0"), - os.path.join(SCR_DIR, "mol.qin.freq_0"), - ) + shutil.copyfile(f"{TEST_DIR}/FF_complex/mol.qin.opt_0", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/FF_complex/mol.qout.opt_0", f"{SCR_DIR}/mol.qout.opt_0") + shutil.copyfile(f"{TEST_DIR}/FF_complex/mol.qout.freq_0", f"{SCR_DIR}/mol.qout.freq_0") + shutil.copyfile(f"{TEST_DIR}/FF_complex/mol.qin.freq_0", f"{SCR_DIR}/mol.qin.freq_0") os.chdir(SCR_DIR) def tearDown(self): @@ -1162,13 +1144,10 @@ def test_OptFF(self): ).as_dict() assert next(job).as_dict() == expected_next assert ( - QCInput.from_file(os.path.join(TEST_DIR, "single_freq_frag/mol.qin.freq_0")).as_dict() - == QCInput.from_file(os.path.join(SCR_DIR, "mol.qin")).as_dict() - ) - shutil.copyfile( - os.path.join(SCR_DIR, "mol.qin"), - os.path.join(SCR_DIR, "mol.qin.freq_0"), + QCInput.from_file(f"{TEST_DIR}/single_freq_frag/mol.qin.freq_0").as_dict() + == QCInput.from_file(f"{SCR_DIR}/mol.qin").as_dict() ) + shutil.copyfile(f"{SCR_DIR}/mol.qin", f"{SCR_DIR}/mol.qin.freq_0") with pytest.raises(StopIteration): job.__next__() @@ -1178,22 +1157,10 @@ def test_OptFF(self): class TSFFTest(TestCase): def setUp(self): os.makedirs(SCR_DIR) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_no_freqfirst/mol.qin.freq_0"), - os.path.join(SCR_DIR, "test.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_no_freqfirst/mol.qout.ts_0"), - os.path.join(SCR_DIR, "test.qout.ts_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_no_freqfirst/mol.qout.freq_0"), - os.path.join(SCR_DIR, "test.qout.freq_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_no_freqfirst/mol.qin.freq_0"), - os.path.join(SCR_DIR, "test.qin.freq_0"), - ) + shutil.copyfile(f"{TEST_DIR}/fftsopt_no_freqfirst/mol.qin.freq_0", f"{SCR_DIR}/test.qin") + shutil.copyfile(f"{TEST_DIR}/fftsopt_no_freqfirst/mol.qout.ts_0", f"{SCR_DIR}/test.qout.ts_0") + shutil.copyfile(f"{TEST_DIR}/fftsopt_no_freqfirst/mol.qout.freq_0", f"{SCR_DIR}/test.qout.freq_0") + shutil.copyfile(f"{TEST_DIR}/fftsopt_no_freqfirst/mol.qin.freq_0", f"{SCR_DIR}/test.qin.freq_0") os.chdir(SCR_DIR) def tearDown(self): @@ -1230,8 +1197,8 @@ def test_OptFF(self): ).as_dict() assert next(job).as_dict() == expected_next assert ( - QCInput.from_file(os.path.join(TEST_DIR, "fftsopt_no_freqfirst/mol.qin.freq_0")).as_dict() - == QCInput.from_file(os.path.join(SCR_DIR, "test.qin")).as_dict() + QCInput.from_file(f"{TEST_DIR}/fftsopt_no_freqfirst/mol.qin.freq_0").as_dict() + == QCInput.from_file(f"{SCR_DIR}/test.qin").as_dict() ) with pytest.raises(StopIteration): job.__next__() @@ -1241,26 +1208,11 @@ def test_OptFF(self): class TSFFFreqfirstTest(TestCase): def setUp(self): os.makedirs(f"{SCR_DIR}/scratch", exist_ok=True) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_freqfirst/mol.qin.orig"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_freqfirst/mol.qin.freq_pre"), - os.path.join(SCR_DIR, "mol.qin.freq_pre"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_freqfirst/mol.qout.freq_pre"), - os.path.join(SCR_DIR, "mol.qout.freq_pre"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_freqfirst/mol.qout.ts_0"), - os.path.join(SCR_DIR, "mol.qout.ts_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_freqfirst/mol.qout.freq_0"), - os.path.join(SCR_DIR, "mol.qout.freq_0"), - ) + shutil.copyfile(f"{TEST_DIR}/fftsopt_freqfirst/mol.qin.orig", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/fftsopt_freqfirst/mol.qin.freq_pre", f"{SCR_DIR}/mol.qin.freq_pre") + shutil.copyfile(f"{TEST_DIR}/fftsopt_freqfirst/mol.qout.freq_pre", f"{SCR_DIR}/mol.qout.freq_pre") + shutil.copyfile(f"{TEST_DIR}/fftsopt_freqfirst/mol.qout.ts_0", f"{SCR_DIR}/mol.qout.ts_0") + shutil.copyfile(f"{TEST_DIR}/fftsopt_freqfirst/mol.qout.freq_0", f"{SCR_DIR}/mol.qout.freq_0") os.chdir(SCR_DIR) def tearDown(self): @@ -1300,13 +1252,10 @@ def test_OptFF(self): ).as_dict() assert next(job).as_dict() == expected_next assert ( - QCInput.from_file(os.path.join(TEST_DIR, "fftsopt_freqfirst/mol.qin.ts_0")).as_dict() - == QCInput.from_file(os.path.join(SCR_DIR, "mol.qin")).as_dict() - ) - shutil.copyfile( - os.path.join(SCR_DIR, "mol.qin"), - os.path.join(SCR_DIR, "mol.qin.ts_0"), + QCInput.from_file(f"{TEST_DIR}/fftsopt_freqfirst/mol.qin.ts_0").as_dict() + == QCInput.from_file(f"{SCR_DIR}/mol.qin").as_dict() ) + shutil.copyfile(f"{SCR_DIR}/mol.qin", f"{SCR_DIR}/mol.qin.ts_0") expected_next = QCJob( qchem_command="qchem -slurm", max_cores=32, @@ -1319,13 +1268,10 @@ def test_OptFF(self): ).as_dict() assert next(job).as_dict() == expected_next assert ( - QCInput.from_file(os.path.join(TEST_DIR, "fftsopt_freqfirst/mol.qin.freq_0")).as_dict() - == QCInput.from_file(os.path.join(SCR_DIR, "mol.qin")).as_dict() - ) - shutil.copyfile( - os.path.join(SCR_DIR, "mol.qin"), - os.path.join(SCR_DIR, "mol.qin.freq_0"), + QCInput.from_file(f"{TEST_DIR}/fftsopt_freqfirst/mol.qin.freq_0").as_dict() + == QCInput.from_file(f"{SCR_DIR}/mol.qin").as_dict() ) + shutil.copyfile(f"{SCR_DIR}/mol.qin", f"{SCR_DIR}/mol.qin.freq_0") with pytest.raises(StopIteration): job.__next__() @@ -1334,34 +1280,13 @@ def test_OptFF(self): class TSFFFreqFirstMultipleCyclesTest(TestCase): def setUp(self): os.makedirs(f"{SCR_DIR}/scratch", exist_ok=True) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qin.orig"), - os.path.join(SCR_DIR, "mol.qin"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qin.freq_pre"), - os.path.join(SCR_DIR, "mol.qin.freq_pre"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qout.freq_pre"), - os.path.join(SCR_DIR, "mol.qout.freq_pre"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qout.ts_0"), - os.path.join(SCR_DIR, "mol.qout.ts_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qout.freq_0"), - os.path.join(SCR_DIR, "mol.qout.freq_0"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qout.ts_1"), - os.path.join(SCR_DIR, "mol.qout.ts_1"), - ) - shutil.copyfile( - os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qout.freq_1"), - os.path.join(SCR_DIR, "mol.qout.freq_1"), - ) + shutil.copyfile(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qin.orig", f"{SCR_DIR}/mol.qin") + shutil.copyfile(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qin.freq_pre", f"{SCR_DIR}/mol.qin.freq_pre") + shutil.copyfile(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qout.freq_pre", f"{SCR_DIR}/mol.qout.freq_pre") + shutil.copyfile(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qout.ts_0", f"{SCR_DIR}/mol.qout.ts_0") + shutil.copyfile(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qout.freq_0", f"{SCR_DIR}/mol.qout.freq_0") + shutil.copyfile(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qout.ts_1", f"{SCR_DIR}/mol.qout.ts_1") + shutil.copyfile(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qout.freq_1", f"{SCR_DIR}/mol.qout.freq_1") os.chdir(SCR_DIR) def tearDown(self): @@ -1401,13 +1326,10 @@ def test_OptFF(self): ).as_dict() assert next(job).as_dict() == expected_next assert ( - QCInput.from_file(os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qin.ts_0")).as_dict() - == QCInput.from_file(os.path.join(SCR_DIR, "mol.qin")).as_dict() - ) - shutil.copyfile( - os.path.join(SCR_DIR, "mol.qin"), - os.path.join(SCR_DIR, "mol.qin.ts_0"), + QCInput.from_file(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qin.ts_0").as_dict() + == QCInput.from_file(f"{SCR_DIR}/mol.qin").as_dict() ) + shutil.copyfile(f"{SCR_DIR}/mol.qin", f"{SCR_DIR}/mol.qin.ts_0") expected_next = QCJob( qchem_command="qchem -slurm", max_cores=32, @@ -1420,13 +1342,10 @@ def test_OptFF(self): ).as_dict() assert next(job).as_dict() == expected_next assert ( - QCInput.from_file(os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qin.freq_0")).as_dict() - == QCInput.from_file(os.path.join(SCR_DIR, "mol.qin")).as_dict() - ) - shutil.copyfile( - os.path.join(SCR_DIR, "mol.qin"), - os.path.join(SCR_DIR, "mol.qin.freq_0"), + QCInput.from_file(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qin.freq_0").as_dict() + == QCInput.from_file(f"{SCR_DIR}/mol.qin").as_dict() ) + shutil.copyfile(f"{SCR_DIR}/mol.qin", f"{SCR_DIR}/mol.qin.freq_0") expected_next = QCJob( qchem_command="qchem -slurm", max_cores=32, @@ -1439,13 +1358,10 @@ def test_OptFF(self): ).as_dict() assert next(job).as_dict() == expected_next assert ( - QCInput.from_file(os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qin.ts_1")).as_dict() - == QCInput.from_file(os.path.join(SCR_DIR, "mol.qin")).as_dict() - ) - shutil.copyfile( - os.path.join(SCR_DIR, "mol.qin"), - os.path.join(SCR_DIR, "mol.qin.ts_1"), + QCInput.from_file(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qin.ts_1").as_dict() + == QCInput.from_file(f"{SCR_DIR}/mol.qin").as_dict() ) + shutil.copyfile(f"{SCR_DIR}/mol.qin", f"{SCR_DIR}/mol.qin.ts_1") expected_next = QCJob( qchem_command="qchem -slurm", max_cores=32, @@ -1458,13 +1374,10 @@ def test_OptFF(self): ).as_dict() assert next(job).as_dict() == expected_next assert ( - QCInput.from_file(os.path.join(TEST_DIR, "fftsopt_multiple_cycles/mol.qin.freq_1")).as_dict() - == QCInput.from_file(os.path.join(SCR_DIR, "mol.qin")).as_dict() - ) - shutil.copyfile( - os.path.join(SCR_DIR, "mol.qin"), - os.path.join(SCR_DIR, "mol.qin.freq_1"), + QCInput.from_file(f"{TEST_DIR}/fftsopt_multiple_cycles/mol.qin.freq_1").as_dict() + == QCInput.from_file(f"{SCR_DIR}/mol.qin").as_dict() ) + shutil.copyfile(f"{SCR_DIR}/mol.qin", f"{SCR_DIR}/mol.qin.freq_1") with pytest.raises(StopIteration): job.__next__()