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 5import buildconfig 6import mozunit 7 8from unittest import TestCase 9 10from mozbuild.artifacts import ArtifactJob, ThunderbirdMixin 11 12 13class FakeArtifactJob(ArtifactJob): 14 package_re = r"" 15 16 17class TestArtifactJob(TestCase): 18 def _assert_candidate_trees(self, version_display, expected_trees): 19 buildconfig.substs["MOZ_APP_VERSION_DISPLAY"] = version_display 20 21 job = FakeArtifactJob() 22 self.assertGreater(len(job.candidate_trees), 0) 23 self.assertEqual(job.candidate_trees, expected_trees) 24 25 def test_candidate_trees_with_empty_file(self): 26 self._assert_candidate_trees( 27 version_display="", expected_trees=ArtifactJob.default_candidate_trees 28 ) 29 30 def test_candidate_trees_with_beta_version(self): 31 self._assert_candidate_trees( 32 version_display="92.1b2", expected_trees=ArtifactJob.beta_candidate_trees 33 ) 34 35 def test_candidate_trees_with_esr_version(self): 36 self._assert_candidate_trees( 37 version_display="91.3.0esr", expected_trees=ArtifactJob.esr_candidate_trees 38 ) 39 40 def test_candidate_trees_with_nightly_version(self): 41 self._assert_candidate_trees( 42 version_display="95.0a1", expected_trees=ArtifactJob.nightly_candidate_trees 43 ) 44 45 def test_candidate_trees_with_release_version(self): 46 self._assert_candidate_trees( 47 version_display="93.0.1", expected_trees=ArtifactJob.default_candidate_trees 48 ) 49 50 def test_candidate_trees_with_newline_before_version(self): 51 self._assert_candidate_trees( 52 version_display="\n\n91.3.0esr", 53 expected_trees=ArtifactJob.esr_candidate_trees, 54 ) 55 56 def test_property_is_cached(self): 57 job = FakeArtifactJob() 58 expected_trees = ArtifactJob.esr_candidate_trees 59 60 buildconfig.substs["MOZ_APP_VERSION_DISPLAY"] = "91.3.0.esr" 61 self.assertEqual(job.candidate_trees, expected_trees) 62 # Because the property is cached, changing the 63 # `MOZ_APP_VERSION_DISPLAY` won't have any impact. 64 buildconfig.substs["MOZ_APP_VERSION_DISPLAY"] = "" 65 self.assertEqual(job.candidate_trees, expected_trees) 66 67 68class FakeThunderbirdJob(ThunderbirdMixin, FakeArtifactJob): 69 pass 70 71 72class TestThunderbirdMixin(TestCase): 73 def _assert_candidate_trees(self, version_display, expected_trees): 74 buildconfig.substs["MOZ_APP_VERSION_DISPLAY"] = version_display 75 76 job = FakeThunderbirdJob() 77 self.assertGreater(len(job.candidate_trees), 0) 78 self.assertEqual(job.candidate_trees, expected_trees) 79 80 def test_candidate_trees_with_beta_version(self): 81 self._assert_candidate_trees( 82 version_display="92.1b2", 83 expected_trees=ThunderbirdMixin.beta_candidate_trees, 84 ) 85 86 def test_candidate_trees_with_esr_version(self): 87 self._assert_candidate_trees( 88 version_display="91.3.0esr", 89 expected_trees=ThunderbirdMixin.esr_candidate_trees, 90 ) 91 92 def test_candidate_trees_with_nightly_version(self): 93 self._assert_candidate_trees( 94 version_display="95.0a1", 95 expected_trees=ThunderbirdMixin.nightly_candidate_trees, 96 ) 97 98 def test_property_is_cached(self): 99 job = FakeThunderbirdJob() 100 expected_trees = ThunderbirdMixin.esr_candidate_trees 101 102 buildconfig.substs["MOZ_APP_VERSION_DISPLAY"] = "91.3.0.esr" 103 self.assertEqual(job.candidate_trees, expected_trees) 104 # Because the property is cached, changing the 105 # `MOZ_APP_VERSION_DISPLAY` won't have any impact. 106 buildconfig.substs["MOZ_APP_VERSION_DISPLAY"] = "" 107 self.assertEqual(job.candidate_trees, expected_trees) 108 109 110if __name__ == "__main__": 111 mozunit.main() 112