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

Side by Side Diff: tests/scm_unittest.py

Issue 3294017: Improve tests (Closed)
Patch Set: Created 10 years, 3 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
« no previous file with comments | « tests/gclient_scm_test.py ('k') | tests/super_mox.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/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 scm.py.""" 6 """Unit tests for scm.py."""
7 7
8 from shutil import rmtree 8 from shutil import rmtree
9 import tempfile 9 import tempfile
10 10
11 # Fixes include path. 11 # Fixes include path.
12 from super_mox import mox, SuperMoxBaseTestBase, SuperMoxTestBase 12 from super_mox import mox, TestCaseUtils, SuperMoxTestBase
13 13
14 import scm 14 import scm
15 15
16 16
17 class BaseTestCase(SuperMoxTestBase): 17 class BaseTestCase(SuperMoxTestBase):
18 # Like unittest's assertRaises, but checks for Gclient.Error. 18 # Like unittest's assertRaises, but checks for Gclient.Error.
19 def assertRaisesError(self, msg, fn, *args, **kwargs): 19 def assertRaisesError(self, msg, fn, *args, **kwargs):
20 try: 20 try:
21 fn(*args, **kwargs) 21 fn(*args, **kwargs)
22 except scm.gclient_utils.Error, e: 22 except scm.gclient_utils.Error, e:
(...skipping 16 matching lines...) Expand all
39 self.mox.ReplayAll() 39 self.mox.ReplayAll()
40 members = [ 40 members = [
41 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail', 41 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail',
42 'cStringIO', 'gclient_utils', 'glob', 'os', 're', 'shutil', 42 'cStringIO', 'gclient_utils', 'glob', 'os', 're', 'shutil',
43 'subprocess', 'sys', 'tempfile', 'time', 'xml', 43 'subprocess', 'sys', 'tempfile', 'time', 'xml',
44 ] 44 ]
45 # If this test fails, you should add the relevant test. 45 # If this test fails, you should add the relevant test.
46 self.compareMembers(scm, members) 46 self.compareMembers(scm, members)
47 47
48 48
49 class GitWrapperTestCase(SuperMoxBaseTestBase): 49 class GitWrapperTestCase(BaseSCMTestCase):
50 sample_git_import = """blob
51 mark :1
52 data 6
53 Hello
54
55 blob
56 mark :2
57 data 4
58 Bye
59
60 reset refs/heads/master
61 commit refs/heads/master
62 mark :3
63 author Bob <bob@example.com> 1253744361 -0700
64 committer Bob <bob@example.com> 1253744361 -0700
65 data 8
66 A and B
67 M 100644 :1 a
68 M 100644 :2 b
69
70 blob
71 mark :4
72 data 10
73 Hello
74 You
75
76 blob
77 mark :5
78 data 8
79 Bye
80 You
81
82 commit refs/heads/origin
83 mark :6
84 author Alice <alice@example.com> 1253744424 -0700
85 committer Alice <alice@example.com> 1253744424 -0700
86 data 13
87 Personalized
88 from :3
89 M 100644 :4 a
90 M 100644 :5 b
91
92 reset refs/heads/master
93 from :3
94 """
95
96 def CreateGitRepo(self, git_import, path):
97 try:
98 scm.subprocess.Popen(['git', 'init'],
99 stdout=scm.subprocess.PIPE,
100 stderr=scm.subprocess.STDOUT,
101 cwd=path).communicate()
102 except OSError:
103 # git is not available, skip this test.
104 return False
105 scm.subprocess.Popen(['git', 'fast-import'],
106 stdin=scm.subprocess.PIPE,
107 stdout=scm.subprocess.PIPE,
108 stderr=scm.subprocess.STDOUT,
109 cwd=path).communicate(input=git_import)
110 scm.subprocess.Popen(['git', 'checkout'],
111 stdout=scm.subprocess.PIPE,
112 stderr=scm.subprocess.STDOUT,
113 cwd=path).communicate()
114 return True
115
116 def setUp(self):
117 SuperMoxBaseTestBase.setUp(self)
118 self.args = self.Args()
119 self.url = 'git://foo'
120 self.root_dir = tempfile.mkdtemp()
121 self.relpath = '.'
122 self.base_path = scm.os.path.join(self.root_dir, self.relpath)
123 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
124 self.fake_root = self.Dir()
125
126 def tearDown(self):
127 rmtree(self.root_dir)
128 SuperMoxBaseTestBase.tearDown(self)
129
130 def testMembersChanged(self): 50 def testMembersChanged(self):
131 self.mox.ReplayAll()
132 members = [ 51 members = [
133 'AssertVersion', 'Capture', 'CaptureStatus', 52 'AssertVersion', 'Capture', 'CaptureStatus',
134 'FetchUpstreamTuple', 53 'FetchUpstreamTuple',
135 'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot', 54 'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot',
136 'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch', 55 'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch',
137 'GetUpstreamBranch', 'IsGitSvn', 'ShortBranchName', 56 'GetUpstreamBranch', 'IsGitSvn', 'ShortBranchName',
138 ] 57 ]
139 # If this test fails, you should add the relevant test. 58 # If this test fails, you should add the relevant test.
140 self.compareMembers(scm.GIT, members) 59 self.compareMembers(scm.GIT, members)
141 60
142 def testGetEmail(self): 61 def testGetEmail(self):
143 self.mox.StubOutWithMock(scm.GIT, 'Capture') 62 self.mox.StubOutWithMock(scm.GIT, 'Capture')
144 scm.GIT.Capture(['config', 'user.email'], self.fake_root, error_ok=True 63 scm.GIT.Capture(['config', 'user.email'], self.root_dir, error_ok=True
145 ).AndReturn(['mini@me.com', '']) 64 ).AndReturn(['mini@me.com', ''])
146 self.mox.ReplayAll() 65 self.mox.ReplayAll()
147 self.assertEqual(scm.GIT.GetEmail(self.fake_root), 'mini@me.com') 66 self.assertEqual(scm.GIT.GetEmail(self.root_dir), 'mini@me.com')
148 67
149 68
150 class SVNTestCase(BaseSCMTestCase): 69 class SVNTestCase(BaseSCMTestCase):
151 def setUp(self): 70 def setUp(self):
152 BaseSCMTestCase.setUp(self) 71 BaseSCMTestCase.setUp(self)
153 self.root_dir = self.Dir()
154 self.args = self.Args()
155 self.url = self.Url()
156 self.relpath = 'asf'
157 self.mox.StubOutWithMock(scm.SVN, 'Capture') 72 self.mox.StubOutWithMock(scm.SVN, 'Capture')
73 self.url = self.SvnUrl()
158 74
159 def testMembersChanged(self): 75 def testMembersChanged(self):
160 self.mox.ReplayAll() 76 self.mox.ReplayAll()
161 members = [ 77 members = [
162 'AssertVersion', 'Capture', 'CaptureRevision', 'CaptureInfo', 78 'AssertVersion', 'Capture', 'CaptureRevision', 'CaptureInfo',
163 'CaptureStatus', 'current_version', 'DiffItem', 'GenerateDiff', 79 'CaptureStatus', 'current_version', 'DiffItem', 'GenerateDiff',
164 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved', 80 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved',
165 'IsMovedInfo', 'ReadSimpleAuth', 'RunAndGetFileList', 81 'IsMovedInfo', 'ReadSimpleAuth', 'RunAndGetFileList',
166 ] 82 ]
167 # If this test fails, you should add the relevant test. 83 # If this test fails, you should add the relevant test.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 self.mox.ReplayAll() 232 self.mox.ReplayAll()
317 info = scm.SVN.CaptureStatus(None) 233 info = scm.SVN.CaptureStatus(None)
318 self.assertEquals(info, []) 234 self.assertEquals(info, [])
319 235
320 236
321 if __name__ == '__main__': 237 if __name__ == '__main__':
322 import unittest 238 import unittest
323 unittest.main() 239 unittest.main()
324 240
325 # vim: ts=2:sw=2:tw=80:et: 241 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « tests/gclient_scm_test.py ('k') | tests/super_mox.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698