Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / chromite / cbuildbot / repository_unittest.py
1 #!/usr/bin/python
2 # Copyright (c) 2012 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 """Unittests for repository.py."""
7
8 from __future__ import print_function
9
10 import functools
11 import os
12 import sys
13
14 import constants
15 sys.path.insert(0, constants.SOURCE_ROOT)
16 from chromite.cbuildbot import repository
17 from chromite.lib import cros_build_lib
18 from chromite.lib import cros_test_lib
19
20 # pylint: disable=W0212,R0904,E1101,W0613
21 class RepositoryTests(cros_test_lib.MoxTestCase):
22   """Test cases related to repository checkout methods."""
23
24   def RunCommand_Mock(self, result, *args, **kwargs):
25     output = self.mox.CreateMockAnything()
26     output.output = result
27     return output
28
29   def testExternalRepoCheckout(self):
30     """Test we detect external checkouts properly."""
31     self.mox.StubOutWithMock(cros_build_lib, 'RunCommand')
32     tests = [
33         'https://chromium.googlesource.com/chromiumos/manifest.git',
34         'test@abcdef.bla.com:39291/bla/manifest.git',
35         'test@abcdef.bla.com:39291/bla/manifest',
36         'test@abcdef.bla.com:39291/bla/Manifest-internal',
37      ]
38
39     for test in tests:
40       cros_build_lib.RunCommand = functools.partial(self.RunCommand_Mock, test)
41       self.assertFalse(repository.IsInternalRepoCheckout('.'))
42
43   def testInternalRepoCheckout(self):
44     """Test we detect internal checkouts properly."""
45     self.mox.StubOutWithMock(cros_build_lib, 'RunCommand')
46     tests = [
47         'https://chrome-internal.googlesource.com/chromeos/manifest-internal',
48         'test@abcdef.bla.com:39291/bla/manifest-internal.git',
49     ]
50
51     for test in tests:
52       cros_build_lib.RunCommand = functools.partial(self.RunCommand_Mock, test)
53       self.assertTrue(repository.IsInternalRepoCheckout('.'))
54
55
56 class RepoInitTests(cros_test_lib.MoxTempDirTestCase):
57   """Test cases related to repository initialization."""
58
59   def _Initialize(self, branch='master'):
60     repo = repository.RepoRepository(constants.MANIFEST_URL, self.tempdir,
61                                      branch=branch)
62     repo.Initialize()
63
64   def testReInitialization(self):
65     """Test ability to switch between branches."""
66     self._Initialize('release-R19-2046.B')
67     self._Initialize('master')
68
69     # Test that a failed re-init due to bad branch doesn't leave repo in bad
70     # state.
71     self.assertRaises(Exception, self._Initialize, 'monkey')
72     self._Initialize('release-R20-2268.B')
73
74
75 class RepoInitChromeBotTests(RepoInitTests):
76   """Test that Re-init works with the chrome-bot account.
77
78   In testing, repo init behavior on the buildbots is different from a
79   local run, because there is some logic in 'repo' that filters changes based on
80   GIT_COMMITTER_IDENT.  So for sanity's sake, try to emulate running on the
81   buildbots.
82   """
83   def setUp(self):
84     os.putenv('GIT_COMMITTER_EMAIL', 'chrome-bot@chromium.org')
85     os.putenv('GIT_AUTHOR_EMAIL', 'chrome-bot@chromium.org')
86
87
88 if __name__ == '__main__':
89   cros_test_lib.main()