| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 from __future__ import with_statement | 8 from __future__ import with_statement |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 try: | 227 try: |
| 228 co.apply_patch([patch.FilePatchDiff('svn_utils_test.txt', BAD_PATCH, [])]) | 228 co.apply_patch([patch.FilePatchDiff('svn_utils_test.txt', BAD_PATCH, [])]) |
| 229 self.fail() | 229 self.fail() |
| 230 except checkout.PatchApplicationFailed, e: | 230 except checkout.PatchApplicationFailed, e: |
| 231 self.assertEquals(e.filename, 'svn_utils_test.txt') | 231 self.assertEquals(e.filename, 'svn_utils_test.txt') |
| 232 self.assertEquals(e.status, err_msg) | 232 self.assertEquals(e.status, err_msg) |
| 233 | 233 |
| 234 def _log(self): | 234 def _log(self): |
| 235 raise NotImplementedError() | 235 raise NotImplementedError() |
| 236 | 236 |
| 237 def _test_process(self, co): | 237 def _test_process(self, co_lambda): |
| 238 """Makes sure the process lambda is called correctly.""" | 238 """Makes sure the process lambda is called correctly.""" |
| 239 co.post_processors = [lambda *args: results.append(args)] | 239 post_processors = [lambda *args: results.append(args)] |
| 240 co = co_lambda(post_processors) |
| 241 self.assertEquals(post_processors, co.post_processors) |
| 240 co.prepare(None) | 242 co.prepare(None) |
| 241 ps = self.get_patches() | 243 ps = self.get_patches() |
| 242 results = [] | 244 results = [] |
| 243 co.apply_patch(ps) | 245 co.apply_patch(ps) |
| 244 expected = [(co, p) for p in ps.patches] | 246 expected = [(co, p) for p in ps.patches] |
| 245 self.assertEquals(expected, results) | 247 self.assertEquals(expected, results) |
| 246 | 248 |
| 247 | 249 |
| 248 class SvnBaseTest(BaseTest): | 250 class SvnBaseTest(BaseTest): |
| 249 def setUp(self): | 251 def setUp(self): |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 self.assertEquals( | 390 self.assertEquals( |
| 389 ['bin_file', 'extra', 'new_dir/subdir/new_file', 'svn_utils_test.txt'], | 391 ['bin_file', 'extra', 'new_dir/subdir/new_file', 'svn_utils_test.txt'], |
| 390 sorted(patches.filenames)) | 392 sorted(patches.filenames)) |
| 391 # *.txt = svn:eol-style=LF in subversion_config/config. | 393 # *.txt = svn:eol-style=LF in subversion_config/config. |
| 392 out = subprocess2.check_output( | 394 out = subprocess2.check_output( |
| 393 ['svn', 'pget', 'svn:eol-style', 'svn_utils_test.txt'], | 395 ['svn', 'pget', 'svn:eol-style', 'svn_utils_test.txt'], |
| 394 cwd=co.project_path) | 396 cwd=co.project_path) |
| 395 self.assertEquals('LF\n', out) | 397 self.assertEquals('LF\n', out) |
| 396 | 398 |
| 397 def testProcess(self): | 399 def testProcess(self): |
| 398 co = checkout.SvnCheckout( | 400 co = lambda x: checkout.SvnCheckout( |
| 399 self.root_dir, self.name, | 401 self.root_dir, self.name, |
| 400 None, None, | 402 None, None, |
| 401 self.svn_url) | 403 self.svn_url, |
| 404 x) |
| 402 self._test_process(co) | 405 self._test_process(co) |
| 403 | 406 |
| 404 def testPrepare(self): | 407 def testPrepare(self): |
| 405 co = checkout.SvnCheckout( | 408 co = checkout.SvnCheckout( |
| 406 self.root_dir, self.name, | 409 self.root_dir, self.name, |
| 407 None, None, | 410 None, None, |
| 408 self.svn_url) | 411 self.svn_url) |
| 409 self._test_prepare(co) | 412 self._test_prepare(co) |
| 410 | 413 |
| 411 | 414 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 self.assertEquals( | 471 self.assertEquals( |
| 469 e.status, | 472 e.status, |
| 470 'Cannot apply svn property foo to file svn_utils_test.txt.') | 473 'Cannot apply svn property foo to file svn_utils_test.txt.') |
| 471 co.prepare(None) | 474 co.prepare(None) |
| 472 # svn:eol-style is ignored. | 475 # svn:eol-style is ignored. |
| 473 svn_props = [('svn:eol-style', 'LF')] | 476 svn_props = [('svn:eol-style', 'LF')] |
| 474 co.apply_patch( | 477 co.apply_patch( |
| 475 [patch.FilePatchDiff('svn_utils_test.txt', NAKED_PATCH, svn_props)]) | 478 [patch.FilePatchDiff('svn_utils_test.txt', NAKED_PATCH, svn_props)]) |
| 476 | 479 |
| 477 def testProcess(self): | 480 def testProcess(self): |
| 478 co = checkout.SvnCheckout( | 481 co = lambda x: checkout.SvnCheckout( |
| 479 self.root_dir, self.name, | 482 self.root_dir, self.name, |
| 480 None, None, | 483 None, None, |
| 481 self.svn_url) | 484 self.svn_url, x) |
| 482 self._test_process(co) | 485 self._test_process(co) |
| 483 | 486 |
| 484 def testPrepare(self): | 487 def testPrepare(self): |
| 485 co = checkout.SvnCheckout( | 488 co = checkout.SvnCheckout( |
| 486 self.root_dir, self.name, | 489 self.root_dir, self.name, |
| 487 None, None, | 490 None, None, |
| 488 self.svn_url) | 491 self.svn_url) |
| 489 self._test_prepare(co) | 492 self._test_prepare(co) |
| 490 | 493 |
| 491 | 494 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 545 |
| 543 def testException(self): | 546 def testException(self): |
| 544 self._check_exception( | 547 self._check_exception( |
| 545 self._get_co(True), | 548 self._get_co(True), |
| 546 'patching file svn_utils_test.txt\n' | 549 'patching file svn_utils_test.txt\n' |
| 547 'Hunk #1 FAILED at 3.\n' | 550 'Hunk #1 FAILED at 3.\n' |
| 548 '1 out of 1 hunk FAILED -- saving rejects to file ' | 551 '1 out of 1 hunk FAILED -- saving rejects to file ' |
| 549 'svn_utils_test.txt.rej\n') | 552 'svn_utils_test.txt.rej\n') |
| 550 | 553 |
| 551 def testProcess(self): | 554 def testProcess(self): |
| 552 co = checkout.SvnCheckout( | 555 co = lambda x: checkout.SvnCheckout( |
| 553 self.root_dir, self.name, | 556 self.root_dir, self.name, |
| 554 None, None, | 557 None, None, |
| 555 self.svn_url) | 558 self.svn_url, x) |
| 556 self._test_process(co) | 559 self._test_process(co) |
| 557 | 560 |
| 558 def testPrepare(self): | 561 def testPrepare(self): |
| 559 co = checkout.SvnCheckout( | 562 co = checkout.SvnCheckout( |
| 560 self.root_dir, self.name, | 563 self.root_dir, self.name, |
| 561 None, None, | 564 None, None, |
| 562 self.svn_url) | 565 self.svn_url) |
| 563 self._test_prepare(co) | 566 self._test_prepare(co) |
| 564 | 567 |
| 565 | 568 |
| 566 if __name__ == '__main__': | 569 if __name__ == '__main__': |
| 567 if '-v' in sys.argv: | 570 if '-v' in sys.argv: |
| 568 DEBUGGING = True | 571 DEBUGGING = True |
| 569 logging.basicConfig( | 572 logging.basicConfig( |
| 570 level=logging.DEBUG, | 573 level=logging.DEBUG, |
| 571 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 574 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 572 else: | 575 else: |
| 573 logging.basicConfig( | 576 logging.basicConfig( |
| 574 level=logging.ERROR, | 577 level=logging.ERROR, |
| 575 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 578 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 576 unittest.main() | 579 unittest.main() |
| OLD | NEW |