| OLD | NEW |
| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 fn(*args, **kwargs) | 21 fn(*args, **kwargs) |
| 22 except scm.gclient_utils.Error, e: | 22 except scm.gclient_utils.Error, e: |
| 23 self.assertEquals(e.args[0], msg) | 23 self.assertEquals(e.args[0], msg) |
| 24 else: | 24 else: |
| 25 self.fail('%s not raised' % msg) | 25 self.fail('%s not raised' % msg) |
| 26 | 26 |
| 27 | 27 |
| 28 class BaseSCMTestCase(BaseTestCase): | 28 class BaseSCMTestCase(BaseTestCase): |
| 29 def setUp(self): | 29 def setUp(self): |
| 30 BaseTestCase.setUp(self) | 30 BaseTestCase.setUp(self) |
| 31 self.mox.StubOutWithMock(scm.gclient_utils, 'Popen') | 31 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCall') |
| 32 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilter') | 32 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilter') |
| 33 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilterAndHeader') | 33 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilterAndHeader') |
| 34 self.mox.StubOutWithMock(scm.gclient_utils, 'Popen') |
| 34 | 35 |
| 35 | 36 |
| 36 class RootTestCase(BaseSCMTestCase): | 37 class RootTestCase(BaseSCMTestCase): |
| 37 def testMembersChanged(self): | 38 def testMembersChanged(self): |
| 38 self.mox.ReplayAll() | 39 self.mox.ReplayAll() |
| 39 members = [ | 40 members = [ |
| 40 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail', | 41 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail', |
| 41 'cStringIO', 'gclient_utils', 'glob', 'os', 're', 'shutil', | 42 'cStringIO', 'gclient_utils', 'glob', 'os', 're', 'shutil', |
| 42 'subprocess', 'sys', 'tempfile', 'time', 'xml', | 43 'subprocess', 'sys', 'tempfile', 'time', 'xml', |
| 43 ] | 44 ] |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 self.assertEqual(scm.GIT.GetEmail(self.fake_root), 'mini@me.com') | 147 self.assertEqual(scm.GIT.GetEmail(self.fake_root), 'mini@me.com') |
| 147 | 148 |
| 148 | 149 |
| 149 class SVNTestCase(BaseSCMTestCase): | 150 class SVNTestCase(BaseSCMTestCase): |
| 150 def setUp(self): | 151 def setUp(self): |
| 151 BaseSCMTestCase.setUp(self) | 152 BaseSCMTestCase.setUp(self) |
| 152 self.root_dir = self.Dir() | 153 self.root_dir = self.Dir() |
| 153 self.args = self.Args() | 154 self.args = self.Args() |
| 154 self.url = self.Url() | 155 self.url = self.Url() |
| 155 self.relpath = 'asf' | 156 self.relpath = 'asf' |
| 157 self.mox.StubOutWithMock(scm.SVN, 'Capture') |
| 156 | 158 |
| 157 def testMembersChanged(self): | 159 def testMembersChanged(self): |
| 158 self.mox.ReplayAll() | 160 self.mox.ReplayAll() |
| 159 members = [ | 161 members = [ |
| 160 'AssertVersion', 'Capture', 'CaptureBaseRevision', | 162 'AssertVersion', 'Capture', 'CaptureRevision', 'CaptureInfo', |
| 161 'CaptureHeadRevision', 'CaptureInfo', 'CaptureStatus', | 163 'CaptureStatus', 'current_version', 'DiffItem', 'GenerateDiff', |
| 162 'current_version', 'DiffItem', 'GenerateDiff', | |
| 163 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved', | 164 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved', |
| 164 'IsMovedInfo', 'ReadSimpleAuth', 'RunAndGetFileList', | 165 'IsMovedInfo', 'ReadSimpleAuth', 'RunAndGetFileList', |
| 165 ] | 166 ] |
| 166 # If this test fails, you should add the relevant test. | 167 # If this test fails, you should add the relevant test. |
| 167 self.compareMembers(scm.SVN, members) | 168 self.compareMembers(scm.SVN, members) |
| 168 | 169 |
| 169 def testGetCheckoutRoot(self): | 170 def testGetCheckoutRoot(self): |
| 170 self.mox.StubOutWithMock(scm.SVN, 'CaptureInfo') | 171 self.mox.StubOutWithMock(scm.SVN, 'CaptureInfo') |
| 171 self.mox.StubOutWithMock(scm, 'GetCasedPath') | 172 self.mox.StubOutWithMock(scm, 'GetCasedPath') |
| 172 scm.os.path.abspath(self.root_dir + 'x').AndReturn(self.root_dir) | 173 scm.os.path.abspath(self.root_dir + 'x').AndReturn(self.root_dir) |
| 173 scm.GetCasedPath(self.root_dir).AndReturn(self.root_dir) | 174 scm.GetCasedPath(self.root_dir).AndReturn(self.root_dir) |
| 174 result1 = { "Repository Root": "Some root" } | 175 result1 = { "Repository Root": "Some root" } |
| 175 scm.SVN.CaptureInfo(self.root_dir, print_error=False).AndReturn(result1) | 176 scm.SVN.CaptureInfo(self.root_dir).AndReturn(result1) |
| 176 results2 = { "Repository Root": "A different root" } | 177 results2 = { "Repository Root": "A different root" } |
| 177 scm.SVN.CaptureInfo(scm.os.path.dirname(self.root_dir), | 178 scm.SVN.CaptureInfo( |
| 178 print_error=False).AndReturn(results2) | 179 scm.os.path.dirname(self.root_dir)).AndReturn(results2) |
| 179 self.mox.ReplayAll() | 180 self.mox.ReplayAll() |
| 180 self.assertEquals(scm.SVN.GetCheckoutRoot(self.root_dir + 'x'), | 181 self.assertEquals(scm.SVN.GetCheckoutRoot(self.root_dir + 'x'), |
| 181 self.root_dir) | 182 self.root_dir) |
| 182 | 183 |
| 183 def testGetFileInfo(self): | 184 def testGetFileInfo(self): |
| 184 xml_text = r"""<?xml version="1.0"?> | 185 xml_text = r"""<?xml version="1.0"?> |
| 185 <info> | 186 <info> |
| 186 <entry kind="file" path="%s" revision="14628"> | 187 <entry kind="file" path="%s" revision="14628"> |
| 187 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> | 188 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> |
| 188 <repository><root>http://src.chromium.org/svn</root></repository> | 189 <repository><root>http://src.chromium.org/svn</root></repository> |
| 189 <wc-info> | 190 <wc-info> |
| 190 <schedule>add</schedule> | 191 <schedule>add</schedule> |
| 191 <depth>infinity</depth> | 192 <depth>infinity</depth> |
| 192 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-
url> | 193 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-
url> |
| 193 <copy-from-rev>14628</copy-from-rev> | 194 <copy-from-rev>14628</copy-from-rev> |
| 194 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> | 195 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> |
| 195 </wc-info> | 196 </wc-info> |
| 196 </entry> | 197 </entry> |
| 197 </info> | 198 </info> |
| 198 """ % self.url | 199 """ % self.url |
| 199 self.mox.StubOutWithMock(scm.SVN, 'Capture') | 200 scm.SVN.Capture(['info', '--xml', self.url]).AndReturn(xml_text) |
| 200 scm.SVN.Capture(['info', '--xml', self.url], '.', True).AndReturn(xml_text) | |
| 201 expected = { | 201 expected = { |
| 202 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', | 202 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', |
| 203 'UUID': None, | 203 'UUID': None, |
| 204 'Repository Root': 'http://src.chromium.org/svn', | 204 'Repository Root': 'http://src.chromium.org/svn', |
| 205 'Schedule': 'add', | 205 'Schedule': 'add', |
| 206 'Copied From URL': | 206 'Copied From URL': |
| 207 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS', | 207 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS', |
| 208 'Copied From Rev': '14628', | 208 'Copied From Rev': '14628', |
| 209 'Path': self.url, | 209 'Path': self.url, |
| 210 'Revision': 14628, | 210 'Revision': 14628, |
| 211 'Node Kind': 'file', | 211 'Node Kind': 'file', |
| 212 } | 212 } |
| 213 self.mox.ReplayAll() | 213 self.mox.ReplayAll() |
| 214 file_info = scm.SVN.CaptureInfo(self.url, '.', True) | 214 file_info = scm.SVN.CaptureInfo(self.url) |
| 215 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) | 215 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) |
| 216 | 216 |
| 217 def testCaptureInfo(self): | 217 def testCaptureInfo(self): |
| 218 xml_text = """<?xml version="1.0"?> | 218 xml_text = """<?xml version="1.0"?> |
| 219 <info> | 219 <info> |
| 220 <entry | 220 <entry |
| 221 kind="dir" | 221 kind="dir" |
| 222 path="." | 222 path="." |
| 223 revision="35"> | 223 revision="35"> |
| 224 <url>%s</url> | 224 <url>%s</url> |
| 225 <repository> | 225 <repository> |
| 226 <root>%s</root> | 226 <root>%s</root> |
| 227 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> | 227 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> |
| 228 </repository> | 228 </repository> |
| 229 <wc-info> | 229 <wc-info> |
| 230 <schedule>normal</schedule> | 230 <schedule>normal</schedule> |
| 231 <depth>infinity</depth> | 231 <depth>infinity</depth> |
| 232 </wc-info> | 232 </wc-info> |
| 233 <commit | 233 <commit |
| 234 revision="35"> | 234 revision="35"> |
| 235 <author>maruel</author> | 235 <author>maruel</author> |
| 236 <date>2008-12-04T20:12:19.685120Z</date> | 236 <date>2008-12-04T20:12:19.685120Z</date> |
| 237 </commit> | 237 </commit> |
| 238 </entry> | 238 </entry> |
| 239 </info> | 239 </info> |
| 240 """ % (self.url, self.root_dir) | 240 """ % (self.url, self.root_dir) |
| 241 self.mox.StubOutWithMock(scm.SVN, 'Capture') | 241 scm.SVN.Capture(['info', '--xml', self.url]).AndReturn(xml_text) |
| 242 scm.SVN.Capture(['info', '--xml', self.url], '.', True).AndReturn(xml_text) | |
| 243 self.mox.ReplayAll() | 242 self.mox.ReplayAll() |
| 244 file_info = scm.SVN.CaptureInfo(self.url, '.', True) | 243 file_info = scm.SVN.CaptureInfo(self.url) |
| 245 expected = { | 244 expected = { |
| 246 'URL': self.url, | 245 'URL': self.url, |
| 247 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', | 246 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', |
| 248 'Revision': 35, | 247 'Revision': 35, |
| 249 'Repository Root': self.root_dir, | 248 'Repository Root': self.root_dir, |
| 250 'Schedule': 'normal', | 249 'Schedule': 'normal', |
| 251 'Copied From URL': None, | 250 'Copied From URL': None, |
| 252 'Copied From Rev': None, | 251 'Copied From Rev': None, |
| 253 'Path': '.', | 252 'Path': '.', |
| 254 'Node Kind': 'directory', | 253 'Node Kind': 'directory', |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 <wc-status props="normal" item="conflicted" revision="14725"> | 285 <wc-status props="normal" item="conflicted" revision="14725"> |
| 287 <commit revision="14633"> | 286 <commit revision="14633"> |
| 288 <author>nsylvain@chromium.org</author> | 287 <author>nsylvain@chromium.org</author> |
| 289 <date>2009-04-27T19:37:17.977400Z</date> | 288 <date>2009-04-27T19:37:17.977400Z</date> |
| 290 </commit> | 289 </commit> |
| 291 </wc-status> | 290 </wc-status> |
| 292 </entry> | 291 </entry> |
| 293 </target> | 292 </target> |
| 294 </status> | 293 </status> |
| 295 """ | 294 """ |
| 296 proc = self.mox.CreateMockAnything() | 295 scm.SVN.Capture(['status', '--xml', '.']).AndReturn(text) |
| 297 scm.gclient_utils.Popen(['svn', 'status', '--xml', '.'], | |
| 298 cwd=None, | |
| 299 stderr=None, | |
| 300 stdout=scm.subprocess.PIPE).AndReturn(proc) | |
| 301 proc.communicate().AndReturn((text, 0)) | |
| 302 | 296 |
| 303 self.mox.ReplayAll() | 297 self.mox.ReplayAll() |
| 304 info = scm.SVN.CaptureStatus('.') | 298 info = scm.SVN.CaptureStatus('.') |
| 305 expected = [ | 299 expected = [ |
| 306 ('? ', 'unversionned_file.txt'), | 300 ('? ', 'unversionned_file.txt'), |
| 307 ('M ', 'build\\internal\\essential.vsprops'), | 301 ('M ', 'build\\internal\\essential.vsprops'), |
| 308 ('A + ', 'chrome\\app\\d'), | 302 ('A + ', 'chrome\\app\\d'), |
| 309 ('MM ', 'chrome\\app\\DEPS'), | 303 ('MM ', 'chrome\\app\\DEPS'), |
| 310 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), | 304 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), |
| 311 ] | 305 ] |
| 312 self.assertEquals(sorted(info), sorted(expected)) | 306 self.assertEquals(sorted(info), sorted(expected)) |
| 313 | 307 |
| 314 def testCaptureStatusEmpty(self): | 308 def testCaptureStatusEmpty(self): |
| 315 text = r"""<?xml version="1.0"?> | 309 text = r"""<?xml version="1.0"?> |
| 316 <status> | 310 <status> |
| 317 <target | 311 <target |
| 318 path="perf"> | 312 path="perf"> |
| 319 </target> | 313 </target> |
| 320 </status>""" | 314 </status>""" |
| 321 proc = self.mox.CreateMockAnything() | 315 scm.SVN.Capture(['status', '--xml']).AndReturn(text) |
| 322 scm.gclient_utils.Popen(['svn', 'status', '--xml'], | |
| 323 cwd=None, | |
| 324 stderr=None, | |
| 325 stdout=scm.subprocess.PIPE).AndReturn(proc) | |
| 326 proc.communicate().AndReturn((text, 0)) | |
| 327 self.mox.ReplayAll() | 316 self.mox.ReplayAll() |
| 328 info = scm.SVN.CaptureStatus(None) | 317 info = scm.SVN.CaptureStatus(None) |
| 329 self.assertEquals(info, []) | 318 self.assertEquals(info, []) |
| 330 | 319 |
| 331 | 320 |
| 332 if __name__ == '__main__': | 321 if __name__ == '__main__': |
| 333 import unittest | 322 import unittest |
| 334 unittest.main() | 323 unittest.main() |
| 335 | 324 |
| 336 # vim: ts=2:sw=2:tw=80:et: | 325 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |