OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Unit tests for trychange.py.""" | 6 """Unit tests for trychange.py.""" |
7 | 7 |
8 # Fixes include path. | 8 # Fixes include path. |
9 from super_mox import mox, SuperMoxTestBase | 9 from super_mox import mox, SuperMoxTestBase |
10 | 10 |
11 import trychange | 11 import trychange |
12 | 12 |
13 | 13 |
14 class TryChangeTestsBase(SuperMoxTestBase): | 14 class TryChangeTestsBase(SuperMoxTestBase): |
15 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 15 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
16 def setUp(self): | 16 def setUp(self): |
17 SuperMoxTestBase.setUp(self) | 17 SuperMoxTestBase.setUp(self) |
18 self.mox.StubOutWithMock(trychange.gclient_utils, 'CheckCall') | 18 self.mox.StubOutWithMock(trychange.gclient_utils, 'CheckCall') |
19 self.mox.StubOutWithMock(trychange.scm.GIT, 'Capture') | 19 self.mox.StubOutWithMock(trychange.scm.GIT, 'Capture') |
20 self.mox.StubOutWithMock(trychange.scm.GIT, 'GenerateDiff') | 20 self.mox.StubOutWithMock(trychange.scm.GIT, 'GenerateDiff') |
21 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetCheckoutRoot') | 21 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetCheckoutRoot') |
| 22 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetEmail') |
22 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetPatchName') | 23 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetPatchName') |
23 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetEmail') | 24 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetUpstreamBranch') |
24 self.mox.StubOutWithMock(trychange.scm.SVN, 'DiffItem') | 25 self.mox.StubOutWithMock(trychange.scm.SVN, 'DiffItem') |
25 self.mox.StubOutWithMock(trychange.scm.SVN, 'GenerateDiff') | 26 self.mox.StubOutWithMock(trychange.scm.SVN, 'GenerateDiff') |
26 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetCheckoutRoot') | 27 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetCheckoutRoot') |
27 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetEmail') | 28 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetEmail') |
28 self.fake_root = self.Dir() | 29 self.fake_root = self.Dir() |
29 self.expected_files = ['foo.txt', 'bar.txt'] | 30 self.expected_files = ['foo.txt', 'bar.txt'] |
30 self.options = trychange.optparse.Values() | 31 self.options = trychange.optparse.Values() |
31 self.options.files = self.expected_files | 32 self.options.files = self.expected_files |
32 self.options.diff = None | 33 self.options.diff = None |
33 self.options.name = None | 34 self.options.name = None |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 members = [ | 82 members = [ |
82 'AutomagicalSettings', 'GclStyleSettings', 'GclientStyleSettings', | 83 'AutomagicalSettings', 'GclStyleSettings', 'GclientStyleSettings', |
83 'GetCodeReviewSetting', 'ReadRootFile', | 84 'GetCodeReviewSetting', 'ReadRootFile', |
84 'GenerateDiff', 'GetFileNames', | 85 'GenerateDiff', 'GetFileNames', |
85 ] | 86 ] |
86 # If this test fails, you should add the relevant test. | 87 # If this test fails, you should add the relevant test. |
87 self.compareMembers(trychange.GIT, members) | 88 self.compareMembers(trychange.GIT, members) |
88 | 89 |
89 def testBasic(self): | 90 def testBasic(self): |
90 trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root) | 91 trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root) |
| 92 trychange.scm.GIT.GetUpstreamBranch(self.fake_root).AndReturn('somewhere') |
91 trychange.scm.GIT.GenerateDiff(self.fake_root, | 93 trychange.scm.GIT.GenerateDiff(self.fake_root, |
92 full_move=True, | 94 full_move=True, |
93 files=['foo.txt', 'bar.txt'], | 95 files=['foo.txt', 'bar.txt'], |
94 branch=None).AndReturn('A diff') | 96 branch='somewhere').AndReturn('A diff') |
95 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') | 97 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') |
96 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') | 98 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') |
97 self.mox.ReplayAll() | 99 self.mox.ReplayAll() |
98 git = trychange.GIT(self.options, self.fake_root) | 100 git = trychange.GIT(self.options, self.fake_root) |
99 self.assertEqual(git.GetFileNames(), self.expected_files) | 101 self.assertEqual(git.GetFileNames(), self.expected_files) |
100 self.assertEqual(git.checkout_root, self.fake_root) | 102 self.assertEqual(git.checkout_root, self.fake_root) |
101 self.assertEqual(git.GenerateDiff(), 'A diff') | 103 self.assertEqual(git.GenerateDiff(), 'A diff') |
102 | 104 |
103 | 105 |
104 if __name__ == '__main__': | 106 if __name__ == '__main__': |
105 import unittest | 107 import unittest |
106 unittest.main() | 108 unittest.main() |
OLD | NEW |