| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 try: | 226 try: |
| 227 co.apply_patch([patch.FilePatchDiff('svn_utils_test.txt', BAD_PATCH, [])]) | 227 co.apply_patch([patch.FilePatchDiff('svn_utils_test.txt', BAD_PATCH, [])]) |
| 228 self.fail() | 228 self.fail() |
| 229 except checkout.PatchApplicationFailed, e: | 229 except checkout.PatchApplicationFailed, e: |
| 230 self.assertEquals(e.filename, 'svn_utils_test.txt') | 230 self.assertEquals(e.filename, 'svn_utils_test.txt') |
| 231 self.assertEquals(e.status, err_msg) | 231 self.assertEquals(e.status, err_msg) |
| 232 | 232 |
| 233 def _log(self): | 233 def _log(self): |
| 234 raise NotImplementedError() | 234 raise NotImplementedError() |
| 235 | 235 |
| 236 def _test_process(self, co): |
| 237 """Makes sure the process lambda is called correctly.""" |
| 238 co.prepare() |
| 239 ps = self.get_patches() |
| 240 results = [] |
| 241 co.apply_patch(ps, [lambda *args: results.append(args)]) |
| 242 expected = [(co, p) for p in ps.patches] |
| 243 self.assertEquals(expected, results) |
| 244 |
| 236 | 245 |
| 237 class SvnBaseTest(BaseTest): | 246 class SvnBaseTest(BaseTest): |
| 238 def setUp(self): | 247 def setUp(self): |
| 239 super(SvnBaseTest, self).setUp() | 248 super(SvnBaseTest, self).setUp() |
| 240 self.enabled = self.FAKE_REPOS.set_up_svn() | 249 self.enabled = self.FAKE_REPOS.set_up_svn() |
| 241 self.assertTrue(self.enabled) | 250 self.assertTrue(self.enabled) |
| 242 self.svn_trunk = 'trunk' | 251 self.svn_trunk = 'trunk' |
| 243 self.svn_url = self.svn_base + self.svn_trunk | 252 self.svn_url = self.svn_base + self.svn_trunk |
| 244 self.previous_log = self._log() | 253 self.previous_log = self._log() |
| 245 | 254 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 co.apply_patch(patches) | 379 co.apply_patch(patches) |
| 371 self.assertEquals( | 380 self.assertEquals( |
| 372 ['bin_file', 'extra', 'new_dir/subdir/new_file', 'svn_utils_test.txt'], | 381 ['bin_file', 'extra', 'new_dir/subdir/new_file', 'svn_utils_test.txt'], |
| 373 sorted(patches.filenames)) | 382 sorted(patches.filenames)) |
| 374 # *.txt = svn:eol-style=LF in subversion_config/config. | 383 # *.txt = svn:eol-style=LF in subversion_config/config. |
| 375 out = subprocess2.check_output( | 384 out = subprocess2.check_output( |
| 376 ['svn', 'pget', 'svn:eol-style', 'svn_utils_test.txt'], | 385 ['svn', 'pget', 'svn:eol-style', 'svn_utils_test.txt'], |
| 377 cwd=co.project_path) | 386 cwd=co.project_path) |
| 378 self.assertEquals('LF\n', out) | 387 self.assertEquals('LF\n', out) |
| 379 | 388 |
| 389 def testProcess(self): |
| 390 co = checkout.SvnCheckout( |
| 391 self.root_dir, self.name, |
| 392 None, None, |
| 393 self.svn_url) |
| 394 self._test_process(co) |
| 395 |
| 380 | 396 |
| 381 class GitSvnCheckout(SvnBaseTest): | 397 class GitSvnCheckout(SvnBaseTest): |
| 382 name = 'foo.git' | 398 name = 'foo.git' |
| 383 | 399 |
| 384 def _get_co(self, read_only): | 400 def _get_co(self, read_only): |
| 385 co = checkout.GitSvnCheckout( | 401 co = checkout.GitSvnCheckout( |
| 386 self.root_dir, self.name[:-4], | 402 self.root_dir, self.name[:-4], |
| 387 self.usr, self.pwd, | 403 self.usr, self.pwd, |
| 388 self.svn_base, self.svn_trunk) | 404 self.svn_base, self.svn_trunk) |
| 389 if read_only: | 405 if read_only: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 self.assertEquals(e.filename, 'svn_utils_test.txt') | 451 self.assertEquals(e.filename, 'svn_utils_test.txt') |
| 436 self.assertEquals( | 452 self.assertEquals( |
| 437 e.status, | 453 e.status, |
| 438 'Cannot apply svn property foo to file svn_utils_test.txt.') | 454 'Cannot apply svn property foo to file svn_utils_test.txt.') |
| 439 co.prepare() | 455 co.prepare() |
| 440 # svn:eol-style is ignored. | 456 # svn:eol-style is ignored. |
| 441 svn_props = [('svn:eol-style', 'LF')] | 457 svn_props = [('svn:eol-style', 'LF')] |
| 442 co.apply_patch( | 458 co.apply_patch( |
| 443 [patch.FilePatchDiff('svn_utils_test.txt', NAKED_PATCH, svn_props)]) | 459 [patch.FilePatchDiff('svn_utils_test.txt', NAKED_PATCH, svn_props)]) |
| 444 | 460 |
| 461 def testProcess(self): |
| 462 co = checkout.SvnCheckout( |
| 463 self.root_dir, self.name, |
| 464 None, None, |
| 465 self.svn_url) |
| 466 self._test_process(co) |
| 467 |
| 445 | 468 |
| 446 class RawCheckout(SvnBaseTest): | 469 class RawCheckout(SvnBaseTest): |
| 447 def setUp(self): | 470 def setUp(self): |
| 448 super(RawCheckout, self).setUp() | 471 super(RawCheckout, self).setUp() |
| 449 # Use a svn checkout as the base. | 472 # Use a svn checkout as the base. |
| 450 self.base_co = checkout.SvnCheckout( | 473 self.base_co = checkout.SvnCheckout( |
| 451 self.root_dir, self.name, None, None, self.svn_url) | 474 self.root_dir, self.name, None, None, self.svn_url) |
| 452 self.base_co.prepare() | 475 self.base_co.prepare() |
| 453 | 476 |
| 454 def _get_co(self, read_only): | 477 def _get_co(self, read_only): |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 self._check(True) | 518 self._check(True) |
| 496 | 519 |
| 497 def testException(self): | 520 def testException(self): |
| 498 self._check_exception( | 521 self._check_exception( |
| 499 self._get_co(True), | 522 self._get_co(True), |
| 500 'patching file svn_utils_test.txt\n' | 523 'patching file svn_utils_test.txt\n' |
| 501 'Hunk #1 FAILED at 3.\n' | 524 'Hunk #1 FAILED at 3.\n' |
| 502 '1 out of 1 hunk FAILED -- saving rejects to file ' | 525 '1 out of 1 hunk FAILED -- saving rejects to file ' |
| 503 'svn_utils_test.txt.rej\n') | 526 'svn_utils_test.txt.rej\n') |
| 504 | 527 |
| 528 def testProcess(self): |
| 529 co = checkout.SvnCheckout( |
| 530 self.root_dir, self.name, |
| 531 None, None, |
| 532 self.svn_url) |
| 533 self._test_process(co) |
| 534 |
| 505 | 535 |
| 506 if __name__ == '__main__': | 536 if __name__ == '__main__': |
| 507 if '-v' in sys.argv: | 537 if '-v' in sys.argv: |
| 508 DEBUGGING = True | 538 DEBUGGING = True |
| 509 logging.basicConfig( | 539 logging.basicConfig( |
| 510 level=logging.DEBUG, | 540 level=logging.DEBUG, |
| 511 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 541 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 512 else: | 542 else: |
| 513 logging.basicConfig( | 543 logging.basicConfig( |
| 514 level=logging.ERROR, | 544 level=logging.ERROR, |
| 515 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 545 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 516 unittest.main() | 546 unittest.main() |
| OLD | NEW |