Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: tests/revert_unittest.py

Issue 556092: Remove stale revert.py unit test and fix another test I broke in r37487. (Closed)
Patch Set: Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/presubmit_unittest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
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
4 # found in the LICENSE file.
5
6 """Unit tests for revert.py."""
7
8 import revert
9 from super_mox import mox, SuperMoxTestBase
10
11
12 class RevertTestsBase(SuperMoxTestBase):
13 """Setups and tear downs the mocks but doesn't test anything as-is."""
14 def setUp(self):
15 SuperMoxTestBase.setUp(self)
16 self.mox.StubOutWithMock(revert, 'gcl')
17 self.mox.StubOutWithMock(revert, 'gclient')
18 self.mox.StubOutWithMock(revert, 'gclient_scm')
19
20 # These functions are not tested.
21 self.mox.StubOutWithMock(revert, 'GetRepoBase')
22 self.mox.StubOutWithMock(revert, 'CaptureSVNLog')
23
24
25 class RevertUnittest(RevertTestsBase):
26 """General revert.py tests."""
27 def testMembersChanged(self):
28 members = [
29 'CaptureSVNLog', 'GetRepoBase', 'Main', 'ModifiedFile', 'NoBlameList',
30 'NoModifiedFile', 'OutsideOfCheckout', 'Revert', 'UniqueFast',
31 'exceptions', 'gcl', 'gclient', 'gclient_scm', 'gclient_utils',
32 'optparse', 'os', 'sys', 'xml'
33 ]
34 # If this test fails, you should add the relevant test.
35 self.compareMembers(revert, members)
36
37
38 class RevertMainUnittest(RevertTestsBase):
39 def setUp(self):
40 RevertTestsBase.setUp(self)
41 self.mox.StubOutWithMock(revert, 'gcl')
42 self.mox.StubOutWithMock(revert, 'Revert')
43 self.fake_root = '/revert/RevertMainUnittest/ShouldntExist'
44
45 def testMain(self):
46 # OptParser calls revert.os.path.exists and is a pain when mocked.
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)
52 revert.Revert([42, 23], True, True, False, 'bleh', ['foo@example.com']
53 ).AndReturn(31337)
54 self.mox.ReplayAll()
55
56 self.assertEquals(revert.Main(['revert', '-c', '-f', '-n', '-m', 'bleh',
57 '-r', 'foo@example.com', '42', '23']),
58 31337)
59
60
61 class RevertRevertUnittest(RevertTestsBase):
62 def setUp(self):
63 RevertTestsBase.setUp(self)
64 self.mox.StubOutWithMock(revert.gclient_scm.scm.SVN, 'CaptureStatus')
65
66 def testRevert(self):
67 revert.gcl.GetRepositoryRoot().AndReturn('foo')
68 revert.os.chdir('foo')
69 entries = [{
70 'author': 'Georges',
71 'paths': [
72 {'path': 'proto://fqdn/repo/random_file'}
73 ],
74 }]
75 revert.CaptureSVNLog(['-r', '42', '-v']).AndReturn(entries)
76 revert.GetRepoBase().AndReturn('proto://fqdn/repo/')
77 revert.gclient_scm.scm.SVN.CaptureStatus(['random_file']).AndReturn([])
78 revert.gcl.RunShell(['svn', 'up', 'random_file'])
79 revert.os.path.isdir('random_file').AndReturn(False)
80 status = """--- Reverse-merging r42 into '.':
81 M random_file
82 """
83 revert.gcl.RunShellWithReturnCode(['svn', 'merge', '-c', '-42',
84 'random_file'],
85 print_output=True).AndReturn([status, 0])
86 change = self.mox.CreateMockAnything()
87 revert.gcl.ChangeInfo('revert42', 0, 0, 'Reverting 42.\n\nbleh',
88 [('M ', 'random_file')], 'foo').AndReturn(change)
89 change.Save()
90 revert.gcl.UploadCL(change,
91 ['--no_presubmit', '-r', 'foo@example.com', '--no_try'])
92 revert.gcl.Commit(change, ['--no_presubmit', '--force'])
93 revert.gclient.Main(['gclient.py', 'sync'])
94 outputs = [
95 'Blaming Georges\n',
96 'Emailing foo@example.com\n',
97 'These files were modified in 42:',
98 'random_file',
99 '',
100 'Reverting 42 in ./'
101 ]
102 for line in outputs:
103 revert.sys.stdout.write(line)
104 revert.sys.stdout.write('\n')
105 self.mox.ReplayAll()
106
107 revert.Revert([42], True, True, False, 'bleh', ['foo@example.com'])
108
109
110 if __name__ == '__main__':
111 import unittest
112 unittest.main()
OLDNEW
« no previous file with comments | « tests/presubmit_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698