def select_qualifier_list(self): # Add whitelists if 'whitelist' in self.ns and self.ns.whitelist: for whitelist_file in self.ns.whitelist: qualifier = self.get_whitelist_from_file( whitelist_file.name, whitelist_file) if qualifier is not None: self._qualifier_list.append(qualifier) # Add all the --include jobs for pattern in self.ns.include_pattern_list: origin = Origin(CommandLineTextSource('-i', pattern), None, None) try: qualifier = RegExpJobQualifier('^{}$'.format(pattern), origin, inclusive=True) except Exception as exc: logger.warning(_("Incorrect pattern %r: %s"), pattern, exc) else: self._qualifier_list.append(qualifier) # Add all the --exclude jobs for pattern in self.ns.exclude_pattern_list: origin = Origin(CommandLineTextSource('-x', pattern), None, None) try: qualifier = RegExpJobQualifier('^{}$'.format(pattern), origin, inclusive=False) except Exception as exc: logger.warning(_("Incorrect pattern %r: %s"), pattern, exc) else: self._qualifier_list.append(qualifier) if self.config.whitelist is not Unset: self._qualifier_list.append( self.get_whitelist_from_file(self.config.whitelist))
def _get_matching_job_list(self, ns, job_list): logger.debug("_get_matching_job_list(%r, %r)", ns, job_list) qualifier_list = [] # Add whitelists for whitelist_file in ns.whitelist: qualifier = self.get_whitelist_from_file(whitelist_file.name, whitelist_file) if qualifier is not None: qualifier_list.append(qualifier) # Add all the --include jobs for pattern in ns.include_pattern_list: try: qualifier = RegExpJobQualifier('^{}$'.format(pattern), inclusive=True) except Exception as exc: logger.warning(_("Incorrect pattern %r: %s"), pattern, exc) else: qualifier_list.append(qualifier) # Add all the --exclude jobs for pattern in ns.exclude_pattern_list: try: qualifier = RegExpJobQualifier('^{}$'.format(pattern), inclusive=False) except Exception as exc: logger.warning(_("Incorrect pattern %r: %s"), pattern, exc) else: qualifier_list.append(qualifier) logger.debug("select_jobs(%r, %r)", job_list, qualifier_list) return select_jobs(job_list, qualifier_list)
def test_inclusive(self): """ verify that inclusive selection works """ self.assertTrue( CompositeQualifier([ RegExpJobQualifier('foo', self.origin), ]).designates(make_job("foo"))) self.assertFalse( CompositeQualifier([ RegExpJobQualifier('foo', self.origin), ]).designates(make_job("bar")))
def test_get_vote(self): """ verify that RegExpJobQualifier.get_vote() works as expected """ self.assertEqual( RegExpJobQualifier("foo", self.origin).get_vote( JobDefinition({'id': 'foo'})), IJobQualifier.VOTE_INCLUDE) self.assertEqual( RegExpJobQualifier("foo", self.origin, inclusive=False).get_vote( JobDefinition({'id': 'foo'})), IJobQualifier.VOTE_EXCLUDE) self.assertEqual( RegExpJobQualifier("foo", self.origin).get_vote( JobDefinition({'id': 'bar'})), IJobQualifier.VOTE_IGNORE) self.assertEqual( RegExpJobQualifier("foo", self.origin, inclusive=False).get_vote( JobDefinition({'id': 'bar'})), IJobQualifier.VOTE_IGNORE)
def test_exclusive(self): """ verify that non-inclusive selection works """ self.assertFalse( CompositeQualifier([RegExpJobQualifier('foo', inclusive=False) ]).designates(make_job("foo"))) self.assertFalse( CompositeQualifier([ RegExpJobQualifier(".*"), RegExpJobQualifier('foo', inclusive=False) ]).designates(make_job("foo"))) self.assertTrue( CompositeQualifier([ RegExpJobQualifier(".*"), RegExpJobQualifier('foo', inclusive=False) ]).designates(make_job("bar")))
def _get_matching_job_list(self, ns, job_list): logger.debug("_get_matching_job_list(%r, %r)", ns, job_list) qualifier_list = [] # Add the test plan if ns.test_plan is not None: # Uh, dodgy, recreate a list of providers from the list of jobs we # know about here. This code needs to be re-factored to use the # upcoming provider store class. for provider in {job.provider for job in job_list}: for unit in provider.id_map[ns.test_plan]: if unit.Meta.name == 'test plan': qualifier_list.append(unit.get_qualifier()) break else: logger.debug(_("There is no test plan: %s"), ns.test_plan) # Add whitelists for whitelist_file in ns.whitelist: qualifier = self.get_whitelist_from_file(whitelist_file.name, whitelist_file) if qualifier is not None: qualifier_list.append(qualifier) # Add all the --include jobs for pattern in ns.include_pattern_list: origin = Origin(CommandLineTextSource('-i', pattern), None, None) try: qualifier = RegExpJobQualifier('^{}$'.format(pattern), origin, inclusive=True) except Exception as exc: logger.warning(_("Incorrect pattern %r: %s"), pattern, exc) else: qualifier_list.append(qualifier) # Add all the --exclude jobs for pattern in ns.exclude_pattern_list: origin = Origin(CommandLineTextSource('-x', pattern), None, None) try: qualifier = RegExpJobQualifier('^{}$'.format(pattern), origin, inclusive=False) except Exception as exc: logger.warning(_("Incorrect pattern %r: %s"), pattern, exc) else: qualifier_list.append(qualifier) logger.debug("select_jobs(%r, %r)", job_list, qualifier_list) return select_jobs(job_list, qualifier_list)
def test_get_vote(self): """ verify how CompositeQualifier.get_vote() behaves in various situations """ # Default is IGNORE self.assertEqual( CompositeQualifier([]).get_vote(make_job("foo")), IJobQualifier.VOTE_IGNORE) # Any match is INCLUDE self.assertEqual( CompositeQualifier([ RegExpJobQualifier("foo", self.origin), ]).get_vote(make_job("foo")), IJobQualifier.VOTE_INCLUDE) # Any negative match is EXCLUDE self.assertEqual( CompositeQualifier([ RegExpJobQualifier("foo", self.origin, inclusive=False), ]).get_vote(make_job("foo")), IJobQualifier.VOTE_EXCLUDE) # Negative matches take precedence over positive matches self.assertEqual( CompositeQualifier([ RegExpJobQualifier("foo", self.origin), RegExpJobQualifier("foo", self.origin, inclusive=False), ]).get_vote(make_job("foo")), IJobQualifier.VOTE_EXCLUDE) # Unrelated patterns are not affecting the result self.assertEqual( CompositeQualifier([ RegExpJobQualifier("foo", self.origin), RegExpJobQualifier("bar", self.origin), ]).get_vote(make_job("foo")), IJobQualifier.VOTE_INCLUDE)
def setUp(self): self.origin = mock.Mock(name='origin', spec_set=Origin) self.qualifier = RegExpJobQualifier("f.*", self.origin)
def test_get_matching_job_list(self): job_list = [make_job('foo'), make_job('froz'), make_job('barg')] self.assertEqual( get_matching_job_list(job_list, RegExpJobQualifier('f.*')), [make_job('foo'), make_job('froz')])
def test_get_matching_job_list(self): origin = mock.Mock(name='origin', spec_set=Origin) job_list = [make_job('foo'), make_job('froz'), make_job('barg')] self.assertEqual( get_matching_job_list(job_list, RegExpJobQualifier('f.*', origin)), [make_job('foo'), make_job('froz')])
def setUp(self): self.qualifier = RegExpJobQualifier("f.*")