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 ] | |
70 options, args = trychange.gen_parser(None).parse_args(cmd) | |
71 self.assertEquals([], args) | |
72 # pylint: disable=W0212 | |
73 values = trychange._ParseSendChangeOptions(options) | |
74 self.assertEquals( | |
75 [ | |
76 ('user', 'maruel'), | |
77 ('name', None), | |
78 ('email', 'maruel@chromium.org'), | |
79 ('bot', 'bot1:test1,test2'), | |
80 ('bot', 'bot2:test1,test2'), | |
Peter Mayo
2012/03/07 15:53:46
Eventually flagging this as ambiguous might be goo
M-A Ruel
2012/03/07 17:52:56
Good question. Not sure though about processing th
| |
81 ], | |
82 values) | |
83 | |
84 def test_flags_bad_combination(self): | |
85 cmd = [ | |
86 '--bot', 'bot1:test1', | |
87 '--testfilter', 'test2', | |
88 ] | |
89 options, args = trychange.gen_parser(None).parse_args(cmd) | |
90 self.assertEquals([], args) | |
91 try: | |
92 # pylint: disable=W0212 | |
93 trychange._ParseSendChangeOptions(options) | |
94 self.fail() | |
95 except ValueError: | |
96 pass | |
97 | |
98 | |
60 class SVNUnittest(TryChangeTestsBase): | 99 class SVNUnittest(TryChangeTestsBase): |
61 """trychange.SVN tests.""" | 100 """trychange.SVN tests.""" |
62 def testMembersChanged(self): | 101 def testMembersChanged(self): |
63 members = [ | 102 members = [ |
64 'AutomagicalSettings', 'CaptureStatus', 'GetCodeReviewSetting', | 103 'AutomagicalSettings', 'CaptureStatus', 'GetCodeReviewSetting', |
65 'ReadRootFile', 'GenerateDiff', 'GetFileNames', 'files', 'file_tuples', | 104 'ReadRootFile', 'GenerateDiff', 'GetFileNames', 'files', 'file_tuples', |
66 ] | 105 ] |
67 # If this test fails, you should add the relevant test. | 106 # If this test fails, you should add the relevant test. |
68 self.compareMembers(trychange.SVN, members) | 107 self.compareMembers(trychange.SVN, members) |
69 | 108 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') | 143 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') |
105 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') | 144 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') |
106 self.mox.ReplayAll() | 145 self.mox.ReplayAll() |
107 git = trychange.GIT(self.options, self.fake_root, self.options.files) | 146 git = trychange.GIT(self.options, self.fake_root, self.options.files) |
108 self.assertEqual(git.GetFileNames(), self.expected_files) | 147 self.assertEqual(git.GetFileNames(), self.expected_files) |
109 self.assertEqual(git.checkout_root, self.fake_root) | 148 self.assertEqual(git.checkout_root, self.fake_root) |
110 self.assertEqual(git.GenerateDiff(), 'A diff') | 149 self.assertEqual(git.GenerateDiff(), 'A diff') |
111 | 150 |
112 | 151 |
113 if __name__ == '__main__': | 152 if __name__ == '__main__': |
114 import unittest | |
115 unittest.main() | 153 unittest.main() |
OLD | NEW |