From 737941e2c760afcf16c35498e0e210483fb12eb7 Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Wed, 16 Oct 2019 16:13:54 +0200 Subject: [PATCH] Copy job parameters without salome session. --- src/cpp/Test/SampleTest.cxx | 55 +++++++++++++++++++++++++++++++------ src/pydefx/parameters.py | 38 +++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/cpp/Test/SampleTest.cxx b/src/cpp/Test/SampleTest.cxx index c51fd89..3704302 100644 --- a/src/cpp/Test/SampleTest.cxx +++ b/src/cpp/Test/SampleTest.cxx @@ -208,8 +208,6 @@ void SampleTest::params() { Py_Initialize(); { - try - { ydefx::JobParametersProxy jpp; CPPUNIT_ASSERT(jpp.resource_name() == "localhost"); CPPUNIT_ASSERT(jpp.job_type() == "yacs_file"); @@ -262,12 +260,53 @@ void SampleTest::params() CPPUNIT_ASSERT(jpp.result_directory() == "rd"); CPPUNIT_ASSERT(jpp.wckey() == "wk"); CPPUNIT_ASSERT(jpp.work_directory() == "wd"); - } - catch(std::exception& e) - { - std::cout << e.what(); - CPPUNIT_FAIL("Unexpected exception!"); - } + // test copy constructor + ydefx::JobParametersProxy jpp_2(jpp); + CPPUNIT_ASSERT(jpp_2.env_file() == "a"); + CPPUNIT_ASSERT(jpp_2.exclusive()); + CPPUNIT_ASSERT(jpp_2.extra_params() == "b"); + CPPUNIT_ASSERT(jpp_2.job_file() == "c"); + CPPUNIT_ASSERT(jpp_2.job_name() == "d"); + CPPUNIT_ASSERT(jpp_2.job_type() == "e"); + CPPUNIT_ASSERT(jpp_2.local_directory() == "fi"); + CPPUNIT_ASSERT(jpp_2.maximum_duration() == "dur"); + CPPUNIT_ASSERT(jpp_2.mem_mb() == 5); + CPPUNIT_ASSERT(jpp_2.mem_per_cpu() == 42); + CPPUNIT_ASSERT(jpp_2.nb_branches() == 18); + CPPUNIT_ASSERT(jpp_2.nb_node() == 15); + CPPUNIT_ASSERT(jpp_2.nb_proc() == 13); + CPPUNIT_ASSERT(jpp_2.nb_proc_per_node() == 12); + CPPUNIT_ASSERT(jpp_2.partition() == "gg"); + CPPUNIT_ASSERT(jpp_2.pre_command() == "pc"); + CPPUNIT_ASSERT(jpp_2.queue() == "qq"); + CPPUNIT_ASSERT(jpp_2.resource_name() == "rn"); + CPPUNIT_ASSERT(jpp_2.result_directory() == "rd"); + CPPUNIT_ASSERT(jpp_2.wckey() == "wk"); + CPPUNIT_ASSERT(jpp_2.work_directory() == "wd"); + // test copy operator + ydefx::JobParametersProxy jpp_3; + jpp_3 = jpp; + CPPUNIT_ASSERT(jpp_3.env_file() == "a"); + CPPUNIT_ASSERT(jpp_3.exclusive()); + CPPUNIT_ASSERT(jpp_3.extra_params() == "b"); + CPPUNIT_ASSERT(jpp_3.job_file() == "c"); + CPPUNIT_ASSERT(jpp_3.job_name() == "d"); + CPPUNIT_ASSERT(jpp_3.job_type() == "e"); + CPPUNIT_ASSERT(jpp_3.local_directory() == "fi"); + CPPUNIT_ASSERT(jpp_3.maximum_duration() == "dur"); + CPPUNIT_ASSERT(jpp_3.mem_mb() == 5); + CPPUNIT_ASSERT(jpp_3.mem_per_cpu() == 42); + CPPUNIT_ASSERT(jpp_3.nb_branches() == 18); + CPPUNIT_ASSERT(jpp_3.nb_node() == 15); + CPPUNIT_ASSERT(jpp_3.nb_proc() == 13); + CPPUNIT_ASSERT(jpp_3.nb_proc_per_node() == 12); + CPPUNIT_ASSERT(jpp_3.partition() == "gg"); + CPPUNIT_ASSERT(jpp_3.pre_command() == "pc"); + CPPUNIT_ASSERT(jpp_3.queue() == "qq"); + CPPUNIT_ASSERT(jpp_3.resource_name() == "rn"); + CPPUNIT_ASSERT(jpp_3.result_directory() == "rd"); + CPPUNIT_ASSERT(jpp_3.wckey() == "wk"); + CPPUNIT_ASSERT(jpp_3.work_directory() == "wd"); } Py_Finalize(); } diff --git a/src/pydefx/parameters.py b/src/pydefx/parameters.py index 4feba18..53b9bd6 100644 --- a/src/pydefx/parameters.py +++ b/src/pydefx/parameters.py @@ -58,3 +58,41 @@ class Parameters: def createTmpResultDirectory(self): self.salome_parameters.result_directory = configuration.newResultDirectory( tempfile.gettempdir()) + + # Specific deep copy function is needed because the default one does not work + # for swig objects, when we are in no salome session mode. + def __deepcopy__(self, memo): + cls = self.__class__ + newobj = cls.__new__(cls) + newobj.nb_branches = self.nb_branches + newobj.salome_parameters = salome_proxy.createSalomeParameters() + newobj.salome_parameters.job_name = self.salome_parameters.job_name + newobj.salome_parameters.job_type = self.salome_parameters.job_type + newobj.salome_parameters.job_file = self.salome_parameters.job_file + newobj.salome_parameters.pre_command = self.salome_parameters.pre_command + newobj.salome_parameters.env_file = self.salome_parameters.env_file + newobj.salome_parameters.in_files = list(self.salome_parameters.in_files) + newobj.salome_parameters.out_files = list(self.salome_parameters.out_files) + newobj.salome_parameters.work_directory = self.salome_parameters.work_directory + newobj.salome_parameters.local_directory = self.salome_parameters.local_directory + newobj.salome_parameters.result_directory = self.salome_parameters.result_directory + newobj.salome_parameters.maximum_duration = self.salome_parameters.maximum_duration + newobj.salome_parameters.queue = self.salome_parameters.queue + newobj.salome_parameters.partition = self.salome_parameters.partition + newobj.salome_parameters.exclusive = self.salome_parameters.exclusive + newobj.salome_parameters.mem_per_cpu = self.salome_parameters.mem_per_cpu + newobj.salome_parameters.wckey = self.salome_parameters.wckey + newobj.salome_parameters.extra_params = self.salome_parameters.extra_params + newobj.salome_parameters.specific_parameters = self.salome_parameters.specific_parameters + newobj.salome_parameters.resource_required.name = self.salome_parameters.resource_required.name + newobj.salome_parameters.resource_required.hostname = self.salome_parameters.resource_required.hostname + newobj.salome_parameters.resource_required.can_launch_batch_jobs = self.salome_parameters.resource_required.can_launch_batch_jobs + newobj.salome_parameters.resource_required.can_run_containers = self.salome_parameters.resource_required.can_run_containers + newobj.salome_parameters.resource_required.OS = self.salome_parameters.resource_required.OS + newobj.salome_parameters.resource_required.nb_proc = self.salome_parameters.resource_required.nb_proc + newobj.salome_parameters.resource_required.mem_mb = self.salome_parameters.resource_required.mem_mb + newobj.salome_parameters.resource_required.cpu_clock = self.salome_parameters.resource_required.cpu_clock + newobj.salome_parameters.resource_required.nb_node = self.salome_parameters.resource_required.nb_node + newobj.salome_parameters.resource_required.nb_proc_per_node = self.salome_parameters.resource_required.nb_proc_per_node + + return newobj -- 2.39.2