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 gcl.py.""" | 6 """Unit tests for gcl.py.""" |
7 | 7 |
8 import unittest | 8 import unittest |
9 | 9 |
10 # Local imports | 10 # Local imports |
11 import __init__ | |
12 import gcl | 11 import gcl |
13 mox = __init__.mox | 12 import super_mox |
| 13 from super_mox import mox |
14 | 14 |
15 | 15 |
16 class GclTestsBase(mox.MoxTestBase): | 16 class GclTestsBase(super_mox.SuperMoxTestBase): |
17 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 17 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
18 def setUp(self): | 18 def setUp(self): |
19 mox.MoxTestBase.setUp(self) | 19 super_mox.SuperMoxTestBase.setUp(self) |
20 self.mox.StubOutWithMock(gcl, 'RunShell') | 20 self.mox.StubOutWithMock(gcl, 'RunShell') |
21 self.mox.StubOutWithMock(gcl.gclient, 'CaptureSVNInfo') | 21 self.mox.StubOutWithMock(gcl.gclient, 'CaptureSVNInfo') |
22 self.mox.StubOutWithMock(gcl, 'os') | 22 self.mox.StubOutWithMock(gcl, 'os') |
23 self.mox.StubOutWithMock(gcl.os, 'getcwd') | 23 self.mox.StubOutWithMock(gcl.os, 'getcwd') |
24 | 24 |
25 def compareMembers(self, object, members): | |
26 """If you add a member, be sure to add the relevant test!""" | |
27 # Skip over members starting with '_' since they are usually not meant to | |
28 # be for public use. | |
29 actual_members = [x for x in sorted(dir(object)) | |
30 if not x.startswith('_')] | |
31 expected_members = sorted(members) | |
32 if actual_members != expected_members: | |
33 diff = ([i for i in actual_members if i not in expected_members] + | |
34 [i for i in expected_members if i not in actual_members]) | |
35 print diff | |
36 self.assertEqual(actual_members, expected_members) | |
37 | |
38 | 25 |
39 class GclUnittest(GclTestsBase): | 26 class GclUnittest(GclTestsBase): |
40 """General gcl.py tests.""" | 27 """General gcl.py tests.""" |
41 def testMembersChanged(self): | 28 def testMembersChanged(self): |
42 members = [ | 29 members = [ |
43 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS', | 30 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS', |
44 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks', | 31 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks', |
45 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenerateChangeName', | 32 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenerateChangeName', |
46 'GenerateDiff', | 33 'GenerateDiff', |
47 'GetCacheDir', 'GetCachedFile', 'GetChangesDir', 'GetCLs', | 34 'GetCacheDir', 'GetCachedFile', 'GetChangesDir', 'GetCLs', |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 gcl.os.chdir('somewhere') | 259 gcl.os.chdir('somewhere') |
273 self.mox.ReplayAll() | 260 self.mox.ReplayAll() |
274 | 261 |
275 gcl.UploadCL(change_info, args) | 262 gcl.UploadCL(change_info, args) |
276 self.assertEquals(change_info.issue, 1) | 263 self.assertEquals(change_info.issue, 1) |
277 self.assertEquals(change_info.patchset, 2) | 264 self.assertEquals(change_info.patchset, 2) |
278 | 265 |
279 | 266 |
280 if __name__ == '__main__': | 267 if __name__ == '__main__': |
281 unittest.main() | 268 unittest.main() |
OLD | NEW |