| OLD | NEW |
| 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 checkout.py.""" | 6 """Unit tests for checkout.py.""" |
| 7 | 7 |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 'author': self.FAKE_REPOS.USERS[0][0], | 301 'author': self.FAKE_REPOS.USERS[0][0], |
| 302 'revprops': [('realauthor', self.FAKE_REPOS.USERS[1][0])] | 302 'revprops': [('realauthor', self.FAKE_REPOS.USERS[1][0])] |
| 303 } | 303 } |
| 304 root = os.path.join(self.root_dir, self.name) | 304 root = os.path.join(self.root_dir, self.name) |
| 305 self._check_base(self._get_co(None), root, False, expected) | 305 self._check_base(self._get_co(None), root, False, expected) |
| 306 | 306 |
| 307 def testException(self): | 307 def testException(self): |
| 308 self._check_exception( | 308 self._check_exception( |
| 309 self._get_co(None), | 309 self._get_co(None), |
| 310 'While running patch -p1 --forward --force --no-backup-if-mismatch;\n' | 310 'While running patch -p1 --forward --force --no-backup-if-mismatch;\n' |
| 311 'patching file chrome/file.cc\n' | 311 ' patching file chrome/file.cc\n' |
| 312 'Hunk #1 FAILED at 3.\n' | 312 ' Hunk #1 FAILED at 3.\n' |
| 313 '1 out of 1 hunk FAILED -- saving rejects to file ' | 313 ' 1 out of 1 hunk FAILED -- saving rejects to file ' |
| 314 'chrome/file.cc.rej\n') | 314 'chrome/file.cc.rej\n') |
| 315 | 315 |
| 316 def testSvnProps(self): | 316 def testSvnProps(self): |
| 317 co = self._get_co(None) | 317 co = self._get_co(None) |
| 318 co.prepare(None) | 318 co.prepare(None) |
| 319 try: | 319 try: |
| 320 # svn:ignore can only be applied to directories. | 320 # svn:ignore can only be applied to directories. |
| 321 svn_props = [('svn:ignore', 'foo')] | 321 svn_props = [('svn:ignore', 'foo')] |
| 322 co.apply_patch( | 322 co.apply_patch( |
| 323 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) | 323 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) |
| 324 self.fail() | 324 self.fail() |
| 325 except checkout.PatchApplicationFailed, e: | 325 except checkout.PatchApplicationFailed, e: |
| 326 self.assertEquals(e.filename, 'chrome/file.cc') | 326 self.assertEquals(e.filename, 'chrome/file.cc') |
| 327 self.assertEquals( | 327 self.assertEquals( |
| 328 e.status, | 328 e.status, |
| 329 'While running svn propset svn:ignore foo chrome/file.cc ' | 329 'While running svn propset svn:ignore foo chrome/file.cc ' |
| 330 '--non-interactive;\n' | 330 '--non-interactive;\n' |
| 331 'patching file chrome/file.cc\n' | 331 ' patching file chrome/file.cc\n' |
| 332 'svn: Cannot set \'svn:ignore\' on a file (\'chrome/file.cc\')\n') | 332 ' svn: Cannot set \'svn:ignore\' on a file (\'chrome/file.cc\')\n') |
| 333 co.prepare(None) | 333 co.prepare(None) |
| 334 svn_props = [('svn:eol-style', 'LF'), ('foo', 'bar')] | 334 svn_props = [('svn:eol-style', 'LF'), ('foo', 'bar')] |
| 335 co.apply_patch( | 335 co.apply_patch( |
| 336 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) | 336 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) |
| 337 filepath = os.path.join(self.root_dir, self.name, 'chrome/file.cc') | 337 filepath = os.path.join(self.root_dir, self.name, 'chrome/file.cc') |
| 338 # Manually verify the properties. | 338 # Manually verify the properties. |
| 339 props = subprocess2.check_output( | 339 props = subprocess2.check_output( |
| 340 ['svn', 'proplist', filepath], | 340 ['svn', 'proplist', filepath], |
| 341 cwd=self.root_dir).splitlines()[1:] | 341 cwd=self.root_dir).splitlines()[1:] |
| 342 props = sorted(p.strip() for p in props) | 342 props = sorted(p.strip() for p in props) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 except NotImplementedError: | 465 except NotImplementedError: |
| 466 pass | 466 pass |
| 467 self.assertTree(self.get_trunk(True), root) | 467 self.assertTree(self.get_trunk(True), root) |
| 468 # Verify that prepare() is a no-op. | 468 # Verify that prepare() is a no-op. |
| 469 self.assertEquals(None, co.prepare(None)) | 469 self.assertEquals(None, co.prepare(None)) |
| 470 self.assertTree(self.get_trunk(True), root) | 470 self.assertTree(self.get_trunk(True), root) |
| 471 | 471 |
| 472 def testException(self): | 472 def testException(self): |
| 473 self._check_exception( | 473 self._check_exception( |
| 474 self._get_co(None), | 474 self._get_co(None), |
| 475 'patching file chrome/file.cc\n' | 475 'While running patch -u --binary -p1;\n' |
| 476 'Hunk #1 FAILED at 3.\n' | 476 ' patching file chrome/file.cc\n' |
| 477 '1 out of 1 hunk FAILED -- saving rejects to file ' | 477 ' Hunk #1 FAILED at 3.\n' |
| 478 ' 1 out of 1 hunk FAILED -- saving rejects to file ' |
| 478 'chrome/file.cc.rej\n') | 479 'chrome/file.cc.rej\n') |
| 479 | 480 |
| 480 def testProcess(self): | 481 def testProcess(self): |
| 481 self._test_process(self._get_co) | 482 self._test_process(self._get_co) |
| 482 | 483 |
| 483 def testPrepare(self): | 484 def testPrepare(self): |
| 484 # RawCheckout doesn't support prepare() but emulate it. | 485 # RawCheckout doesn't support prepare() but emulate it. |
| 485 co = self._get_co(None) | 486 co = self._get_co(None) |
| 486 revs = [1] | 487 revs = [1] |
| 487 def prepare(asked): | 488 def prepare(asked): |
| (...skipping 19 matching lines...) Expand all Loading... |
| 507 post_processors) | 508 post_processors) |
| 508 | 509 |
| 509 def testAll(self): | 510 def testAll(self): |
| 510 root = os.path.join(self.root_dir, self.name) | 511 root = os.path.join(self.root_dir, self.name) |
| 511 self._check_base(self._get_co(None), root, False, None) | 512 self._check_base(self._get_co(None), root, False, None) |
| 512 | 513 |
| 513 def testException(self): | 514 def testException(self): |
| 514 self._check_exception( | 515 self._check_exception( |
| 515 self._get_co(None), | 516 self._get_co(None), |
| 516 'While running patch -p1 --forward --force --no-backup-if-mismatch;\n' | 517 'While running patch -p1 --forward --force --no-backup-if-mismatch;\n' |
| 517 'patching file chrome/file.cc\n' | 518 ' patching file chrome/file.cc\n' |
| 518 'Hunk #1 FAILED at 3.\n' | 519 ' Hunk #1 FAILED at 3.\n' |
| 519 '1 out of 1 hunk FAILED -- saving rejects to file ' | 520 ' 1 out of 1 hunk FAILED -- saving rejects to file ' |
| 520 'chrome/file.cc.rej\n') | 521 'chrome/file.cc.rej\n') |
| 521 | 522 |
| 522 def testProcess(self): | 523 def testProcess(self): |
| 523 self._test_process(self._get_co) | 524 self._test_process(self._get_co) |
| 524 | 525 |
| 525 def testPrepare(self): | 526 def testPrepare(self): |
| 526 self._test_prepare(self._get_co(None)) | 527 self._test_prepare(self._get_co(None)) |
| 527 | 528 |
| 528 def testMove(self): | 529 def testMove(self): |
| 529 self._check_move(self._get_co(None)) | 530 self._check_move(self._get_co(None)) |
| 530 | 531 |
| 531 | 532 |
| 532 if __name__ == '__main__': | 533 if __name__ == '__main__': |
| 533 if '-v' in sys.argv: | 534 if '-v' in sys.argv: |
| 534 DEBUGGING = True | 535 DEBUGGING = True |
| 535 logging.basicConfig( | 536 logging.basicConfig( |
| 536 level=logging.DEBUG, | 537 level=logging.DEBUG, |
| 537 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 538 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 538 else: | 539 else: |
| 539 logging.basicConfig( | 540 logging.basicConfig( |
| 540 level=logging.ERROR, | 541 level=logging.ERROR, |
| 541 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 542 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 542 unittest.main() | 543 unittest.main() |
| OLD | NEW |