| 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 trychange.py.""" | 6 """Unit tests for trychange.py.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| 11 # Local imports | 11 # Local imports |
| 12 import super_mox |
| 12 import trychange | 13 import trychange |
| 14 from super_mox import mox |
| 13 | 15 |
| 14 | 16 |
| 15 class TryChangeTestsBase(unittest.TestCase): | 17 class TryChangeTestsBase(super_mox.SuperMoxTestBase): |
| 16 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 18 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
| 17 def setUp(self): | 19 pass |
| 18 pass | |
| 19 | |
| 20 def tearDown(self): | |
| 21 pass | |
| 22 | |
| 23 def compareMembers(self, object, members): | |
| 24 """If you add a member, be sure to add the relevant test!""" | |
| 25 # Skip over members starting with '_' since they are usually not meant to | |
| 26 # be for public use. | |
| 27 actual_members = [x for x in sorted(dir(object)) | |
| 28 if not x.startswith('_')] | |
| 29 expected_members = sorted(members) | |
| 30 if actual_members != expected_members: | |
| 31 diff = ([i for i in actual_members if i not in expected_members] + | |
| 32 [i for i in expected_members if i not in actual_members]) | |
| 33 print diff | |
| 34 self.assertEqual(actual_members, expected_members) | |
| 35 | 20 |
| 36 | 21 |
| 37 class TryChangeUnittest(TryChangeTestsBase): | 22 class TryChangeUnittest(TryChangeTestsBase): |
| 38 """General trychange.py tests.""" | 23 """General trychange.py tests.""" |
| 39 def testMembersChanged(self): | 24 def testMembersChanged(self): |
| 40 members = [ | 25 members = [ |
| 41 'EscapeDot', 'ExecuteTryServerScript', 'GIT', 'GetSourceRoot', 'GuessVCS', | 26 'EscapeDot', 'ExecuteTryServerScript', 'GIT', 'GetSourceRoot', 'GuessVCS', |
| 42 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PathDifference', | 27 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PathDifference', |
| 43 'RunCommand', 'SCM', 'SCRIPT_PATH', 'SVN', 'TryChange', 'USAGE', | 28 'RunCommand', 'SCM', 'SCRIPT_PATH', 'SVN', 'TryChange', 'USAGE', |
| 44 'datetime', 'gcl', 'gclient', 'getpass', 'logging', 'optparse', 'os', | 29 'datetime', 'gcl', 'gclient', 'getpass', 'logging', 'optparse', 'os', |
| (...skipping 18 matching lines...) Expand all Loading... |
| 63 def testMembersChanged(self): | 48 def testMembersChanged(self): |
| 64 members = [ | 49 members = [ |
| 65 'GenerateDiff', 'GetEmail', 'GetPatchName', 'ProcessOptions', 'options' | 50 'GenerateDiff', 'GetEmail', 'GetPatchName', 'ProcessOptions', 'options' |
| 66 ] | 51 ] |
| 67 # If this test fails, you should add the relevant test. | 52 # If this test fails, you should add the relevant test. |
| 68 self.compareMembers(trychange.GIT(None), members) | 53 self.compareMembers(trychange.GIT(None), members) |
| 69 | 54 |
| 70 | 55 |
| 71 if __name__ == '__main__': | 56 if __name__ == '__main__': |
| 72 unittest.main() | 57 unittest.main() |
| OLD | NEW |