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.
6 """Unittests for repository.py."""
8 from __future__ import print_function
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
20 # pylint: disable=W0212,R0904,E1101,W0613
21 class RepositoryTests(cros_test_lib.MoxTestCase):
22 """Test cases related to repository checkout methods."""
24 def RunCommand_Mock(self, result, *args, **kwargs):
25 output = self.mox.CreateMockAnything()
26 output.output = result
29 def testExternalRepoCheckout(self):
30 """Test we detect external checkouts properly."""
31 self.mox.StubOutWithMock(cros_build_lib, 'RunCommand')
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',
40 cros_build_lib.RunCommand = functools.partial(self.RunCommand_Mock, test)
41 self.assertFalse(repository.IsInternalRepoCheckout('.'))
43 def testInternalRepoCheckout(self):
44 """Test we detect internal checkouts properly."""
45 self.mox.StubOutWithMock(cros_build_lib, 'RunCommand')
47 'https://chrome-internal.googlesource.com/chromeos/manifest-internal',
48 'test@abcdef.bla.com:39291/bla/manifest-internal.git',
52 cros_build_lib.RunCommand = functools.partial(self.RunCommand_Mock, test)
53 self.assertTrue(repository.IsInternalRepoCheckout('.'))
56 class RepoInitTests(cros_test_lib.MoxTempDirTestCase):
57 """Test cases related to repository initialization."""
59 def _Initialize(self, branch='master'):
60 repo = repository.RepoRepository(constants.MANIFEST_URL, self.tempdir,
64 def testReInitialization(self):
65 """Test ability to switch between branches."""
66 self._Initialize('release-R19-2046.B')
67 self._Initialize('master')
69 # Test that a failed re-init due to bad branch doesn't leave repo in bad
71 self.assertRaises(Exception, self._Initialize, 'monkey')
72 self._Initialize('release-R20-2268.B')
75 class RepoInitChromeBotTests(RepoInitTests):
76 """Test that Re-init works with the chrome-bot account.
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
84 os.putenv('GIT_COMMITTER_EMAIL', 'chrome-bot@chromium.org')
85 os.putenv('GIT_AUTHOR_EMAIL', 'chrome-bot@chromium.org')
88 if __name__ == '__main__':