示例#1
0
 def setUp(self):
     self.job_foo = MockJobDefinition(name='foo')
     self.job_bar = MockJobDefinition(name='bar')
     self.obj = CheckBoxCommandMixIn(Mock(name="checkbox"))
示例#2
0
class MiscTests(TestCase):

    def setUp(self):
        self.job_foo = MockJobDefinition(name='foo')
        self.job_bar = MockJobDefinition(name='bar')
        self.obj = CheckBoxCommandMixIn(Mock(name="checkbox"))

    def test_matching_job_list(self):
        # Nothing gets selected automatically
        ns = Mock()
        ns.whitelist = None
        ns.include_pattern_list = []
        ns.exclude_pattern_list = []
        observed = self.obj._get_matching_job_list(ns, [
            self.job_foo, self.job_bar])
        self.assertEqual(observed, [])

    def test_matching_job_list_including(self):
        # Including jobs with glob pattern works
        ns = Mock()
        ns.whitelist = None
        ns.include_pattern_list = ['f.+']
        ns.exclude_pattern_list = []
        observed = self.obj._get_matching_job_list(ns, [
            self.job_foo, self.job_bar])
        self.assertEqual(observed, [self.job_foo])

    def test_matching_job_list_excluding(self):
        # Excluding jobs with glob pattern works
        ns = Mock()
        ns.whitelist = None
        ns.include_pattern_list = ['.+']
        ns.exclude_pattern_list = ['f.+']
        observed = self.obj._get_matching_job_list(ns, [
            self.job_foo, self.job_bar])
        self.assertEqual(observed, [self.job_bar])

    def test_matching_job_list_whitelist(self):
        # whitelists contain list of include patterns
        # that are read and interpreted as usual
        whitelist = Mock()
        whitelist.readlines.return_value = ['foo']
        ns = Mock()
        ns.whitelist = whitelist
        ns.include_pattern_list = []
        ns.exclude_pattern_list = []
        observed = self.obj._get_matching_job_list(ns, [
            self.job_foo, self.job_bar])
        self.assertEqual(observed, [self.job_foo])

    def test_no_prefix_matching_including(self):
        # Include patterns should only match whole job name
        ns = Mock()
        ns.whitelist = None
        ns.include_pattern_list = ['fo', 'ba.+']
        ns.exclude_pattern_list = []
        observed = self.obj._get_matching_job_list(ns, [self.job_foo,
                                                        self.job_bar])
        self.assertEqual(observed, [self.job_bar])

    def test_no_prefix_matching_excluding(self):
        # Exclude patterns should only match whole job name
        ns = Mock()
        ns.whitelist = None
        ns.include_pattern_list = ['.+']
        ns.exclude_pattern_list = ['fo', 'ba.+']
        observed = self.obj._get_matching_job_list(ns, [self.job_foo,
                                                        self.job_bar])
        self.assertEqual(observed, [self.job_foo])