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

Side by Side Diff: tests/trychange_unittest.py

Issue 10836180: Make git try warn on a dirty index. (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: minimize unittest diff a bit... Created 8 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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
11 11
12 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__))))
13 13
14 from testing_support.super_mox import SuperMoxTestBase 14 from testing_support.super_mox import SuperMoxTestBase
15 15
16 import subprocess2 16 import subprocess2
17 import trychange 17 import trychange
18 18
19 19
20 class TryChangeTestsBase(SuperMoxTestBase): 20 class TryChangeTestsBase(SuperMoxTestBase):
21 """Setups and tear downs the mocks but doesn't test anything as-is.""" 21 """Setups and tear downs the mocks but doesn't test anything as-is."""
22 def setUp(self): 22 def setUp(self):
23 SuperMoxTestBase.setUp(self) 23 SuperMoxTestBase.setUp(self)
24 self.mox.StubOutWithMock(subprocess2, 'communicate') 24 self.mox.StubOutWithMock(subprocess2, 'communicate')
25 self.mox.StubOutWithMock(trychange, 'RunGit')
25 self.mox.StubOutWithMock(trychange.scm.GIT, 'Capture') 26 self.mox.StubOutWithMock(trychange.scm.GIT, 'Capture')
26 self.mox.StubOutWithMock(trychange.scm.GIT, 'GenerateDiff') 27 self.mox.StubOutWithMock(trychange.scm.GIT, 'GenerateDiff')
27 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetCheckoutRoot') 28 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetCheckoutRoot')
28 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetEmail') 29 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetEmail')
29 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetPatchName') 30 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetPatchName')
30 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetUpstreamBranch') 31 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetUpstreamBranch')
31 self.mox.StubOutWithMock(trychange.scm.SVN, 'DiffItem') 32 self.mox.StubOutWithMock(trychange.scm.SVN, 'DiffItem')
32 self.mox.StubOutWithMock(trychange.scm.SVN, 'GenerateDiff') 33 self.mox.StubOutWithMock(trychange.scm.SVN, 'GenerateDiff')
33 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetCheckoutRoot') 34 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetCheckoutRoot')
34 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetEmail') 35 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetEmail')
35 self.fake_root = self.Dir() 36 self.fake_root = self.Dir()
36 self.expected_files = ['foo.txt', 'bar.txt'] 37 self.expected_files = ['foo.txt', 'bar.txt']
37 self.options = trychange.optparse.Values() 38 self.options = trychange.optparse.Values()
38 self.options.files = self.expected_files 39 self.options.files = self.expected_files
39 self.options.diff = None 40 self.options.diff = None
40 self.options.name = None 41 self.options.name = None
41 self.options.email = None 42 self.options.email = None
42 self.options.exclude = [] 43 self.options.exclude = []
43 44
44 45
45 class TryChangeUnittest(TryChangeTestsBase): 46 class TryChangeUnittest(TryChangeTestsBase):
46 """General trychange.py tests.""" 47 """General trychange.py tests."""
47 def testMembersChanged(self): 48 def testMembersChanged(self):
48 members = [ 49 members = [
49 'EPILOG', 'Escape', 'GIT', 'GuessVCS', 'GetMungedDiff', 'HELP_STRING', 50 'DieWithError', 'EPILOG', 'Escape', 'GIT', 'GetMungedDiff', 'GuessVCS',
50 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess', 'SCM', 'SVN', 51 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess',
51 'TryChange', 'USAGE', 52 'RunCommand', 'RunGit', 'SCM', 'SVN', 'TryChange', 'USAGE', 'breakpad',
52 'breakpad', 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils', 53 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils', 'gen_parser',
53 'getpass', 'gen_parser', 54 'getpass', 'json', 'logging', 'optparse', 'os', 'posixpath', 're', 'scm',
54 'json', 'logging', 'optparse', 'os', 'posixpath', 're', 'scm', 'shutil', 55 'shutil', 'subprocess2', 'sys', 'tempfile', 'urllib']
55 'subprocess2', 'sys', 'tempfile', 'urllib',
56 ]
57 # If this test fails, you should add the relevant test. 56 # If this test fails, you should add the relevant test.
58 self.compareMembers(trychange, members) 57 self.compareMembers(trychange, members)
59 58
60 59
61 class TryChangeSimpleTest(unittest.TestCase): 60 class TryChangeSimpleTest(unittest.TestCase):
62 # Doesn't require supermox to run. 61 # Doesn't require supermox to run.
63 def test_flags(self): 62 def test_flags(self):
64 cmd = [ 63 cmd = [
65 '--bot', 'bot1,bot2', 64 '--bot', 'bot1,bot2',
66 '--testfilter', 'test1', 65 '--testfilter', 'test1',
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 'ReadRootFile', 'GenerateDiff', 'GetFileNames', 'files', 'file_tuples', 130 'ReadRootFile', 'GenerateDiff', 'GetFileNames', 'files', 'file_tuples',
132 ] 131 ]
133 # If this test fails, you should add the relevant test. 132 # If this test fails, you should add the relevant test.
134 self.compareMembers(trychange.GIT, members) 133 self.compareMembers(trychange.GIT, members)
135 134
136 def testBasic(self): 135 def testBasic(self):
137 # pylint: disable=E1103 136 # pylint: disable=E1103
138 trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root) 137 trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root)
139 trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root) 138 trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root)
140 trychange.scm.GIT.GetUpstreamBranch(self.fake_root).AndReturn('somewhere') 139 trychange.scm.GIT.GetUpstreamBranch(self.fake_root).AndReturn('somewhere')
140 trychange.RunGit(['diff-index', 'HEAD'])
141 trychange.scm.GIT.GenerateDiff(self.fake_root, 141 trychange.scm.GIT.GenerateDiff(self.fake_root,
142 full_move=True, 142 full_move=True,
143 files=['foo.txt', 'bar.txt'], 143 files=['foo.txt', 'bar.txt'],
144 branch='somewhere').AndReturn('A diff') 144 branch='somewhere').AndReturn('A diff')
145 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') 145 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233')
146 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') 146 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com')
147 self.mox.ReplayAll() 147 self.mox.ReplayAll()
148 git = trychange.GIT(self.options, self.fake_root, self.options.files) 148 git = trychange.GIT(self.options, self.fake_root, self.options.files)
149 self.assertEqual(git.GetFileNames(), self.expected_files) 149 self.assertEqual(git.GetFileNames(), self.expected_files)
150 self.assertEqual(git.checkout_root, self.fake_root) 150 self.assertEqual(git.checkout_root, self.fake_root)
151 self.assertEqual(git.GenerateDiff(), 'A diff') 151 self.assertEqual(git.GenerateDiff(), 'A diff')
152 152
153 153
154 if __name__ == '__main__': 154 if __name__ == '__main__':
155 unittest.main() 155 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | trychange.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698