| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 | 34 |
| 35 class FakeRepos(fake_repos.FakeReposBase): | 35 class FakeRepos(fake_repos.FakeReposBase): |
| 36 def populateSvn(self): | 36 def populateSvn(self): |
| 37 """Creates a few revisions of changes files.""" | 37 """Creates a few revisions of changes files.""" |
| 38 subprocess2.check_call( | 38 subprocess2.check_call( |
| 39 ['svn', 'checkout', self.svn_base, self.svn_checkout, '-q', | 39 ['svn', 'checkout', self.svn_base, self.svn_checkout, '-q', |
| 40 '--non-interactive', '--no-auth-cache', | 40 '--non-interactive', '--no-auth-cache', |
| 41 '--username', self.USERS[0][0], '--password', self.USERS[0][1]]) | 41 '--username', self.USERS[0][0], '--password', self.USERS[0][1]]) |
| 42 assert os.path.isdir(os.path.join(self.svn_checkout, '.svn')) | 42 assert os.path.isdir(os.path.join(self.svn_checkout, '.svn')) |
| 43 self._commit_svn(self._tree_1()) |
| 44 self._commit_svn(self._tree_2()) |
| 45 |
| 46 @staticmethod |
| 47 def _tree_1(): |
| 43 fs = {} | 48 fs = {} |
| 44 fs['trunk/origin'] = 'svn@1' | 49 fs['trunk/origin'] = 'svn@1' |
| 45 fs['trunk/codereview.settings'] = ( | 50 fs['trunk/codereview.settings'] = ( |
| 46 '# Test data\n' | 51 '# Test data\n' |
| 47 'bar: pouet\n') | 52 'bar: pouet\n') |
| 48 fs['trunk/chrome/file.cc'] = ( | 53 fs['trunk/chrome/file.cc'] = ( |
| 49 'a\n' | 54 'a\n' |
| 50 'bb\n' | 55 'bb\n' |
| 51 'ccc\n' | 56 'ccc\n' |
| 52 'dd\n' | 57 'dd\n' |
| 53 'e\n' | 58 'e\n' |
| 54 'ff\n' | 59 'ff\n' |
| 55 'ggg\n' | 60 'ggg\n' |
| 56 'hh\n' | 61 'hh\n' |
| 57 'i\n' | 62 'i\n' |
| 58 'jj\n' | 63 'jj\n' |
| 59 'kkk\n' | 64 'kkk\n' |
| 60 'll\n' | 65 'll\n' |
| 61 'm\n' | 66 'm\n' |
| 62 'nn\n' | 67 'nn\n' |
| 63 'ooo\n' | 68 'ooo\n' |
| 64 'pp\n' | 69 'pp\n' |
| 65 'q\n') | 70 'q\n') |
| 66 self._commit_svn(fs) | 71 return fs |
| 72 |
| 73 @classmethod |
| 74 def _tree_2(cls): |
| 75 fs = cls._tree_1() |
| 67 fs['trunk/origin'] = 'svn@2\n' | 76 fs['trunk/origin'] = 'svn@2\n' |
| 68 fs['trunk/extra'] = 'dummy\n' | 77 fs['trunk/extra'] = 'dummy\n' |
| 69 fs['trunk/bin_file'] = '\x00' | 78 fs['trunk/bin_file'] = '\x00' |
| 70 self._commit_svn(fs) | 79 fs['trunk/chromeos/views/DOMui_menu_widget.h'] = ( |
| 80 '// Copyright (c) 2010\n' |
| 81 '// Use of this source code\n' |
| 82 '// found in the LICENSE file.\n' |
| 83 '\n' |
| 84 '#ifndef DOM\n' |
| 85 '#define DOM\n' |
| 86 '#pragma once\n' |
| 87 '\n' |
| 88 '#include <string>\n' |
| 89 '#endif\n') |
| 90 return fs |
| 71 | 91 |
| 72 def populateGit(self): | 92 def populateGit(self): |
| 73 raise NotImplementedError() | 93 raise NotImplementedError() |
| 74 | 94 |
| 75 | 95 |
| 76 # pylint: disable=R0201 | 96 # pylint: disable=R0201 |
| 77 class BaseTest(fake_repos.FakeReposTestBase): | 97 class BaseTest(fake_repos.FakeReposTestBase): |
| 78 name = 'foo' | 98 name = 'foo' |
| 79 FAKE_REPOS_CLASS = FakeRepos | 99 FAKE_REPOS_CLASS = FakeRepos |
| 80 is_read_only = False | 100 is_read_only = False |
| (...skipping 12 matching lines...) Expand all Loading... |
| 93 subprocess2.call = redirect_call | 113 subprocess2.call = redirect_call |
| 94 self.usr, self.pwd = self.FAKE_REPOS.USERS[0] | 114 self.usr, self.pwd = self.FAKE_REPOS.USERS[0] |
| 95 self.previous_log = None | 115 self.previous_log = None |
| 96 | 116 |
| 97 def tearDown(self): | 117 def tearDown(self): |
| 98 subprocess2.call = self._old_call | 118 subprocess2.call = self._old_call |
| 99 super(BaseTest, self).tearDown() | 119 super(BaseTest, self).tearDown() |
| 100 | 120 |
| 101 def get_patches(self): | 121 def get_patches(self): |
| 102 return patch.PatchSet([ | 122 return patch.PatchSet([ |
| 123 patch.FilePatchDiff('new_dir/subdir/new_file', GIT.NEW_SUBDIR, []), |
| 124 patch.FilePatchDiff('chrome/file.cc', GIT.PATCH, []), |
| 103 # TODO(maruel): Test with is_new == False. | 125 # TODO(maruel): Test with is_new == False. |
| 104 patch.FilePatchBinary('bin_file', '\x00', [], is_new=True), | 126 patch.FilePatchBinary('bin_file', '\x00', [], is_new=True), |
| 105 patch.FilePatchDiff( | |
| 106 'chrome/file.cc', GIT.PATCH, []), | |
| 107 patch.FilePatchDiff('new_dir/subdir/new_file', GIT.NEW_SUBDIR, []), | |
| 108 patch.FilePatchDelete('extra', False), | 127 patch.FilePatchDelete('extra', False), |
| 109 ]) | 128 ]) |
| 110 | 129 |
| 111 def get_trunk(self, modified): | 130 def get_trunk(self, modified): |
| 112 tree = {} | 131 tree = {} |
| 113 subroot = 'trunk/' | 132 subroot = 'trunk/' |
| 114 for k, v in self.FAKE_REPOS.svn_revs[-1].iteritems(): | 133 for k, v in self.FAKE_REPOS.svn_revs[-1].iteritems(): |
| 115 if k.startswith(subroot): | 134 if k.startswith(subroot): |
| 116 f = k[len(subroot):] | 135 f = k[len(subroot):] |
| 117 assert f not in tree | 136 assert f not in tree |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 co.prepare(None) | 213 co.prepare(None) |
| 195 ps = self.get_patches() | 214 ps = self.get_patches() |
| 196 results = [] | 215 results = [] |
| 197 co.apply_patch(ps) | 216 co.apply_patch(ps) |
| 198 expected_co = getattr(co, 'checkout', co) | 217 expected_co = getattr(co, 'checkout', co) |
| 199 # Because of ReadOnlyCheckout. | 218 # Because of ReadOnlyCheckout. |
| 200 expected = [(expected_co, p) for p in ps.patches] | 219 expected = [(expected_co, p) for p in ps.patches] |
| 201 self.assertEquals(len(expected), len(results)) | 220 self.assertEquals(len(expected), len(results)) |
| 202 self.assertEquals(expected, results) | 221 self.assertEquals(expected, results) |
| 203 | 222 |
| 223 def _check_move(self, co): |
| 224 """Makes sure file moves are handled correctly.""" |
| 225 co.prepare(None) |
| 226 patchset = patch.PatchSet([ |
| 227 patch.FilePatchDelete('chromeos/views/DOMui_menu_widget.h', False), |
| 228 patch.FilePatchDiff( |
| 229 'chromeos/views/webui_menu_widget.h', GIT.RENAME_PARTIAL, []), |
| 230 ]) |
| 231 co.apply_patch(patchset) |
| 232 # Make sure chromeos/views/DOMui_menu_widget.h is deleted and |
| 233 # chromeos/views/webui_menu_widget.h is correctly created. |
| 234 root = os.path.join(self.root_dir, self.name) |
| 235 tree = self.get_trunk(False) |
| 236 del tree['chromeos/views/DOMui_menu_widget.h'] |
| 237 tree['chromeos/views/webui_menu_widget.h'] = ( |
| 238 '// Copyright (c) 2011\n' |
| 239 '// Use of this source code\n' |
| 240 '// found in the LICENSE file.\n' |
| 241 '\n' |
| 242 '#ifndef WEB\n' |
| 243 '#define WEB\n' |
| 244 '#pragma once\n' |
| 245 '\n' |
| 246 '#include <string>\n' |
| 247 '#endif\n') |
| 248 #print patchset[0].get() |
| 249 #print fake_repos.read_tree(root) |
| 250 self.assertTree(tree, root) |
| 251 |
| 204 | 252 |
| 205 class SvnBaseTest(BaseTest): | 253 class SvnBaseTest(BaseTest): |
| 206 def setUp(self): | 254 def setUp(self): |
| 207 super(SvnBaseTest, self).setUp() | 255 super(SvnBaseTest, self).setUp() |
| 208 self.enabled = self.FAKE_REPOS.set_up_svn() | 256 self.enabled = self.FAKE_REPOS.set_up_svn() |
| 209 self.assertTrue(self.enabled) | 257 self.assertTrue(self.enabled) |
| 210 self.svn_trunk = 'trunk' | 258 self.svn_trunk = 'trunk' |
| 211 self.svn_url = self.svn_base + self.svn_trunk | 259 self.svn_url = self.svn_base + self.svn_trunk |
| 212 self.previous_log = self._log() | 260 self.previous_log = self._log() |
| 213 | 261 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 ['svn', 'pget', 'svn:eol-style', 'chrome/file.cc'], | 390 ['svn', 'pget', 'svn:eol-style', 'chrome/file.cc'], |
| 343 cwd=co.project_path) | 391 cwd=co.project_path) |
| 344 self.assertEquals('LF\n', out) | 392 self.assertEquals('LF\n', out) |
| 345 | 393 |
| 346 def testProcess(self): | 394 def testProcess(self): |
| 347 self._test_process(self._get_co) | 395 self._test_process(self._get_co) |
| 348 | 396 |
| 349 def testPrepare(self): | 397 def testPrepare(self): |
| 350 self._test_prepare(self._get_co(None)) | 398 self._test_prepare(self._get_co(None)) |
| 351 | 399 |
| 400 def testMove(self): |
| 401 self._check_move(self._get_co(None)) |
| 402 |
| 352 | 403 |
| 353 class GitSvnCheckout(SvnBaseTest): | 404 class GitSvnCheckout(SvnBaseTest): |
| 354 name = 'foo.git' | 405 name = 'foo.git' |
| 355 | 406 |
| 356 def _get_co(self, post_processors): | 407 def _get_co(self, post_processors): |
| 357 self.assertNotEqual(False, post_processors) | 408 self.assertNotEqual(False, post_processors) |
| 358 return checkout.GitSvnCheckout( | 409 return checkout.GitSvnCheckout( |
| 359 self.root_dir, self.name[:-4], | 410 self.root_dir, self.name[:-4], |
| 360 self.usr, self.pwd, | 411 self.usr, self.pwd, |
| 361 self.svn_base, self.svn_trunk, post_processors) | 412 self.svn_base, self.svn_trunk, post_processors) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 # TODO(maruel): Cheat here until prepare(revision != None) implemented. | 463 # TODO(maruel): Cheat here until prepare(revision != None) implemented. |
| 413 co.old_prepare = co.prepare | 464 co.old_prepare = co.prepare |
| 414 def prepare(rev): | 465 def prepare(rev): |
| 415 # Basically, test that it is broken. | 466 # Basically, test that it is broken. |
| 416 self.assertEquals(1, rev) | 467 self.assertEquals(1, rev) |
| 417 self.assertEquals(2, co.old_prepare(None)) | 468 self.assertEquals(2, co.old_prepare(None)) |
| 418 return 1 | 469 return 1 |
| 419 co.prepare = prepare | 470 co.prepare = prepare |
| 420 self._test_prepare(co) | 471 self._test_prepare(co) |
| 421 | 472 |
| 473 def testMove(self): |
| 474 self._check_move(self._get_co(None)) |
| 475 |
| 422 | 476 |
| 423 class RawCheckout(SvnBaseTest): | 477 class RawCheckout(SvnBaseTest): |
| 424 def setUp(self): | 478 def setUp(self): |
| 425 super(RawCheckout, self).setUp() | 479 super(RawCheckout, self).setUp() |
| 426 # Use a svn checkout as the base. | 480 # Use a svn checkout as the base. |
| 427 self.base_co = checkout.SvnCheckout( | 481 self.base_co = checkout.SvnCheckout( |
| 428 self.root_dir, self.name, None, None, self.svn_url) | 482 self.root_dir, self.name, None, None, self.svn_url) |
| 429 self.base_co.prepare(None) | 483 self.base_co.prepare(None) |
| 430 | 484 |
| 431 def _get_co(self, post_processors): | 485 def _get_co(self, post_processors): |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 # RawCheckout doesn't support prepare() but emulate it. | 529 # RawCheckout doesn't support prepare() but emulate it. |
| 476 co = self._get_co(None) | 530 co = self._get_co(None) |
| 477 revs = [1] | 531 revs = [1] |
| 478 def prepare(asked): | 532 def prepare(asked): |
| 479 self.assertEquals(1, asked) | 533 self.assertEquals(1, asked) |
| 480 return revs.pop(0) | 534 return revs.pop(0) |
| 481 co.prepare = prepare | 535 co.prepare = prepare |
| 482 self._test_prepare(co) | 536 self._test_prepare(co) |
| 483 self.assertEquals([], revs) | 537 self.assertEquals([], revs) |
| 484 | 538 |
| 539 def testMove(self): |
| 540 self._check_move(self._get_co(None)) |
| 541 |
| 485 | 542 |
| 486 class ReadOnlyCheckout(SvnBaseTest): | 543 class ReadOnlyCheckout(SvnBaseTest): |
| 487 # Use SvnCheckout as the backed since it support read-only checkouts too. | 544 # Use SvnCheckout as the backed since it support read-only checkouts too. |
| 488 is_read_only = True | 545 is_read_only = True |
| 489 | 546 |
| 490 def _get_co(self, post_processors): | 547 def _get_co(self, post_processors): |
| 491 self.assertNotEqual(False, post_processors) | 548 self.assertNotEqual(False, post_processors) |
| 492 return checkout.ReadOnlyCheckout( | 549 return checkout.ReadOnlyCheckout( |
| 493 checkout.SvnCheckout( | 550 checkout.SvnCheckout( |
| 494 self.root_dir, self.name, None, None, self.svn_url, None), | 551 self.root_dir, self.name, None, None, self.svn_url, None), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 506 'Hunk #1 FAILED at 3.\n' | 563 'Hunk #1 FAILED at 3.\n' |
| 507 '1 out of 1 hunk FAILED -- saving rejects to file ' | 564 '1 out of 1 hunk FAILED -- saving rejects to file ' |
| 508 'chrome/file.cc.rej\n') | 565 'chrome/file.cc.rej\n') |
| 509 | 566 |
| 510 def testProcess(self): | 567 def testProcess(self): |
| 511 self._test_process(self._get_co) | 568 self._test_process(self._get_co) |
| 512 | 569 |
| 513 def testPrepare(self): | 570 def testPrepare(self): |
| 514 self._test_prepare(self._get_co(None)) | 571 self._test_prepare(self._get_co(None)) |
| 515 | 572 |
| 573 def testMove(self): |
| 574 self._check_move(self._get_co(None)) |
| 575 |
| 516 | 576 |
| 517 if __name__ == '__main__': | 577 if __name__ == '__main__': |
| 518 if '-v' in sys.argv: | 578 if '-v' in sys.argv: |
| 519 DEBUGGING = True | 579 DEBUGGING = True |
| 520 logging.basicConfig( | 580 logging.basicConfig( |
| 521 level=logging.DEBUG, | 581 level=logging.DEBUG, |
| 522 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 582 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 523 else: | 583 else: |
| 524 logging.basicConfig( | 584 logging.basicConfig( |
| 525 level=logging.ERROR, | 585 level=logging.ERROR, |
| 526 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 586 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 527 unittest.main() | 587 unittest.main() |
| OLD | NEW |