test_util_attributes.py (4341B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 6 import unittest 7 8 import pytest 9 from mozunit import main 10 11 from gecko_taskgraph.util.attributes import ( 12 match_run_on_projects, 13 match_run_on_repo_type, 14 release_level, 15 ) 16 17 18 class MatchRunOnProjects(unittest.TestCase): 19 def test_empty(self): 20 self.assertFalse(match_run_on_projects({"project": "birch"}, [])) 21 22 def test_all(self): 23 self.assertTrue(match_run_on_projects({"project": "birch"}, ["all"])) 24 self.assertTrue(match_run_on_projects({"project": "larch"}, ["all"])) 25 self.assertTrue(match_run_on_projects({"project": "autoland"}, ["all"])) 26 self.assertTrue(match_run_on_projects({"project": "mozilla-central"}, ["all"])) 27 self.assertTrue(match_run_on_projects({"project": "mozilla-beta"}, ["all"])) 28 self.assertTrue(match_run_on_projects({"project": "mozilla-release"}, ["all"])) 29 30 def test_release(self): 31 self.assertFalse(match_run_on_projects({"project": "birch"}, ["release"])) 32 self.assertTrue(match_run_on_projects({"project": "larch"}, ["release"])) 33 self.assertFalse(match_run_on_projects({"project": "autoland"}, ["release"])) 34 self.assertTrue( 35 match_run_on_projects({"project": "mozilla-central"}, ["release"]) 36 ) 37 self.assertTrue(match_run_on_projects({"project": "mozilla-beta"}, ["release"])) 38 self.assertTrue( 39 match_run_on_projects({"project": "mozilla-release"}, ["release"]) 40 ) 41 42 def test_integration(self): 43 self.assertFalse(match_run_on_projects({"project": "birch"}, ["integration"])) 44 self.assertFalse(match_run_on_projects({"project": "larch"}, ["integration"])) 45 self.assertTrue(match_run_on_projects({"project": "autoland"}, ["integration"])) 46 self.assertFalse( 47 match_run_on_projects({"project": "mozilla-central"}, ["integration"]) 48 ) 49 self.assertFalse( 50 match_run_on_projects({"project": "mozilla-beta"}, ["integration"]) 51 ) 52 self.assertFalse( 53 match_run_on_projects({"project": "mozilla-integration"}, ["integration"]) 54 ) 55 56 def test_combo(self): 57 self.assertTrue( 58 match_run_on_projects({"project": "birch"}, ["release", "birch", "maple"]) 59 ) 60 self.assertTrue( 61 match_run_on_projects({"project": "larch"}, ["release", "birch", "maple"]) 62 ) 63 self.assertTrue( 64 match_run_on_projects({"project": "maple"}, ["release", "birch", "maple"]) 65 ) 66 self.assertFalse( 67 match_run_on_projects( 68 {"project": "autoland"}, ["release", "birch", "maple"] 69 ) 70 ) 71 self.assertTrue( 72 match_run_on_projects( 73 {"project": "mozilla-central"}, ["release", "birch", "maple"] 74 ) 75 ) 76 self.assertTrue( 77 match_run_on_projects( 78 {"project": "mozilla-beta"}, ["release", "birch", "maple"] 79 ) 80 ) 81 self.assertTrue( 82 match_run_on_projects( 83 {"project": "mozilla-release"}, ["release", "birch", "maple"] 84 ) 85 ) 86 self.assertTrue(match_run_on_projects({"project": "birch"}, ["birch", "trunk"])) 87 88 89 @pytest.mark.parametrize( 90 "repo_type,run_on_repo_types,expected", 91 ( 92 ("hg", ["hg"], True), 93 ("hg", [], False), 94 ("hg", ["all"], True), 95 ("git", ["git", "hg"], True), 96 ("git", ["hg"], False), 97 ), 98 ) 99 def test_match_run_on_repo_type(repo_type, run_on_repo_types, expected): 100 assert match_run_on_repo_type(repo_type, run_on_repo_types) == expected 101 102 103 @pytest.mark.parametrize( 104 "params,expected", 105 ( 106 ({"project": "autoland"}, "staging"), 107 ({"project": "mozilla-central"}, "production"), 108 ({"project": "firefox", "head_ref": "refs/heads/test"}, "staging"), 109 ({"project": "firefox", "head_ref": "refs/tags/beta"}, "staging"), 110 ({"project": "firefox", "head_ref": "refs/heads/beta"}, "production"), 111 ), 112 ) 113 def test_release_level(params, expected): 114 assert release_level(params) == expected 115 116 117 if __name__ == "__main__": 118 main()