| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 sys | 9 import sys |
| 10 import unittest |
| 10 | 11 |
| 11 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 12 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 12 | 13 |
| 13 from testing_support.super_mox import SuperMoxTestBase | 14 from testing_support.super_mox import SuperMoxTestBase |
| 14 | 15 |
| 15 import subprocess2 | 16 import subprocess2 |
| 16 import trychange | 17 import trychange |
| 17 | 18 |
| 18 | 19 |
| 19 class TryChangeTestsBase(SuperMoxTestBase): | 20 class TryChangeTestsBase(SuperMoxTestBase): |
| (...skipping 22 matching lines...) Expand all Loading... |
| 42 | 43 |
| 43 | 44 |
| 44 class TryChangeUnittest(TryChangeTestsBase): | 45 class TryChangeUnittest(TryChangeTestsBase): |
| 45 """General trychange.py tests.""" | 46 """General trychange.py tests.""" |
| 46 def testMembersChanged(self): | 47 def testMembersChanged(self): |
| 47 members = [ | 48 members = [ |
| 48 'EPILOG', 'Escape', 'GIT', 'GuessVCS', 'GetMungedDiff', 'HELP_STRING', | 49 'EPILOG', 'Escape', 'GIT', 'GuessVCS', 'GetMungedDiff', 'HELP_STRING', |
| 49 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess', 'SCM', 'SVN', | 50 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess', 'SCM', 'SVN', |
| 50 'TryChange', 'USAGE', | 51 'TryChange', 'USAGE', |
| 51 'breakpad', 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils', | 52 'breakpad', 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils', |
| 52 'getpass', | 53 'getpass', 'gen_parser', |
| 53 'json', 'logging', 'optparse', 'os', 'posixpath', 're', 'scm', 'shutil', | 54 'json', 'logging', 'optparse', 'os', 'posixpath', 're', 'scm', 'shutil', |
| 54 'subprocess2', 'sys', 'tempfile', 'urllib', | 55 'subprocess2', 'sys', 'tempfile', 'urllib', |
| 55 ] | 56 ] |
| 56 # If this test fails, you should add the relevant test. | 57 # If this test fails, you should add the relevant test. |
| 57 self.compareMembers(trychange, members) | 58 self.compareMembers(trychange, members) |
| 58 | 59 |
| 59 | 60 |
| 61 class TryChangeSimpleTest(unittest.TestCase): |
| 62 # Doesn't require supermox to run. |
| 63 def test_flags(self): |
| 64 cmd = [ |
| 65 '--bot', 'bot1', |
| 66 '--testfilter', 'test1', |
| 67 '--bot', 'bot2', |
| 68 '--testfilter', 'test2', |
| 69 '--user', 'joe', |
| 70 '--email', 'joe@example.com', |
| 71 ] |
| 72 options, args = trychange.gen_parser(None).parse_args(cmd) |
| 73 self.assertEquals([], args) |
| 74 # pylint: disable=W0212 |
| 75 values = trychange._ParseSendChangeOptions(options) |
| 76 self.assertEquals( |
| 77 [ |
| 78 ('user', 'joe'), |
| 79 ('name', None), |
| 80 ('email', 'joe@example.com'), |
| 81 ('bot', 'bot1:test1,test2'), |
| 82 ('bot', 'bot2:test1,test2'), |
| 83 ], |
| 84 values) |
| 85 |
| 86 def test_flags_bad_combination(self): |
| 87 cmd = [ |
| 88 '--bot', 'bot1:test1', |
| 89 '--testfilter', 'test2', |
| 90 ] |
| 91 options, args = trychange.gen_parser(None).parse_args(cmd) |
| 92 self.assertEquals([], args) |
| 93 try: |
| 94 # pylint: disable=W0212 |
| 95 trychange._ParseSendChangeOptions(options) |
| 96 self.fail() |
| 97 except ValueError: |
| 98 pass |
| 99 |
| 100 |
| 60 class SVNUnittest(TryChangeTestsBase): | 101 class SVNUnittest(TryChangeTestsBase): |
| 61 """trychange.SVN tests.""" | 102 """trychange.SVN tests.""" |
| 62 def testMembersChanged(self): | 103 def testMembersChanged(self): |
| 63 members = [ | 104 members = [ |
| 64 'AutomagicalSettings', 'CaptureStatus', 'GetCodeReviewSetting', | 105 'AutomagicalSettings', 'CaptureStatus', 'GetCodeReviewSetting', |
| 65 'ReadRootFile', 'GenerateDiff', 'GetFileNames', 'files', 'file_tuples', | 106 'ReadRootFile', 'GenerateDiff', 'GetFileNames', 'files', 'file_tuples', |
| 66 ] | 107 ] |
| 67 # If this test fails, you should add the relevant test. | 108 # If this test fails, you should add the relevant test. |
| 68 self.compareMembers(trychange.SVN, members) | 109 self.compareMembers(trychange.SVN, members) |
| 69 | 110 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') | 145 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') |
| 105 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') | 146 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') |
| 106 self.mox.ReplayAll() | 147 self.mox.ReplayAll() |
| 107 git = trychange.GIT(self.options, self.fake_root, self.options.files) | 148 git = trychange.GIT(self.options, self.fake_root, self.options.files) |
| 108 self.assertEqual(git.GetFileNames(), self.expected_files) | 149 self.assertEqual(git.GetFileNames(), self.expected_files) |
| 109 self.assertEqual(git.checkout_root, self.fake_root) | 150 self.assertEqual(git.checkout_root, self.fake_root) |
| 110 self.assertEqual(git.GenerateDiff(), 'A diff') | 151 self.assertEqual(git.GenerateDiff(), 'A diff') |
| 111 | 152 |
| 112 | 153 |
| 113 if __name__ == '__main__': | 154 if __name__ == '__main__': |
| 114 import unittest | |
| 115 unittest.main() | 155 unittest.main() |
| OLD | NEW |