OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 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 revert.py.""" | 6 """Unit tests for revert.py.""" |
7 | 7 |
8 import os | |
9 import unittest | |
10 | |
11 # Local imports | |
12 import revert | 8 import revert |
13 import super_mox | 9 from super_mox import mox, SuperMoxTestBase |
14 from super_mox import mox | |
15 | 10 |
16 | 11 |
17 class RevertTestsBase(super_mox.SuperMoxTestBase): | 12 class RevertTestsBase(SuperMoxTestBase): |
18 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 13 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
19 def setUp(self): | 14 def setUp(self): |
20 super_mox.SuperMoxTestBase.setUp(self) | 15 SuperMoxTestBase.setUp(self) |
21 self.mox.StubOutWithMock(revert, 'gcl') | 16 self.mox.StubOutWithMock(revert, 'gcl') |
22 self.mox.StubOutWithMock(revert, 'gclient') | 17 self.mox.StubOutWithMock(revert, 'gclient') |
23 self.mox.StubOutWithMock(revert, 'gclient_scm') | 18 self.mox.StubOutWithMock(revert, 'gclient_scm') |
24 self.mox.StubOutWithMock(revert, 'os') | |
25 self.mox.StubOutWithMock(revert.os, 'path') | |
26 self.mox.StubOutWithMock(revert.sys, 'stdout') | |
27 | 19 |
28 # These functions are not tested. | 20 # These functions are not tested. |
29 self.mox.StubOutWithMock(revert, 'GetRepoBase') | 21 self.mox.StubOutWithMock(revert, 'GetRepoBase') |
30 self.mox.StubOutWithMock(revert, 'CaptureSVNLog') | 22 self.mox.StubOutWithMock(revert, 'CaptureSVNLog') |
31 | 23 |
32 | 24 |
33 class RevertUnittest(RevertTestsBase): | 25 class RevertUnittest(RevertTestsBase): |
34 """General revert.py tests.""" | 26 """General revert.py tests.""" |
35 def testMembersChanged(self): | 27 def testMembersChanged(self): |
36 members = [ | 28 members = [ |
37 'CaptureSVNLog', 'GetRepoBase', 'Main', 'ModifiedFile', 'NoBlameList', | 29 'CaptureSVNLog', 'GetRepoBase', 'Main', 'ModifiedFile', 'NoBlameList', |
38 'NoModifiedFile', 'OutsideOfCheckout', 'Revert', 'UniqueFast', | 30 'NoModifiedFile', 'OutsideOfCheckout', 'Revert', 'UniqueFast', |
39 'exceptions', 'gcl', 'gclient', 'gclient_scm', 'gclient_utils', | 31 'exceptions', 'gcl', 'gclient', 'gclient_scm', 'gclient_utils', |
40 'optparse', 'os', 'sys', 'xml' | 32 'optparse', 'os', 'sys', 'xml' |
41 ] | 33 ] |
42 # If this test fails, you should add the relevant test. | 34 # If this test fails, you should add the relevant test. |
43 self.compareMembers(revert, members) | 35 self.compareMembers(revert, members) |
44 | 36 |
45 | 37 |
46 class RevertMainUnittest(RevertTestsBase): | 38 class RevertMainUnittest(RevertTestsBase): |
47 def setUp(self): | 39 def setUp(self): |
48 RevertTestsBase.setUp(self) | 40 RevertTestsBase.setUp(self) |
49 self.mox.StubOutWithMock(revert, 'gcl') | 41 self.mox.StubOutWithMock(revert, 'gcl') |
50 self.mox.StubOutWithMock(revert, 'os') | |
51 self.mox.StubOutWithMock(revert.os, 'path') | |
52 self.mox.StubOutWithMock(revert, 'sys') | |
53 self.mox.StubOutWithMock(revert, 'Revert') | 42 self.mox.StubOutWithMock(revert, 'Revert') |
| 43 self.fake_root = '/revert/RevertMainUnittest/ShouldntExist' |
54 | 44 |
55 def testMain(self): | 45 def testMain(self): |
56 revert.gcl.GetInfoDir().AndReturn('foo') | 46 # OptParser calls revert.os.path.exists and is a pain when mocked. |
57 revert.os.path.exists('foo').AndReturn(True) | 47 self.UnMock(revert.os.path, 'exists') |
| 48 revert.gcl.GetInfoDir().AndReturn(self.fake_root) |
| 49 #revert.os.path.exists(self.fake_root).AndReturn(True) |
| 50 revert.os.mkdir(self.fake_root) |
| 51 revert.gcl.GetInfoDir().AndReturn(self.fake_root) |
58 revert.Revert([42, 23], True, True, False, 'bleh', ['foo@example.com'] | 52 revert.Revert([42, 23], True, True, False, 'bleh', ['foo@example.com'] |
59 ).AndReturn(31337) | 53 ).AndReturn(31337) |
60 self.mox.ReplayAll() | 54 self.mox.ReplayAll() |
61 | 55 |
62 self.assertEquals(revert.Main(['revert', '-c', '-f', '-n', '-m', 'bleh', | 56 self.assertEquals(revert.Main(['revert', '-c', '-f', '-n', '-m', 'bleh', |
63 '-r', 'foo@example.com', '42', '23']), | 57 '-r', 'foo@example.com', '42', '23']), |
64 31337) | 58 31337) |
65 | 59 |
66 | 60 |
67 class RevertRevertUnittest(RevertTestsBase): | 61 class RevertRevertUnittest(RevertTestsBase): |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 ] | 100 ] |
107 for line in outputs: | 101 for line in outputs: |
108 revert.sys.stdout.write(line) | 102 revert.sys.stdout.write(line) |
109 revert.sys.stdout.write('\n') | 103 revert.sys.stdout.write('\n') |
110 self.mox.ReplayAll() | 104 self.mox.ReplayAll() |
111 | 105 |
112 revert.Revert([42], True, True, False, 'bleh', ['foo@example.com']) | 106 revert.Revert([42], True, True, False, 'bleh', ['foo@example.com']) |
113 | 107 |
114 | 108 |
115 if __name__ == '__main__': | 109 if __name__ == '__main__': |
| 110 import unittest |
116 unittest.main() | 111 unittest.main() |
OLD | NEW |