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

Side by Side Diff: tests/trychange_unittest.py

Issue 54373011: Rework bot and test parsing to allow receipt of (bot, set(test)) specifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Final changes. Created 7 years, 1 month 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 | « presubmit_support.py ('k') | trychange.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 import unittest
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 class TryChangeUnittest(TryChangeTestsBase): 45 class TryChangeUnittest(TryChangeTestsBase):
46 """General trychange.py tests.""" 46 """General trychange.py tests."""
47 def testMembersChanged(self): 47 def testMembersChanged(self):
48 members = [ 48 members = [
49 'DieWithError', 'EPILOG', 'Escape', 'GIT', 'GetMungedDiff', 'GuessVCS', 49 'DieWithError', 'EPILOG', 'Escape', 'GIT', 'GetMungedDiff', 'GuessVCS',
50 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'OptionParser', 50 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'OptionParser',
51 'PrintSuccess', 51 'PrintSuccess',
52 'RunCommand', 'RunGit', 'SCM', 'SVN', 'TryChange', 'USAGE', 'breakpad', 52 'RunCommand', 'RunGit', 'SCM', 'SVN', 'TryChange', 'USAGE', 'breakpad',
53 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils', 'gen_parser', 53 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils', 'gen_parser',
54 'getpass', 'json', 'logging', 'optparse', 'os', 'posixpath', 're', 'scm', 54 'getpass', 'itertools', 'json', 'logging', 'optparse', 'os', 'posixpath',
55 'shutil', 'subprocess2', 'sys', 'tempfile', 'urllib'] 55 're', 'scm', 'shutil', 'subprocess2', 'sys', 'tempfile', 'urllib']
56 # If this test fails, you should add the relevant test. 56 # If this test fails, you should add the relevant test.
57 self.compareMembers(trychange, members) 57 self.compareMembers(trychange, members)
58 58
59 59
60 class TryChangeSimpleTest(unittest.TestCase): 60 class TryChangeSimpleTest(unittest.TestCase):
61 # Doesn't require supermox to run. 61 # Doesn't require supermox to run.
62 def test_flags(self): 62 def test_flags(self):
63 cmd = [ 63 cmd = [
64 '--bot', 'bot1,bot2', 64 '--bot', 'bot1,bot2',
65 '--testfilter', 'test1', 65 '--testfilter', 'test1',
66 '--testfilter', 'test2', 66 '--testfilter', 'test2',
67 '--user', 'joe', 67 '--user', 'joe',
68 '--email', 'joe@example.com', 68 '--email', 'joe@example.com',
69 ] 69 ]
70 options, args = trychange.gen_parser(None).parse_args(cmd) 70 options, args = trychange.gen_parser(None).parse_args(cmd)
71 self.assertEquals([], args) 71 self.assertEquals([], args)
72 # pylint: disable=W0212 72 # pylint: disable=W0212
73 values = trychange._ParseSendChangeOptions(options) 73 bot_spec = trychange._ParseBotList(options.bot, options.testfilter)
74 if options.testfilter:
75 bot_spec = trychange._ApplyTestFilter(options.testfilter, bot_spec)
76 values = trychange._ParseSendChangeOptions(bot_spec, options)
74 self.assertEquals( 77 self.assertEquals(
75 [ 78 [
76 ('user', 'joe'), 79 ('user', 'joe'),
77 ('name', None), 80 ('name', None),
78 ('email', 'joe@example.com'), 81 ('email', 'joe@example.com'),
79 ('bot', 'bot1:test1,test2'), 82 ('bot', 'bot1:test1,test2'),
80 ('bot', 'bot2:test1,test2'), 83 ('bot', 'bot2:test1,test2'),
81 ], 84 ],
82 values) 85 values)
83 86
84 def test_flags_bad_combination(self): 87 def test_flags_bad_combination(self):
85 cmd = [ 88 cmd = [
86 '--bot', 'bot1:test1', 89 '--bot', 'bot1:test1',
87 '--testfilter', 'test2', 90 '--testfilter', 'test2',
88 ] 91 ]
89 options, args = trychange.gen_parser(None).parse_args(cmd) 92 options, args = trychange.gen_parser(None).parse_args(cmd)
90 self.assertEquals([], args) 93 self.assertEquals([], args)
91 try: 94 try:
92 # pylint: disable=W0212 95 # pylint: disable=W0212
93 trychange._ParseSendChangeOptions(options) 96 trychange._ParseBotList(options.bot, options.testfilter)
94 self.fail() 97 self.fail()
95 except ValueError: 98 except ValueError:
96 pass 99 pass
97 100
98 101
99 class SVNUnittest(TryChangeTestsBase): 102 class SVNUnittest(TryChangeTestsBase):
100 """trychange.SVN tests.""" 103 """trychange.SVN tests."""
101 def testMembersChanged(self): 104 def testMembersChanged(self):
102 members = [ 105 members = [
103 'AutomagicalSettings', 'CaptureStatus', 'GetCodeReviewSetting', 106 'AutomagicalSettings', 'CaptureStatus', 'GetCodeReviewSetting',
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') 149 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com')
147 self.mox.ReplayAll() 150 self.mox.ReplayAll()
148 git = trychange.GIT(self.options, self.fake_root, self.options.files) 151 git = trychange.GIT(self.options, self.fake_root, self.options.files)
149 self.assertEqual(git.GetFileNames(), self.expected_files) 152 self.assertEqual(git.GetFileNames(), self.expected_files)
150 self.assertEqual(git.checkout_root, self.fake_root) 153 self.assertEqual(git.checkout_root, self.fake_root)
151 self.assertEqual(git.GenerateDiff(), 'A diff') 154 self.assertEqual(git.GenerateDiff(), 'A diff')
152 155
153 156
154 if __name__ == '__main__': 157 if __name__ == '__main__':
155 unittest.main() 158 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_support.py ('k') | trychange.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698