def test_run_task_saves_result(self): trial_result = mock.create_autospec(mock_types.MockTrialResult) self.system.finish_trial = lambda: trial_result subject = RunSystemTask( system=self.system, image_source=self.image_source, state=JobState.RUNNING, node_id='test', job_id=1 ) self.assertFalse(trial_result.save.called) subject.run_task(self.path_manager) self.assertTrue(trial_result.save.called)
def test_run_task_records_returned_trial_result(self): trial_result = mock.create_autospec(mock_types.MockTrialResult) self.system.finish_trial = lambda: trial_result subject = RunSystemTask( system=self.system, image_source=self.image_source, state=JobState.RUNNING, node_id='test', job_id=1 ) self.assertIsNone(subject.result) subject.run_task(self.path_manager) self.assertTrue(subject.is_finished) self.assertEqual(subject.result, trial_result)
def test_run_task_passes_through_seed(self): trial_result = mock.create_autospec(mock_types.MockTrialResult) self.system.finish_trial = lambda: trial_result seed = 14578 mock_system = mock.create_autospec(VisionSystem, spec_set=True) subject = RunSystemTask( system=mock_system, image_source=self.image_source, state=JobState.RUNNING, seed=seed, node_id='test', job_id=1 ) subject.run_task(self.path_manager) self.assertTrue(mock_system.start_trial.called) self.assertEqual(mock.call(self.image_source.sequence_type, seed=seed), mock_system.start_trial.call_args)
def test_run_task_records_unable_to_measure_trial(self): self.system.is_image_source_appropriate = lambda _: False subject = RunSystemTask( system=self.system, image_source=self.image_source, state=JobState.RUNNING, node_id='test', job_id=1 ) self.assertIsNone(subject.result) subject.run_task(self.path_manager) self.assertTrue(subject.is_finished) self.assertIsNotNone(subject.result) self.assertFalse(subject.result.success) self.assertIsNotNone(subject.result.message) self.assertEqual(self.system, subject.result.system) self.assertEqual(self.image_source, subject.result.image_source)
def test_run_task_records_exception_during_execution_and_re_raises(self): message = 'No mercy. No respite.' def bad_measure_results(*_, **__): raise ValueError(message) self.system.start_trial = bad_measure_results subject = RunSystemTask( system=self.system, image_source=self.image_source, state=JobState.RUNNING, node_id='test', job_id=1 ) self.assertIsNone(subject.result) with self.assertRaises(ValueError): subject.run_task(self.path_manager) self.assertTrue(subject.is_finished) self.assertIsNotNone(subject.result) self.assertFalse(subject.result.success) self.assertIsNotNone(subject.result.message) self.assertIn(message, subject.result.message) self.assertEqual(self.system, subject.result.system) self.assertEqual(self.image_source, subject.result.image_source)