| 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, 'SubprocessCall') | 32 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCall') |
| 32 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCallAndFilter') | 33 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCallAndFilter') |
| 33 | 34 |
| 34 | 35 |
| 35 class RootTestCase(BaseSCMTestCase): | 36 class RootTestCase(BaseSCMTestCase): |
| 36 def testMembersChanged(self): | 37 def testMembersChanged(self): |
| 37 self.mox.ReplayAll() | 38 self.mox.ReplayAll() |
| 38 members = [ | 39 members = [ |
| 39 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail', | 40 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail', |
| 40 'cStringIO', 'gclient_utils', 'glob', 'os', 're', 'shutil', | 41 'cStringIO', 'gclient_utils', 'glob', 'os', 're', 'shutil', |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 <commit revision="14633"> | 289 <commit revision="14633"> |
| 289 <author>nsylvain@chromium.org</author> | 290 <author>nsylvain@chromium.org</author> |
| 290 <date>2009-04-27T19:37:17.977400Z</date> | 291 <date>2009-04-27T19:37:17.977400Z</date> |
| 291 </commit> | 292 </commit> |
| 292 </wc-status> | 293 </wc-status> |
| 293 </entry> | 294 </entry> |
| 294 </target> | 295 </target> |
| 295 </status> | 296 </status> |
| 296 """ | 297 """ |
| 297 proc = self.mox.CreateMockAnything() | 298 proc = self.mox.CreateMockAnything() |
| 298 scm.subprocess.Popen(['svn', 'status', '--xml', '.'], | 299 scm.gclient_utils.Popen(['svn', 'status', '--xml', '.'], |
| 299 cwd=None, | 300 cwd=None, |
| 300 shell=scm.sys.platform.startswith('win'), | 301 stderr=None, |
| 301 stderr=None, | 302 stdout=scm.subprocess.PIPE).AndReturn(proc) |
| 302 stdout=scm.subprocess.PIPE).AndReturn(proc) | |
| 303 proc.communicate().AndReturn((text, 0)) | 303 proc.communicate().AndReturn((text, 0)) |
| 304 | 304 |
| 305 self.mox.ReplayAll() | 305 self.mox.ReplayAll() |
| 306 info = scm.SVN.CaptureStatus('.') | 306 info = scm.SVN.CaptureStatus('.') |
| 307 expected = [ | 307 expected = [ |
| 308 ('? ', 'unversionned_file.txt'), | 308 ('? ', 'unversionned_file.txt'), |
| 309 ('M ', 'build\\internal\\essential.vsprops'), | 309 ('M ', 'build\\internal\\essential.vsprops'), |
| 310 ('A + ', 'chrome\\app\\d'), | 310 ('A + ', 'chrome\\app\\d'), |
| 311 ('MM ', 'chrome\\app\\DEPS'), | 311 ('MM ', 'chrome\\app\\DEPS'), |
| 312 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), | 312 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), |
| 313 ] | 313 ] |
| 314 self.assertEquals(sorted(info), sorted(expected)) | 314 self.assertEquals(sorted(info), sorted(expected)) |
| 315 | 315 |
| 316 def testRun(self): | 316 def testRun(self): |
| 317 param2 = 'bleh' | 317 param2 = 'bleh' |
| 318 scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], | 318 scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], |
| 319 param2).AndReturn(None) | 319 param2).AndReturn(None) |
| 320 self.mox.ReplayAll() | 320 self.mox.ReplayAll() |
| 321 scm.SVN.Run(['foo', 'bar'], param2) | 321 scm.SVN.Run(['foo', 'bar'], param2) |
| 322 | 322 |
| 323 def testCaptureStatusEmpty(self): | 323 def testCaptureStatusEmpty(self): |
| 324 text = r"""<?xml version="1.0"?> | 324 text = r"""<?xml version="1.0"?> |
| 325 <status> | 325 <status> |
| 326 <target | 326 <target |
| 327 path="perf"> | 327 path="perf"> |
| 328 </target> | 328 </target> |
| 329 </status>""" | 329 </status>""" |
| 330 proc = self.mox.CreateMockAnything() | 330 proc = self.mox.CreateMockAnything() |
| 331 scm.subprocess.Popen(['svn', 'status', '--xml'], | 331 scm.gclient_utils.Popen(['svn', 'status', '--xml'], |
| 332 cwd=None, | 332 cwd=None, |
| 333 shell=scm.sys.platform.startswith('win'), | 333 stderr=None, |
| 334 stderr=None, | 334 stdout=scm.subprocess.PIPE).AndReturn(proc) |
| 335 stdout=scm.subprocess.PIPE).AndReturn(proc) | |
| 336 proc.communicate().AndReturn((text, 0)) | 335 proc.communicate().AndReturn((text, 0)) |
| 337 self.mox.ReplayAll() | 336 self.mox.ReplayAll() |
| 338 info = scm.SVN.CaptureStatus(None) | 337 info = scm.SVN.CaptureStatus(None) |
| 339 self.assertEquals(info, []) | 338 self.assertEquals(info, []) |
| 340 | 339 |
| 341 | 340 |
| 342 if __name__ == '__main__': | 341 if __name__ == '__main__': |
| 343 import unittest | 342 import unittest |
| 344 unittest.main() | 343 unittest.main() |
| 345 | 344 |
| 346 # vim: ts=2:sw=2:tw=80:et: | 345 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |