class TestOldBuildCancellerUtils(ConfigErrorsMixin, unittest.TestCase): @parameterized.expand([ ('only_builder', [(['bldr'], SourceStampFilter())]), ('with_codebase', [(['bldr'], SourceStampFilter(codebase_eq=['value']))]), ('with_repository', [(['bldr'], SourceStampFilter(repository_eq=['value']))]), ('with_branch', [(['bldr'], SourceStampFilter(branch_eq=['value']))]), ('all', [(['bldr'], SourceStampFilter(codebase_eq=['v1', 'v2'], repository_eq=['v1', 'v2'], branch_eq=['v1', 'v2']))]), ]) def test_check_filters_valid(self, name, filters): OldBuildCanceller.check_filters(filters) @parameterized.expand([ ('dict', {}), ('list_list', [[]]), ]) def test_check_filters_not_dict(self, name, value): with self.assertRaisesConfigError('The filters argument must be a list of tuples'): OldBuildCanceller.check_filters(value) def test_check_filters_invalid_uple(self): with self.assertRaisesConfigError('must be a list of tuples each of which'): OldBuildCanceller.check_filters([('a', 'b', 'c')]) with self.assertRaisesConfigError('must be a list of tuples each of which'): OldBuildCanceller.check_filters([('a',)]) @parameterized.expand([ ('dict', {}, 'filter builders must be list of strings or a string'), ('list_int', [1], 'Value of filter builders must be string'), ]) def test_check_builders_keys_not_list(self, name, value, error): with self.assertRaisesConfigError(error): OldBuildCanceller.check_filters([(value, SourceStampFilter())])
def test_filter_is_matched_codebase(self): filter = SourceStampFilter(project_eq='p', codebase_eq='c', repository_eq='r', branch_eq='b') self.assertEqual(filter.is_matched_codebase('c'), True) self.assertEqual(filter.is_matched_codebase('0'), False)
def test_filter_repr(self): filter = SourceStampFilter(project_eq='p', codebase_eq='c', repository_eq='r', branch_eq='b', project_re='^p$', codebase_re='^c$', repository_re='^r$', branch_re='^b$', project_not_eq='p0', codebase_not_eq='c0', repository_not_eq='r0', branch_not_eq='b0', project_not_re='^p0$', codebase_not_re='^c0$', repository_not_re='^r0$', branch_not_re='^b0$') self.assertEqual( repr(filter), "<SourceStampFilter on project in ['p'] and project not in ['p0'] " + "and project matches [re.compile('^p$')] " + "and project does not match [re.compile('^p0$')] " + "and codebase in ['c'] and codebase not in ['c0'] " + "and codebase matches [re.compile('^c$')] " + "and codebase does not match [re.compile('^c0$')] " + "and repository in ['r'] and repository not in ['r0'] " + "and repository matches [re.compile('^r$')] " + "and repository does not match [re.compile('^r0$')] " + "and branch in ['b'] and branch not in ['b0'] " + "and branch matches [re.compile('^b$')] " + "and branch does not match [re.compile('^b0$')]>")
def test_cancel_buildrequests_matches_any_builder(self): self.canceller = FailingBuildsetCanceller('canceller', [ (['builder1'], None, SourceStampFilter(branch_eq=['branch1'])), ]) yield self.canceller.setServiceParent(self.master) yield self.send_build_finished(500, FAILURE) self.assert_cancelled([501, 502])
def test_cancel_buildrequests_not_failure(self): self.canceller = FailingBuildsetCanceller('canceller', [ (['builder1'], ['builder1', 'builder2', 'builder3' ], SourceStampFilter(branch_eq=['branch1'])), ]) yield self.canceller.setServiceParent(self.master) yield self.send_build_finished(500, SUCCESS) self.assert_cancelled([])
def test_cancel_buildrequests_ss_filter_does_not_match(self): self.canceller = FailingBuildsetCanceller('canceller', [ (['builder1'], ['builder1', 'builder2', 'builder3' ], SourceStampFilter(branch_eq=['branch_other'])), ]) yield self.canceller.setServiceParent(self.master) yield self.send_build_finished(500, FAILURE) self.assert_cancelled([])
def setUp(self): filter = _OldBuildFilterSet() ss_filter = SourceStampFilter(codebase_eq=['cb1', 'cb2'], repository_eq=['rp1', 'rp2'], branch_eq=['br1', 'br2']) filter.add_filter(['bldr1', 'bldr2'], ss_filter) self.cancellations = [] self.tracker = _OldBuildTracker(filter, self.on_cancel)
def test_filter_is_matched_not_eq_or_re(self, name, ss, expected): filter = SourceStampFilter(project_not_eq='p0', codebase_not_eq='c0', repository_not_eq='r0', branch_not_eq='b0') self.assertEqual(filter.is_matched(ss), expected) filter = SourceStampFilter(project_not_re='^p0$', codebase_not_re='^c0$', repository_not_re='^r0$', branch_not_re='^b0$') self.assertEqual(filter.is_matched(ss), expected) filter = SourceStampFilter(project_not_re=re.compile('^p0$'), codebase_not_re=re.compile('^c0$'), repository_not_re=re.compile('^r0$'), branch_not_re=re.compile('^b0$')) self.assertEqual(filter.is_matched(ss), expected)
def test_filter_is_matched_eq_or_re(self, name, ss, expected): filter = SourceStampFilter(project_eq='p', codebase_eq='c', repository_eq='r', branch_eq='b') self.assertEqual(filter.is_matched(ss), expected) filter = SourceStampFilter(project_re='^p$', codebase_re='^c$', repository_re='^r$', branch_re='^b$') self.assertEqual(filter.is_matched(ss), expected) filter = SourceStampFilter(project_re=re.compile('^p$'), codebase_re=re.compile('^c$'), repository_re=re.compile('^r$'), branch_re=re.compile('^b$')) self.assertEqual(filter.is_matched(ss), expected)
def test_multiple_filters_on_builder(self, name, builder, props, expected): filter = _OldBuildFilterSet() filter.add_filter(['builder1'], SourceStampFilter(project_eq='p')) filter.add_filter(['builder1'], SourceStampFilter(repository_eq='r')) self.assertEqual(filter.is_matched(builder, props), expected)
def setup_canceller_with_filters(self): self.canceller = OldBuildCanceller('canceller', [ (['builder1'], SourceStampFilter(branch_eq=['branch1'])), (['builder2'], SourceStampFilter(branch_eq=['branch2'])), ]) yield self.canceller.setServiceParent(self.master)
def test_check_builders_keys_not_list(self, name, value, error): with self.assertRaisesConfigError(error): OldBuildCanceller.check_filters([(value, SourceStampFilter())])