Exemplo n.º 1
0
    def test_load_forward_model(self):
        with self.assertRaises(IOError):
            job = ExtJob("CONFIG_FILE", True)

        with TestAreaContext("python/job_queue/forward_model1"):
            create_valid_config("CONFIG")
            job = ExtJob("CONFIG", True)
            self.assertEqual(job.name(), "CONFIG")
            self.assertEqual(job.get_stdout_file(), None)
            self.assertEqual(job.get_stderr_file(), None)

            self.assertEqual(job.get_executable(),
                             os.path.join(os.getcwd(), "script.sh"))
            self.assertTrue(os.access(job.get_executable(), os.X_OK))

            self.assertEqual(job.min_arg, -1)

            job = ExtJob("CONFIG", True, name="Job")
            self.assertEqual(job.name(), "Job")
            pfx = "ExtJob("
            self.assertEqual(pfx, repr(job)[:len(pfx)])

        with TestAreaContext("python/job_queue/forward_model1a"):
            create_upgraded_valid_config("CONFIG")
            job = ExtJob("CONFIG", True)
            self.assertEqual(job.min_arg, 2)
            self.assertEqual(job.max_arg, 7)
            argTypes = job.arg_types
            self.assertEqual(
                argTypes,
                [
                    ContentTypeEnum.CONFIG_INT,
                    ContentTypeEnum.CONFIG_FLOAT,
                    ContentTypeEnum.CONFIG_STRING,
                    ContentTypeEnum.CONFIG_BOOL,
                    ContentTypeEnum.CONFIG_RUNTIME_FILE,
                    ContentTypeEnum.CONFIG_RUNTIME_INT,
                    ContentTypeEnum.CONFIG_STRING,
                ],
            )

        with TestAreaContext("python/job_queue/forward_model2"):
            create_config_missing_executable("CONFIG")
            with self.assertRaises(ValueError):
                job = ExtJob("CONFIG", True)

        with TestAreaContext("python/job_queue/forward_model3"):
            create_config_missing_EXECUTABLE("CONFIG")
            with self.assertRaises(ValueError):
                job = ExtJob("CONFIG", True)

        with TestAreaContext("python/job_queue/forward_model4"):
            create_config_executable_directory("CONFIG")
            with self.assertRaises(ValueError):
                job = ExtJob("CONFIG", True)

        with TestAreaContext("python/job_queue/forward_model5"):
            create_config_foreign_file("CONFIG")
            with self.assertRaises(ValueError):
                job = ExtJob("CONFIG", True)
Exemplo n.º 2
0
    def test_transfer_arg_types(self):
        with TestAreaContext(
                "python/job_queue/forward_model_transfer_arg_types"):
            with open("FWD_MODEL", "w") as f:
                f.write("EXECUTABLE ls\n")
                f.write("MIN_ARG 2\n")
                f.write("MAX_ARG 6\n")
                f.write("ARG_TYPE 0 INT\n")
                f.write("ARG_TYPE 1 FLOAT\n")
                f.write("ARG_TYPE 2 STRING\n")
                f.write("ARG_TYPE 3 BOOL\n")
                f.write("ARG_TYPE 4 RUNTIME_FILE\n")
                f.write("ARG_TYPE 5 RUNTIME_INT\n")

            job = ExtJob("FWD_MODEL", True)

            ext_joblist = ExtJoblist()
            ext_joblist.add_job(job.name(), job)
            forward_model = ForwardModel(ext_joblist)
            forward_model.add_job("FWD_MODEL")

            run_id = "test_no_jobs_id"
            umask = 4
            global_args = SubstitutionList()

            forward_model.formatted_fprintf(run_id, os.getcwd(), "data_root",
                                            global_args, umask,
                                            EnvironmentVarlist())
            config = load_configs(self.JOBS_JSON_FILE)
            printed_job = config["jobList"][0]
            self.assertEqual(printed_job["min_arg"], 2)
            self.assertEqual(printed_job["max_arg"], 6)
            self.assertEqual(printed_job["arg_types"], [
                "INT", "FLOAT", "STRING", "BOOL", "RUNTIME_FILE", "RUNTIME_INT"
            ])
Exemplo n.º 3
0
    def test_load_forward_model(self):
        with self.assertRaises(IOError):
            job = ExtJob("CONFIG_FILE", True)

        with TestAreaContext("python/job_queue/forward_model1"):
            create_valid_config("CONFIG")
            job = ExtJob("CONFIG", True)
            self.assertEqual(job.name(), "CONFIG")

            self.assertEqual(job.get_executable(),
                             os.path.join(os.getcwd(), "script.sh"))
            self.assertTrue(os.access(job.get_executable(), os.X_OK))

            job = ExtJob("CONFIG", True, name="Job")
            self.assertEqual(job.name(), "Job")
            pfx = 'ExtJob('
            self.assertEqual(pfx, repr(job)[:len(pfx)])

        with TestAreaContext("python/job_queue/forward_model2"):
            create_config_missing_executable("CONFIG")
            with self.assertRaises(ValueError):
                job = ExtJob("CONFIG", True)

        with TestAreaContext("python/job_queue/forward_model3"):
            create_config_missing_EXECUTABLE("CONFIG")
            with self.assertRaises(ValueError):
                job = ExtJob("CONFIG", True)

        with TestAreaContext("python/job_queue/forward_model4"):
            create_config_executable_directory("CONFIG")
            with self.assertRaises(ValueError):
                job = ExtJob("CONFIG", True)

        with TestAreaContext("python/job_queue/forward_model5"):
            create_config_foreign_file("CONFIG")
            with self.assertRaises(ValueError):
                job = ExtJob("CONFIG", True)