Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / chromite / scripts / cbuildbot_unittest.py
1 #!/usr/bin/python
2 # Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Unit tests for the cbuildbot program"""
7
8 from __future__ import print_function
9
10 import os
11 import sys
12
13 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(
14     os.path.abspath(__file__)))))
15
16 from chromite.cbuildbot import constants
17 from chromite.lib import cros_test_lib
18 from chromite.scripts import cbuildbot
19
20
21 class IsDistributedBuilderTest(cros_test_lib.TestCase):
22   """Test for cbuildbot._IsDistributedBuilder."""
23
24   # pylint: disable=W0212
25   def testIsDistributedBuilder(self):
26     """Tests for _IsDistributedBuilder() under various configurations."""
27     parser = cbuildbot._CreateParser()
28     argv = ['x86-generic-paladin']
29     (options, _) = cbuildbot._ParseCommandLine(parser, argv)
30     options.buildbot = False
31     options.pre_cq = False
32
33     build_config = dict(pre_cq=False,
34                         manifest_version=False)
35     chrome_rev = None
36
37     def _TestConfig(expected):
38       self.assertEquals(expected,
39                         cbuildbot._IsDistributedBuilder(
40                             options=options,
41                             chrome_rev=chrome_rev,
42                             build_config=build_config))
43
44     # Default options.
45     _TestConfig(False)
46
47     # In Pre-CQ mode, we run as as a distributed builder.
48     options.pre_cq = True
49     _TestConfig(True)
50
51     options.pre_cq = False
52     build_config['pre_cq'] = True
53     _TestConfig(True)
54
55     build_config['pre_cq'] = False
56     build_config['manifest_version'] = True
57     # Not running in buildbot mode even though manifest_version=True.
58     _TestConfig(False)
59     options.buildbot = True
60     _TestConfig(True)
61
62     for chrome_rev in (constants.CHROME_REV_TOT,
63                        constants.CHROME_REV_LOCAL,
64                        constants.CHROME_REV_SPEC):
65       _TestConfig(False)
66
67
68 if __name__ == '__main__':
69   cros_test_lib.main()