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

Side by Side Diff: tests/trychange_unittest.py

Issue 501143: Remove gclient-specific hacks from trychange into gcl. (Closed)
Patch Set: Small unit test fix Created 11 years 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
OLDNEW
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 optparse 8 import optparse
9 9
10 # Local imports 10 # Local imports
11 import trychange 11 import trychange
12 from super_mox import mox, SuperMoxTestBase 12 from super_mox import mox, SuperMoxTestBase
13 13
14 14
15 class TryChangeTestsBase(SuperMoxTestBase): 15 class TryChangeTestsBase(SuperMoxTestBase):
16 """Setups and tear downs the mocks but doesn't test anything as-is.""" 16 """Setups and tear downs the mocks but doesn't test anything as-is."""
17 pass 17 def setUp(self):
18 SuperMoxTestBase.setUp(self)
19 self.mox.StubOutWithMock(trychange.gclient_utils, 'CheckCall')
20 self.mox.StubOutWithMock(trychange.scm.GIT, 'Capture')
21 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetEmail')
22 self.mox.StubOutWithMock(trychange.scm.SVN, 'DiffItem')
23 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetCheckoutRoot')
24 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetEmail')
25 self.fake_root = self.Dir()
26 self.expected_files = ['foo.txt', 'bar.txt']
27 self.options = optparse.Values()
28 self.options.files = self.expected_files
29 self.options.diff = None
30 self.options.name = None
31 self.options.email = None
18 32
19 33
20 class TryChangeUnittest(TryChangeTestsBase): 34 class TryChangeUnittest(TryChangeTestsBase):
21 """General trychange.py tests.""" 35 """General trychange.py tests."""
22 def testMembersChanged(self): 36 def testMembersChanged(self):
23 members = [ 37 members = [
24 'EscapeDot', 'GIT', 'GetSourceRoot', 38 'EscapeDot', 'GIT', 'GetTryServerSettings', 'GuessVCS',
25 'GetTryServerSettings', 'GuessVCS', 39 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess',
26 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PathDifference',
27 'SCM', 'SVN', 'TryChange', 'USAGE', 'breakpad', 40 'SCM', 'SVN', 'TryChange', 'USAGE', 'breakpad',
28 'datetime', 'gcl', 'gclient_utils', 'getpass', 'logging', 41 'datetime', 'gcl', 'gclient_utils', 'getpass', 'logging',
29 'optparse', 'os', 'presubmit_support', 'scm', 'shutil', 'socket', 42 'optparse', 'os', 'presubmit_support', 'scm', 'shutil', 'socket',
30 'subprocess', 'sys', 'tempfile', 'upload', 'urllib', 43 'subprocess', 'sys', 'tempfile', 'urllib',
31 ] 44 ]
32 # If this test fails, you should add the relevant test. 45 # If this test fails, you should add the relevant test.
33 self.compareMembers(trychange, members) 46 self.compareMembers(trychange, members)
34 47
35 48
36 class SVNUnittest(TryChangeTestsBase): 49 class SVNUnittest(TryChangeTestsBase):
37 """trychange.SVN tests.""" 50 """trychange.SVN tests."""
38 def setUp(self):
39 SuperMoxTestBase.setUp(self)
40 self.fake_root = '/fake_root'
41 self.expected_files = ['foo.txt', 'bar.txt']
42 change_info = trychange.gcl.ChangeInfo(
43 'test_change', 0, 0, 'desc',
44 [('M', f) for f in self.expected_files],
45 self.fake_root)
46 self.svn = trychange.SVN(None)
47 self.svn.change_info = change_info
48
49 def testMembersChanged(self): 51 def testMembersChanged(self):
50 members = [ 52 members = [
51 'GenerateDiff', 'GetFileNames', 'GetLocalRoot', 'ProcessOptions', 53 'GetFileNames', 'GetLocalRoot',
52 'options'
53 ] 54 ]
54 # If this test fails, you should add the relevant test. 55 # If this test fails, you should add the relevant test.
55 self.compareMembers(trychange.SVN(None), members) 56 self.compareMembers(trychange.SVN, members)
56 57
57 def testGetFileNames(self): 58 def testBasic(self):
59 trychange.os.getcwd().AndReturn(self.fake_root)
60 trychange.scm.SVN.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root)
61 trychange.os.getcwd().AndReturn('pro')
62 trychange.os.chdir(self.fake_root)
63 trychange.scm.SVN.DiffItem(self.expected_files[0]).AndReturn('bleh')
64 trychange.scm.SVN.DiffItem(self.expected_files[1]).AndReturn('blew')
65 trychange.os.chdir('pro')
66 trychange.scm.SVN.GetEmail(self.fake_root).AndReturn('georges@example.com')
58 self.mox.ReplayAll() 67 self.mox.ReplayAll()
59 self.assertEqual(self.svn.GetFileNames(), self.expected_files) 68 svn = trychange.SVN(self.options)
60 69 self.assertEqual(svn.GetFileNames(), self.expected_files)
61 def testGetLocalRoot(self): 70 self.assertEqual(svn.GetLocalRoot(), self.fake_root)
62 self.mox.ReplayAll()
63 self.assertEqual(self.svn.GetLocalRoot(), self.fake_root)
64 71
65 72
66 class GITUnittest(TryChangeTestsBase): 73 class GITUnittest(TryChangeTestsBase):
67 """trychange.GIT tests.""" 74 """trychange.GIT tests."""
68 def setUp(self):
69 self.fake_root = trychange.os.path.join(
70 trychange.os.path.dirname(__file__), 'fake_root')
71 self.expected_files = ['foo.txt', 'bar.txt']
72 options = optparse.Values()
73 options.files = self.expected_files
74 self.git = trychange.GIT(options)
75 SuperMoxTestBase.setUp(self)
76
77 def testMembersChanged(self): 75 def testMembersChanged(self):
78 members = [ 76 members = [
79 'GenerateDiff', 'GetFileNames', 'GetLocalRoot', 77 'GetFileNames', 'GetLocalRoot',
80 'GetPatchName', 'ProcessOptions', 'options'
81 ] 78 ]
82 # If this test fails, you should add the relevant test. 79 # If this test fails, you should add the relevant test.
83 self.compareMembers(trychange.GIT(None), members) 80 self.compareMembers(trychange.GIT, members)
84 81
85 def testGetFileNames(self): 82 def testBasic(self):
83 trychange.gclient_utils.CheckCall(
84 ['git', 'rev-parse', '--show-cdup']).AndReturn(self.fake_root)
85 trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root)
86 trychange.gclient_utils.CheckCall(
87 ['git', 'cl', 'upstream']).AndReturn('random branch')
88 trychange.gclient_utils.CheckCall(
89 ['git', 'diff-tree', '-p', '--no-prefix', 'random branch', 'HEAD']
90 ).AndReturn('This is a dummy diff\n+3\n-4\n')
91 trychange.gclient_utils.CheckCall(
92 ['git', 'symbolic-ref', 'HEAD']).AndReturn('refs/heads/another branch')
93 trychange.scm.GIT.GetEmail('.').AndReturn('georges@example.com')
86 self.mox.ReplayAll() 94 self.mox.ReplayAll()
87 self.assertEqual(self.git.GetFileNames(), self.expected_files) 95 git = trychange.GIT(self.options)
88 96 self.assertEqual(git.GetFileNames(), self.expected_files)
89 def testGetLocalRoot(self): 97 self.assertEqual(git.GetLocalRoot(), self.fake_root)
90 self.mox.StubOutWithMock(trychange.upload, 'RunShell')
91 trychange.upload.RunShell(['git', 'rev-parse', '--show-cdup']).AndReturn(
92 self.fake_root)
93 trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root)
94 self.mox.ReplayAll()
95 self.assertEqual(self.git.GetLocalRoot(), self.fake_root)
96 98
97 99
98 if __name__ == '__main__': 100 if __name__ == '__main__':
99 import unittest 101 import unittest
100 unittest.main() 102 unittest.main()
OLDNEW
« gcl.py ('K') | « tests/gclient_utils_test.py ('k') | trychange.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698