def test_smoke(self): """ various smoke tests that check if JobIdQualifier.designates() works """ self.assertTrue(JobIdQualifier('name').designates(make_job('name'))) self.assertFalse(JobIdQualifier('nam').designates(make_job('name'))) self.assertFalse(JobIdQualifier('.*').designates(make_job('name'))) self.assertFalse(JobIdQualifier('*').designates(make_job('name')))
def test_select_jobs__inclusion(self): """ verify that select_jobs() honors qualifier ordering """ job_a = JobDefinition({'id': 'a'}) job_b = JobDefinition({'id': 'b'}) job_c = JobDefinition({'id': 'c'}) qual_a = JobIdQualifier("a", self.origin) qual_c = JobIdQualifier("c", self.origin) for job_list in permutations([job_a, job_b, job_c], 3): # Regardless of how the list of job is ordered the result # should be the same, depending on the qualifier list self.assertEqual(select_jobs(job_list, [qual_a, qual_c]), [job_a, job_c])
def test_get_primitive_qualifiers(self): """ verify that CompositeQualifiers.get_composite_qualifiers() works """ # given three qualifiers q1 = JobIdQualifier("q1", self.origin) q2 = JobIdQualifier("q2", self.origin) q3 = JobIdQualifier("q3", self.origin) # we expect to see them flattened expected = [q1, q2, q3] # from a nested structure like this measured = CompositeQualifier([CompositeQualifier([q1, q2]), q3]).get_primitive_qualifiers() self.assertEqual(expected, measured)
def test_trim_does_remove_job_state(self): """ verify that trim_job_list() removes job state for removed jobs """ self.assertIn("a", self.session.job_state_map) self.session.trim_job_list(JobIdQualifier("a")) self.assertNotIn("a", self.session.job_state_map)
def test_get_vote(self): """ verify that JobIdQualifier.get_vote() works as expected """ self.assertEqual( JobIdQualifier("foo").get_vote(JobDefinition({'id': 'foo'})), IJobQualifier.VOTE_INCLUDE) self.assertEqual( JobIdQualifier("foo", inclusive=False).get_vote( JobDefinition({'id': 'foo'})), IJobQualifier.VOTE_EXCLUDE) self.assertEqual( JobIdQualifier("foo").get_vote(JobDefinition({'id': 'bar'})), IJobQualifier.VOTE_IGNORE) self.assertEqual( JobIdQualifier("foo", inclusive=False).get_vote( JobDefinition({'id': 'bar'})), IJobQualifier.VOTE_IGNORE)
def _get_job(self): job_list = get_matching_job_list( self.get_job_list(None), JobIdQualifier(self.job_id)) if len(job_list) == 0: return None else: return job_list[0]
def test_trim_does_remove_resources(self): """ verify that trim_job_list() removes resources for removed jobs """ self.session.set_resource_list("a", [Resource({'attr': 'value'})]) self.assertIn("a", self.session.resource_map) self.session.trim_job_list(JobIdQualifier("a")) self.assertNotIn("a", self.session.resource_map)
def _get_job(self): job_list = get_matching_job_list( self.get_job_list(None), JobIdQualifier(self.job_id, Origin.get_caller_origin())) if len(job_list) == 0: return None else: return job_list[0]
def test_select_jobs__exclusion(self): """ verify that select_jobs() honors qualifier ordering """ job_a = JobDefinition({'id': 'a'}) job_b = JobDefinition({'id': 'b'}) job_c = JobDefinition({'id': 'c'}) qual_all = CompositeQualifier([ JobIdQualifier("a"), JobIdQualifier("b"), JobIdQualifier("c"), ]) qual_not_c = JobIdQualifier("c", inclusive=False) for job_list in permutations([job_a, job_b, job_c], 3): # Regardless of how the list of job is ordered the result # should be the same, depending on the qualifier list self.assertEqual(select_jobs(job_list, [qual_all, qual_not_c]), [job_a, job_b])
def test_trim_raises_ValueError_for_jobs_on_run_list(self): """ verify that trim_job_list() raises ValueError when any of the jobs marked for removal is in the run_list. """ self.session.update_desired_job_list([self.job_a]) with self.assertRaises(ValueError) as boom: self.session.trim_job_list(JobIdQualifier("a")) self.assertEqual(str(boom.exception), "cannot remove jobs that are on the run list: a")
def test_trim_fires_on_job_state_map_changed(self): """ verify that trim_job_list() fires on_job_state_map_changed() signal """ signal_fired = False def on_job_state_map_changed(): nonlocal signal_fired signal_fired = True self.session.on_job_state_map_changed.connect(on_job_state_map_changed) self.session.trim_job_list(JobIdQualifier("a")) self.assertTrue(signal_fired)
def test_trim_fires_on_job_state_map_changed_only_when_needed(self): """ verify that trim_job_list() does not fires on_job_state_map_changed() signal needlessly, when no jobs is actually being removed. """ signal_fired = False def on_job_state_map_changed(): nonlocal signal_fired signal_fired = True self.session.on_job_state_map_changed.connect(on_job_state_map_changed) self.session.trim_job_list(JobIdQualifier("x")) self.assertFalse(signal_fired)
def test_trim_fires_on_job_removed(self): """ verify that trim_job_list() fires on_job_removed() signal """ signal_fired = False def on_job_removed(job): self.assertIs(job, self.job_a) nonlocal signal_fired signal_fired = True self.session.on_job_removed.connect(on_job_removed) self.session.trim_job_list(JobIdQualifier("a")) self.assertTrue(signal_fired)
def test_trim_does_remove_jobs(self): """ verify that trim_job_list() removes jobs as requested """ self.session.trim_job_list(JobIdQualifier("a")) self.assertEqual(self.session.job_list, [self.job_b])
def setUp(self): self.origin = mock.Mock(name='origin', spec_set=Origin) self.qualifier = JobIdQualifier("foo", self.origin)
def setUp(self): self.qualifier = JobIdQualifier("foo")