Bug 1578824 - Land initial boilerplate for embedding RDM UI into the browser. r=mtigl...
[gecko.git] / taskcluster / taskgraph / test / test_util_attributes.py
blobae535fbc9b38eb254564a311fe55e7f332a30f4f
1 # -*- coding: utf-8 -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from __future__ import absolute_import, print_function, unicode_literals
9 import unittest
10 from taskgraph.util.attributes import (
11 attrmatch,
12 match_run_on_projects,
14 from mozunit import main
17 class Attrmatch(unittest.TestCase):
19 def test_trivial_match(self):
20 """Given no conditions, anything matches"""
21 self.assertTrue(attrmatch({}))
23 def test_missing_attribute(self):
24 """If a filtering attribute is not present, no match"""
25 self.assertFalse(attrmatch({}, someattr=10))
27 def test_literal_attribute(self):
28 """Literal attributes must match exactly"""
29 self.assertTrue(attrmatch({'att': 10}, att=10))
30 self.assertFalse(attrmatch({'att': 10}, att=20))
32 def test_set_attribute(self):
33 """Set attributes require set membership"""
34 self.assertTrue(attrmatch({'att': 10}, att=set([9, 10])))
35 self.assertFalse(attrmatch({'att': 10}, att=set([19, 20])))
37 def test_callable_attribute(self):
38 """Callable attributes are called and any False causes the match to fail"""
39 self.assertTrue(attrmatch({'att': 10}, att=lambda val: True))
40 self.assertFalse(attrmatch({'att': 10}, att=lambda val: False))
42 def even(val):
43 return val % 2 == 0
44 self.assertTrue(attrmatch({'att': 10}, att=even))
45 self.assertFalse(attrmatch({'att': 11}, att=even))
47 def test_all_matches_required(self):
48 """If only one attribute does not match, the result is False"""
49 self.assertFalse(attrmatch({'a': 1}, a=1, b=2, c=3))
50 self.assertFalse(attrmatch({'a': 1, 'b': 2}, a=1, b=2, c=3))
51 self.assertTrue(attrmatch({'a': 1, 'b': 2, 'c': 3}, a=1, b=2, c=3))
54 class MatchRunOnProjects(unittest.TestCase):
56 def test_empty(self):
57 self.assertFalse(match_run_on_projects('try', []))
59 def test_all(self):
60 self.assertTrue(match_run_on_projects('try', ['all']))
61 self.assertTrue(match_run_on_projects('larch', ['all']))
62 self.assertTrue(match_run_on_projects('autoland', ['all']))
63 self.assertTrue(match_run_on_projects('mozilla-inbound', ['all']))
64 self.assertTrue(match_run_on_projects('mozilla-central', ['all']))
65 self.assertTrue(match_run_on_projects('mozilla-beta', ['all']))
66 self.assertTrue(match_run_on_projects('mozilla-release', ['all']))
68 def test_release(self):
69 self.assertFalse(match_run_on_projects('try', ['release']))
70 self.assertFalse(match_run_on_projects('larch', ['release']))
71 self.assertFalse(match_run_on_projects('autoland', ['release']))
72 self.assertFalse(match_run_on_projects('mozilla-inbound', ['release']))
73 self.assertTrue(match_run_on_projects('mozilla-central', ['release']))
74 self.assertTrue(match_run_on_projects('mozilla-beta', ['release']))
75 self.assertTrue(match_run_on_projects('mozilla-release', ['release']))
77 def test_integration(self):
78 self.assertFalse(match_run_on_projects('try', ['integration']))
79 self.assertFalse(match_run_on_projects('larch', ['integration']))
80 self.assertTrue(match_run_on_projects('autoland', ['integration']))
81 self.assertTrue(match_run_on_projects('mozilla-inbound', ['integration']))
82 self.assertFalse(match_run_on_projects('mozilla-central', ['integration']))
83 self.assertFalse(match_run_on_projects('mozilla-beta', ['integration']))
84 self.assertFalse(match_run_on_projects('mozilla-integration', ['integration']))
86 def test_combo(self):
87 self.assertTrue(match_run_on_projects('try', ['release', 'try', 'maple']))
88 self.assertFalse(match_run_on_projects('larch', ['release', 'try', 'maple']))
89 self.assertTrue(match_run_on_projects('maple', ['release', 'try', 'maple']))
90 self.assertFalse(match_run_on_projects('autoland', ['release', 'try', 'maple']))
91 self.assertFalse(match_run_on_projects('mozilla-inbound', ['release', 'try', 'maple']))
92 self.assertTrue(match_run_on_projects('mozilla-central', ['release', 'try', 'maple']))
93 self.assertTrue(match_run_on_projects('mozilla-beta', ['release', 'try', 'maple']))
94 self.assertTrue(match_run_on_projects('mozilla-release', ['release', 'try', 'maple']))
97 if __name__ == '__main__':
98 main()