Ejemplo n.º 1
0
    def test_parent_children__fail(self):
        parent_state = create_state_from_ee2(BATCH_PARENT)
        child_states = [create_state_from_ee2(job_id) for job_id in BATCH_CHILDREN]
        with self.assertRaisesRegex(
            ValueError, "Must supply children when setting children of batch job parent"
        ):
            Job(parent_state)

        child_jobs = [Job(child_state) for child_state in child_states]
        with self.assertRaisesRegex(ValueError, CHILD_ID_MISMATCH):
            Job(
                parent_state,
                children=child_jobs[1:],
            )

        with self.assertRaisesRegex(ValueError, CHILD_ID_MISMATCH):
            Job(
                parent_state,
                children=child_jobs * 2,
            )

        with self.assertRaisesRegex(ValueError, CHILD_ID_MISMATCH):
            Job(
                parent_state,
                children=child_jobs + [create_job_from_ee2(JOB_COMPLETED)],
            )
Ejemplo n.º 2
0
    def test_parameters__param_fetch_fail(self):
        """
        test failure to retrieve job params data
        """
        job_state = get_test_job(JOB_TERMINATED)
        del job_state["job_input"]["params"]
        job = Job(job_state)
        self.assertEqual(job.params, JOB_ATTR_DEFAULTS["params"])

        with self.assertRaisesRegex(Exception, "Unable to fetch parameters for job"):
            job.parameters()
Ejemplo n.º 3
0
    def test_parameters(self):
        """
        test that a job returns the correct parameters
        """
        job_state = get_test_job(JOB_COMPLETED)
        job_params = job_state.get("job_input", {}).get("params", None)
        self.assertIsNotNone(job_params)
        job = Job(job_state)
        self.assertIsNotNone(job.params)

        with assert_obj_method_called(MockClients, "get_job_params", call_status=False):
            params = job.parameters()
            self.assertIsNotNone(params)
            self.assertEqual(params, job_params)
Ejemplo n.º 4
0
    def _mocked_job(self, with_version=True, with_cell_id=True, with_run_id=True, with_token_id=True):
        kwargs = dict()
        if with_version:
            kwargs["app_version"] = self.app_version
        if with_cell_id:
            kwargs["cell_id"] = self.cell_id
        if with_run_id:
            kwargs["run_id"] = self.run_id
        if with_token_id:
            kwargs["token_id"] = self.token_id

        job = Job(self.job_id, self.app_id, self.inputs, self.owner, tag=self.app_tag, **kwargs)

        return job
Ejemplo n.º 5
0
    def test_parameters__param_fetch_ok(self):
        """
        test that a job can successfully retrieve parameters from ee2
        if they do not exist
        """
        job_state = get_test_job(JOB_CREATED)
        job_params = job_state.get("job_input", {}).get("params", None)
        self.assertIsNotNone(job_params)

        # delete the job params from the input
        del job_state["job_input"]["params"]
        job = Job(job_state)
        self.assertEqual(job.params, JOB_ATTR_DEFAULTS["params"])

        params = job.parameters()
        self.assertEqual(params, job_params)
Ejemplo n.º 6
0
    def test_parent_children__ok(self):
        child_jobs = [Job.from_job_id(job_id) for job_id in BATCH_CHILDREN]
        parent_job = Job(
            create_state_from_ee2(BATCH_PARENT),
            children=child_jobs,
        )

        self.assertFalse(parent_job.was_terminal())

        # Make all child jobs completed
        with mock.patch.object(
            MockClients,
            "check_job",
            mock.Mock(return_value={"status": COMPLETED_STATUS}),
        ):
            for child_job in child_jobs:
                child_job.state(force_refresh=True)

        self.assertTrue(parent_job.was_terminal())
Ejemplo n.º 7
0
    def test_job_from_state__custom(self):
        """
        test job initialisation with defaults being filled in
        TODO do a non-default?
        """
        params = [
            {
                "import_type": "FASTQ/FASTA",
                "name": "small.forward.fq",
            }
        ]
        test_job = {
            "user": "******",
            "job_input": {
                "params": params,
                "service_ver": "42",
                "app_id": "This/app",
            },
            "job_id": "0123456789abcdef",
        }

        expected = {
            "app_id": "This/app",
            "app_version": "42",
            "batch_id": JOB_ATTR_DEFAULTS["batch_id"],
            "cell_id": JOB_ATTR_DEFAULTS["cell_id"],
            "extra_data": None,
            "job_id": "0123456789abcdef",
            "params": params,
            "run_id": JOB_ATTR_DEFAULTS["run_id"],
            "tag": JOB_ATTR_DEFAULTS["tag"],
            "user": "******",
        }

        job = Job(test_job)
        self.check_job_attrs_custom(job, expected)
Ejemplo n.º 8
0
def create_job_from_ee2(job_id, extra_data=None, children=None):
    state = get_test_job(job_id)
    job = Job(state, extra_data=extra_data, children=children)
    return job
Ejemplo n.º 9
0
 def test_show_output_widget__incomplete_state(self):
     job = Job(get_test_job(JOB_CREATED))
     self.assertRegex(
         job.show_output_widget(), "Job is incomplete! It has status 'created'"
     )
Ejemplo n.º 10
0
 def test_show_output_widget(self, mock_method):
     mock_method.return_value = True
     job = Job(get_test_job(JOB_COMPLETED))
     self.assertTrue(job.show_output_widget())
     mock_method.assert_called_once()
Ejemplo n.º 11
0
    def test_job_init__error_no_job_id(self):

        with self.assertRaisesRegex(
            ValueError, "Cannot create a job without a job ID!"
        ):
            Job({"params": {}, "app_id": "this/that"})