| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 self._commit_svn(fs) | 70 self._commit_svn(fs) |
| 71 | 71 |
| 72 def populateGit(self): | 72 def populateGit(self): |
| 73 raise NotImplementedError() | 73 raise NotImplementedError() |
| 74 | 74 |
| 75 | 75 |
| 76 # pylint: disable=R0201 | 76 # pylint: disable=R0201 |
| 77 class BaseTest(fake_repos.FakeReposTestBase): | 77 class BaseTest(fake_repos.FakeReposTestBase): |
| 78 name = 'foo' | 78 name = 'foo' |
| 79 FAKE_REPOS_CLASS = FakeRepos | 79 FAKE_REPOS_CLASS = FakeRepos |
| 80 is_read_only = False |
| 80 | 81 |
| 81 def setUp(self): | 82 def setUp(self): |
| 82 # Need to enforce subversion_config first. | 83 # Need to enforce subversion_config first. |
| 83 checkout.SvnMixIn.svn_config_dir = os.path.join( | 84 checkout.SvnMixIn.svn_config_dir = os.path.join( |
| 84 ROOT_DIR, 'subversion_config') | 85 ROOT_DIR, 'subversion_config') |
| 85 super(BaseTest, self).setUp() | 86 super(BaseTest, self).setUp() |
| 86 self._old_call = subprocess2.call | 87 self._old_call = subprocess2.call |
| 87 def redirect_call(args, **kwargs): | 88 def redirect_call(args, **kwargs): |
| 88 if not DEBUGGING: | 89 if not DEBUGGING: |
| 89 kwargs.setdefault('stdout', subprocess2.PIPE) | 90 kwargs.setdefault('stdout', subprocess2.PIPE) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 119 if modified: | 120 if modified: |
| 120 content_lines = tree['chrome/file.cc'].splitlines(True) | 121 content_lines = tree['chrome/file.cc'].splitlines(True) |
| 121 tree['chrome/file.cc'] = ''.join( | 122 tree['chrome/file.cc'] = ''.join( |
| 122 content_lines[0:5] + ['FOO!\n'] + content_lines[5:]) | 123 content_lines[0:5] + ['FOO!\n'] + content_lines[5:]) |
| 123 del tree['extra'] | 124 del tree['extra'] |
| 124 tree['new_dir/subdir/new_file'] = 'A new file\nshould exist.\n' | 125 tree['new_dir/subdir/new_file'] = 'A new file\nshould exist.\n' |
| 125 return tree | 126 return tree |
| 126 | 127 |
| 127 def _check_base(self, co, root, git, expected): | 128 def _check_base(self, co, root, git, expected): |
| 128 read_only = isinstance(co, checkout.ReadOnlyCheckout) | 129 read_only = isinstance(co, checkout.ReadOnlyCheckout) |
| 129 assert not read_only == bool(expected) | 130 self.assertEquals(not read_only, bool(expected)) |
| 131 self.assertEquals(read_only, self.is_read_only) |
| 130 if not read_only: | 132 if not read_only: |
| 131 self.FAKE_REPOS.svn_dirty = True | 133 self.FAKE_REPOS.svn_dirty = True |
| 132 | 134 |
| 133 self.assertEquals(root, co.project_path) | 135 self.assertEquals(root, co.project_path) |
| 134 self.assertEquals(self.previous_log['revision'], co.prepare(None)) | 136 self.assertEquals(self.previous_log['revision'], co.prepare(None)) |
| 135 self.assertEquals('pouet', co.get_settings('bar')) | 137 self.assertEquals('pouet', co.get_settings('bar')) |
| 136 self.assertTree(self.get_trunk(False), root) | 138 self.assertTree(self.get_trunk(False), root) |
| 137 patches = self.get_patches() | 139 patches = self.get_patches() |
| 138 co.apply_patch(patches) | 140 co.apply_patch(patches) |
| 139 self.assertEquals( | 141 self.assertEquals( |
| 140 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], | 142 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], |
| 141 patches.filenames) | 143 patches.filenames) |
| 142 | 144 |
| 143 if git: | 145 if git: |
| 144 # Hackish to verify _branches() internal function. | 146 # Hackish to verify _branches() internal function. |
| 145 # pylint: disable=W0212 | 147 # pylint: disable=W0212 |
| 146 self.assertEquals( | 148 self.assertEquals( |
| 147 (['master', 'working_branch'], 'working_branch'), | 149 (['master', 'working_branch'], 'working_branch'), |
| 148 co.checkout._branches()) | 150 co._branches()) |
| 149 | 151 |
| 150 # Verify that the patch is applied even for read only checkout. | 152 # Verify that the patch is applied even for read only checkout. |
| 151 self.assertTree(self.get_trunk(True), root) | 153 self.assertTree(self.get_trunk(True), root) |
| 152 fake_author = self.FAKE_REPOS.USERS[1][0] | 154 fake_author = self.FAKE_REPOS.USERS[1][0] |
| 153 revision = co.commit(u'msg', fake_author) | 155 revision = co.commit(u'msg', fake_author) |
| 154 # Nothing changed. | 156 # Nothing changed. |
| 155 self.assertTree(self.get_trunk(True), root) | 157 self.assertTree(self.get_trunk(True), root) |
| 156 | 158 |
| 157 if read_only: | 159 if read_only: |
| 158 self.assertEquals('FAKE', revision) | 160 self.assertEquals('FAKE', revision) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 186 | 188 |
| 187 def _test_process(self, co_lambda): | 189 def _test_process(self, co_lambda): |
| 188 """Makes sure the process lambda is called correctly.""" | 190 """Makes sure the process lambda is called correctly.""" |
| 189 post_processors = [lambda *args: results.append(args)] | 191 post_processors = [lambda *args: results.append(args)] |
| 190 co = co_lambda(post_processors) | 192 co = co_lambda(post_processors) |
| 191 self.assertEquals(post_processors, co.post_processors) | 193 self.assertEquals(post_processors, co.post_processors) |
| 192 co.prepare(None) | 194 co.prepare(None) |
| 193 ps = self.get_patches() | 195 ps = self.get_patches() |
| 194 results = [] | 196 results = [] |
| 195 co.apply_patch(ps) | 197 co.apply_patch(ps) |
| 196 expected = [(co, p) for p in ps.patches] | 198 expected_co = getattr(co, 'checkout', co) |
| 199 # Because of ReadOnlyCheckout. |
| 200 expected = [(expected_co, p) for p in ps.patches] |
| 201 self.assertEquals(len(expected), len(results)) |
| 197 self.assertEquals(expected, results) | 202 self.assertEquals(expected, results) |
| 198 | 203 |
| 199 | 204 |
| 200 class SvnBaseTest(BaseTest): | 205 class SvnBaseTest(BaseTest): |
| 201 def setUp(self): | 206 def setUp(self): |
| 202 super(SvnBaseTest, self).setUp() | 207 super(SvnBaseTest, self).setUp() |
| 203 self.enabled = self.FAKE_REPOS.set_up_svn() | 208 self.enabled = self.FAKE_REPOS.set_up_svn() |
| 204 self.assertTrue(self.enabled) | 209 self.assertTrue(self.enabled) |
| 205 self.svn_trunk = 'trunk' | 210 self.svn_trunk = 'trunk' |
| 206 self.svn_url = self.svn_base + self.svn_trunk | 211 self.svn_url = self.svn_base + self.svn_trunk |
| (...skipping 24 matching lines...) Expand all Loading... |
| 231 data['revprops'] = [] | 236 data['revprops'] = [] |
| 232 for prop in revprops.getiterator('property'): | 237 for prop in revprops.getiterator('property'): |
| 233 data['revprops'].append((prop.attrib['name'], prop.text)) | 238 data['revprops'].append((prop.attrib['name'], prop.text)) |
| 234 return data | 239 return data |
| 235 | 240 |
| 236 def _test_prepare(self, co): | 241 def _test_prepare(self, co): |
| 237 self.assertEquals(1, co.prepare(1)) | 242 self.assertEquals(1, co.prepare(1)) |
| 238 | 243 |
| 239 | 244 |
| 240 class SvnCheckout(SvnBaseTest): | 245 class SvnCheckout(SvnBaseTest): |
| 241 def _get_co(self, read_only): | 246 def _get_co(self, post_processors): |
| 242 if read_only: | 247 self.assertNotEqual(False, post_processors) |
| 243 return checkout.ReadOnlyCheckout( | 248 return checkout.SvnCheckout( |
| 244 checkout.SvnCheckout( | 249 self.root_dir, self.name, self.usr, self.pwd, self.svn_url, |
| 245 self.root_dir, self.name, None, None, self.svn_url)) | 250 post_processors) |
| 246 else: | |
| 247 return checkout.SvnCheckout( | |
| 248 self.root_dir, self.name, self.usr, self.pwd, self.svn_url) | |
| 249 | 251 |
| 250 def _check(self, read_only, expected): | 252 def testAll(self): |
| 251 root = os.path.join(self.root_dir, self.name) | |
| 252 self._check_base(self._get_co(read_only), root, False, expected) | |
| 253 | |
| 254 def testAllRW(self): | |
| 255 expected = { | 253 expected = { |
| 256 'author': self.FAKE_REPOS.USERS[0][0], | 254 'author': self.FAKE_REPOS.USERS[0][0], |
| 257 'revprops': [('realauthor', self.FAKE_REPOS.USERS[1][0])] | 255 'revprops': [('realauthor', self.FAKE_REPOS.USERS[1][0])] |
| 258 } | 256 } |
| 259 self._check(False, expected) | 257 root = os.path.join(self.root_dir, self.name) |
| 260 | 258 self._check_base(self._get_co(None), root, False, expected) |
| 261 def testAllRO(self): | |
| 262 self._check(True, None) | |
| 263 | 259 |
| 264 def testException(self): | 260 def testException(self): |
| 265 self._check_exception( | 261 self._check_exception( |
| 266 self._get_co(True), | 262 self._get_co(None), |
| 267 'While running patch -p1 --forward --force;\n' | 263 'While running patch -p1 --forward --force;\n' |
| 268 'patching file chrome/file.cc\n' | 264 'patching file chrome/file.cc\n' |
| 269 'Hunk #1 FAILED at 3.\n' | 265 'Hunk #1 FAILED at 3.\n' |
| 270 '1 out of 1 hunk FAILED -- saving rejects to file ' | 266 '1 out of 1 hunk FAILED -- saving rejects to file ' |
| 271 'chrome/file.cc.rej\n') | 267 'chrome/file.cc.rej\n') |
| 272 | 268 |
| 273 def testSvnProps(self): | 269 def testSvnProps(self): |
| 274 co = self._get_co(False) | 270 co = self._get_co(None) |
| 275 co.prepare(None) | 271 co.prepare(None) |
| 276 try: | 272 try: |
| 277 # svn:ignore can only be applied to directories. | 273 # svn:ignore can only be applied to directories. |
| 278 svn_props = [('svn:ignore', 'foo')] | 274 svn_props = [('svn:ignore', 'foo')] |
| 279 co.apply_patch( | 275 co.apply_patch( |
| 280 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) | 276 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) |
| 281 self.fail() | 277 self.fail() |
| 282 except checkout.PatchApplicationFailed, e: | 278 except checkout.PatchApplicationFailed, e: |
| 283 self.assertEquals(e.filename, 'chrome/file.cc') | 279 self.assertEquals(e.filename, 'chrome/file.cc') |
| 284 self.assertEquals( | 280 self.assertEquals( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 306 self.assertEquals(v, value) | 302 self.assertEquals(v, value) |
| 307 | 303 |
| 308 def testWithRevPropsSupport(self): | 304 def testWithRevPropsSupport(self): |
| 309 # Add the hook that will commit in a way that removes the race condition. | 305 # Add the hook that will commit in a way that removes the race condition. |
| 310 hook = os.path.join(self.FAKE_REPOS.svn_repo, 'hooks', 'pre-commit') | 306 hook = os.path.join(self.FAKE_REPOS.svn_repo, 'hooks', 'pre-commit') |
| 311 shutil.copyfile(os.path.join(ROOT_DIR, 'sample_pre_commit_hook'), hook) | 307 shutil.copyfile(os.path.join(ROOT_DIR, 'sample_pre_commit_hook'), hook) |
| 312 os.chmod(hook, 0755) | 308 os.chmod(hook, 0755) |
| 313 expected = { | 309 expected = { |
| 314 'revprops': [('commit-bot', 'user1@example.com')], | 310 'revprops': [('commit-bot', 'user1@example.com')], |
| 315 } | 311 } |
| 316 self._check(False, expected) | 312 root = os.path.join(self.root_dir, self.name) |
| 313 self._check_base(self._get_co(None), root, False, expected) |
| 317 | 314 |
| 318 def testWithRevPropsSupportNotCommitBot(self): | 315 def testWithRevPropsSupportNotCommitBot(self): |
| 319 # Add the hook that will commit in a way that removes the race condition. | 316 # Add the hook that will commit in a way that removes the race condition. |
| 320 hook = os.path.join(self.FAKE_REPOS.svn_repo, 'hooks', 'pre-commit') | 317 hook = os.path.join(self.FAKE_REPOS.svn_repo, 'hooks', 'pre-commit') |
| 321 shutil.copyfile(os.path.join(ROOT_DIR, 'sample_pre_commit_hook'), hook) | 318 shutil.copyfile(os.path.join(ROOT_DIR, 'sample_pre_commit_hook'), hook) |
| 322 os.chmod(hook, 0755) | 319 os.chmod(hook, 0755) |
| 323 co = checkout.SvnCheckout( | 320 co = checkout.SvnCheckout( |
| 324 self.root_dir, self.name, | 321 self.root_dir, self.name, |
| 325 self.FAKE_REPOS.USERS[1][0], self.FAKE_REPOS.USERS[1][1], | 322 self.FAKE_REPOS.USERS[1][0], self.FAKE_REPOS.USERS[1][1], |
| 326 self.svn_url) | 323 self.svn_url) |
| 327 root = os.path.join(self.root_dir, self.name) | 324 root = os.path.join(self.root_dir, self.name) |
| 328 expected = { | 325 expected = { |
| 329 'author': self.FAKE_REPOS.USERS[1][0], | 326 'author': self.FAKE_REPOS.USERS[1][0], |
| 330 } | 327 } |
| 331 self._check_base(co, root, False, expected) | 328 self._check_base(co, root, False, expected) |
| 332 | 329 |
| 333 def testAutoProps(self): | 330 def testAutoProps(self): |
| 334 co = self._get_co(False) | 331 co = self._get_co(None) |
| 335 co.svn_config = checkout.SvnConfig( | 332 co.svn_config = checkout.SvnConfig( |
| 336 os.path.join(ROOT_DIR, 'subversion_config')) | 333 os.path.join(ROOT_DIR, 'subversion_config')) |
| 337 co.prepare(None) | 334 co.prepare(None) |
| 338 patches = self.get_patches() | 335 patches = self.get_patches() |
| 339 co.apply_patch(patches) | 336 co.apply_patch(patches) |
| 340 self.assertEquals( | 337 self.assertEquals( |
| 341 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], | 338 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], |
| 342 patches.filenames) | 339 patches.filenames) |
| 343 # *.txt = svn:eol-style=LF in subversion_config/config. | 340 # *.txt = svn:eol-style=LF in subversion_config/config. |
| 344 out = subprocess2.check_output( | 341 out = subprocess2.check_output( |
| 345 ['svn', 'pget', 'svn:eol-style', 'chrome/file.cc'], | 342 ['svn', 'pget', 'svn:eol-style', 'chrome/file.cc'], |
| 346 cwd=co.project_path) | 343 cwd=co.project_path) |
| 347 self.assertEquals('LF\n', out) | 344 self.assertEquals('LF\n', out) |
| 348 | 345 |
| 349 def testProcess(self): | 346 def testProcess(self): |
| 350 co = lambda x: checkout.SvnCheckout( | 347 self._test_process(self._get_co) |
| 351 self.root_dir, self.name, | |
| 352 None, None, | |
| 353 self.svn_url, | |
| 354 x) | |
| 355 self._test_process(co) | |
| 356 | 348 |
| 357 def testPrepare(self): | 349 def testPrepare(self): |
| 358 co = checkout.SvnCheckout( | 350 self._test_prepare(self._get_co(None)) |
| 359 self.root_dir, self.name, | |
| 360 None, None, | |
| 361 self.svn_url) | |
| 362 self._test_prepare(co) | |
| 363 | 351 |
| 364 | 352 |
| 365 class GitSvnCheckout(SvnBaseTest): | 353 class GitSvnCheckout(SvnBaseTest): |
| 366 name = 'foo.git' | 354 name = 'foo.git' |
| 367 | 355 |
| 368 def _get_co(self, read_only): | 356 def _get_co(self, post_processors): |
| 369 co = checkout.GitSvnCheckout( | 357 self.assertNotEqual(False, post_processors) |
| 358 return checkout.GitSvnCheckout( |
| 370 self.root_dir, self.name[:-4], | 359 self.root_dir, self.name[:-4], |
| 371 self.usr, self.pwd, | 360 self.usr, self.pwd, |
| 372 self.svn_base, self.svn_trunk) | 361 self.svn_base, self.svn_trunk, post_processors) |
| 373 if read_only: | |
| 374 co = checkout.ReadOnlyCheckout(co) | |
| 375 else: | |
| 376 # Hack to simplify testing. | |
| 377 co.checkout = co | |
| 378 return co | |
| 379 | 362 |
| 380 def _check(self, read_only, expected): | 363 def testAll(self): |
| 381 root = os.path.join(self.root_dir, self.name) | |
| 382 self._check_base(self._get_co(read_only), root, True, expected) | |
| 383 | |
| 384 def testAllRO(self): | |
| 385 self._check(True, None) | |
| 386 | |
| 387 def testAllRW(self): | |
| 388 expected = { | 364 expected = { |
| 389 'author': self.FAKE_REPOS.USERS[0][0], | 365 'author': self.FAKE_REPOS.USERS[0][0], |
| 390 } | 366 } |
| 391 self._check(False, expected) | 367 root = os.path.join(self.root_dir, self.name) |
| 368 self._check_base(self._get_co(None), root, True, expected) |
| 392 | 369 |
| 393 def testGitSvnPremade(self): | 370 def testGitSvnPremade(self): |
| 394 # Test premade git-svn clone. First make a git-svn clone. | 371 # Test premade git-svn clone. First make a git-svn clone. |
| 395 git_svn_co = self._get_co(True) | 372 git_svn_co = self._get_co(None) |
| 396 revision = git_svn_co.prepare(None) | 373 revision = git_svn_co.prepare(None) |
| 397 self.assertEquals(self.previous_log['revision'], revision) | 374 self.assertEquals(self.previous_log['revision'], revision) |
| 398 # Then use GitSvnClone to clone it to lose the git-svn connection and verify | 375 # Then use GitSvnClone to clone it to lose the git-svn connection and verify |
| 399 # git svn init / git svn fetch works. | 376 # git svn init / git svn fetch works. |
| 400 git_svn_clone = checkout.GitSvnPremadeCheckout( | 377 git_svn_clone = checkout.GitSvnPremadeCheckout( |
| 401 self.root_dir, self.name[:-4] + '2', 'trunk', | 378 self.root_dir, self.name[:-4] + '2', 'trunk', |
| 402 self.usr, self.pwd, | 379 self.usr, self.pwd, |
| 403 self.svn_base, self.svn_trunk, git_svn_co.project_path) | 380 self.svn_base, self.svn_trunk, git_svn_co.project_path) |
| 404 self.assertEquals( | 381 self.assertEquals( |
| 405 self.previous_log['revision'], git_svn_clone.prepare(None)) | 382 self.previous_log['revision'], git_svn_clone.prepare(None)) |
| 406 | 383 |
| 407 def testException(self): | 384 def testException(self): |
| 408 self._check_exception( | 385 self._check_exception( |
| 409 self._get_co(True), 'fatal: corrupt patch at line 12\n') | 386 self._get_co(None), 'fatal: corrupt patch at line 12\n') |
| 410 | 387 |
| 411 def testSvnProps(self): | 388 def testSvnProps(self): |
| 412 co = self._get_co(False) | 389 co = self._get_co(None) |
| 413 co.prepare(None) | 390 co.prepare(None) |
| 414 try: | 391 try: |
| 415 svn_props = [('foo', 'bar')] | 392 svn_props = [('foo', 'bar')] |
| 416 co.apply_patch( | 393 co.apply_patch( |
| 417 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) | 394 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) |
| 418 self.fail() | 395 self.fail() |
| 419 except patch.UnsupportedPatchFormat, e: | 396 except patch.UnsupportedPatchFormat, e: |
| 420 self.assertEquals(e.filename, 'chrome/file.cc') | 397 self.assertEquals(e.filename, 'chrome/file.cc') |
| 421 self.assertEquals( | 398 self.assertEquals( |
| 422 e.status, | 399 e.status, |
| 423 'Cannot apply svn property foo to file chrome/file.cc.') | 400 'Cannot apply svn property foo to file chrome/file.cc.') |
| 424 co.prepare(None) | 401 co.prepare(None) |
| 425 # svn:eol-style is ignored. | 402 # svn:eol-style is ignored. |
| 426 svn_props = [('svn:eol-style', 'LF')] | 403 svn_props = [('svn:eol-style', 'LF')] |
| 427 co.apply_patch( | 404 co.apply_patch( |
| 428 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) | 405 [patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, svn_props)]) |
| 429 | 406 |
| 430 def testProcess(self): | 407 def testProcess(self): |
| 431 co = lambda x: checkout.SvnCheckout( | 408 self._test_process(self._get_co) |
| 432 self.root_dir, self.name, | |
| 433 None, None, | |
| 434 self.svn_url, x) | |
| 435 self._test_process(co) | |
| 436 | 409 |
| 437 def testPrepare(self): | 410 def testPrepare(self): |
| 438 co = checkout.SvnCheckout( | 411 co = self._get_co(None) |
| 439 self.root_dir, self.name, | 412 # TODO(maruel): Cheat here until prepare(revision != None) implemented. |
| 440 None, None, | 413 co.old_prepare = co.prepare |
| 441 self.svn_url) | 414 def prepare(rev): |
| 415 # Basically, test that it is broken. |
| 416 self.assertEquals(1, rev) |
| 417 self.assertEquals(2, co.old_prepare(None)) |
| 418 return 1 |
| 419 co.prepare = prepare |
| 442 self._test_prepare(co) | 420 self._test_prepare(co) |
| 443 | 421 |
| 444 | 422 |
| 445 class RawCheckout(SvnBaseTest): | 423 class RawCheckout(SvnBaseTest): |
| 446 def setUp(self): | 424 def setUp(self): |
| 447 super(RawCheckout, self).setUp() | 425 super(RawCheckout, self).setUp() |
| 448 # Use a svn checkout as the base. | 426 # Use a svn checkout as the base. |
| 449 self.base_co = checkout.SvnCheckout( | 427 self.base_co = checkout.SvnCheckout( |
| 450 self.root_dir, self.name, None, None, self.svn_url) | 428 self.root_dir, self.name, None, None, self.svn_url) |
| 451 self.base_co.prepare(None) | 429 self.base_co.prepare(None) |
| 452 | 430 |
| 453 def _get_co(self, read_only): | 431 def _get_co(self, post_processors): |
| 454 co = checkout.RawCheckout(self.root_dir, self.name, None) | 432 self.assertNotEqual(False, post_processors) |
| 455 if read_only: | 433 return checkout.RawCheckout(self.root_dir, self.name, post_processors) |
| 456 return checkout.ReadOnlyCheckout(co) | |
| 457 return co | |
| 458 | 434 |
| 459 def _check(self, read_only): | 435 def testAll(self): |
| 436 # Can't use self._check_base() since it's too different. |
| 460 root = os.path.join(self.root_dir, self.name) | 437 root = os.path.join(self.root_dir, self.name) |
| 461 co = self._get_co(read_only) | 438 co = self._get_co(None) |
| 462 | 439 |
| 463 # A copy of BaseTest._check_base() | 440 # A copy of BaseTest._check_base() |
| 464 self.assertEquals(root, co.project_path) | 441 self.assertEquals(root, co.project_path) |
| 465 self.assertEquals(None, co.prepare(None)) | 442 self.assertEquals(None, co.prepare(None)) |
| 466 self.assertEquals('pouet', co.get_settings('bar')) | 443 self.assertEquals('pouet', co.get_settings('bar')) |
| 467 self.assertTree(self.get_trunk(False), root) | 444 self.assertTree(self.get_trunk(False), root) |
| 468 patches = self.get_patches() | 445 patches = self.get_patches() |
| 469 co.apply_patch(patches) | 446 co.apply_patch(patches) |
| 470 self.assertEquals( | 447 self.assertEquals( |
| 471 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], | 448 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], |
| 472 patches.filenames) | 449 patches.filenames) |
| 473 | 450 |
| 474 # Verify that the patch is applied even for read only checkout. | 451 # Verify that the patch is applied even for read only checkout. |
| 475 self.assertTree(self.get_trunk(True), root) | 452 self.assertTree(self.get_trunk(True), root) |
| 476 if read_only: | 453 try: |
| 477 revision = co.commit(u'msg', self.FAKE_REPOS.USERS[1][0]) | 454 co.commit(u'msg', self.FAKE_REPOS.USERS[1][0]) |
| 478 self.assertEquals('FAKE', revision) | 455 self.fail() |
| 479 else: | 456 except NotImplementedError: |
| 480 try: | 457 pass |
| 481 co.commit(u'msg', self.FAKE_REPOS.USERS[1][0]) | |
| 482 self.fail() | |
| 483 except NotImplementedError: | |
| 484 pass | |
| 485 self.assertTree(self.get_trunk(True), root) | 458 self.assertTree(self.get_trunk(True), root) |
| 486 # Verify that prepare() is a no-op. | 459 # Verify that prepare() is a no-op. |
| 487 self.assertEquals(None, co.prepare(None)) | 460 self.assertEquals(None, co.prepare(None)) |
| 488 self.assertTree(self.get_trunk(True), root) | 461 self.assertTree(self.get_trunk(True), root) |
| 489 | 462 |
| 490 def testAllRW(self): | |
| 491 self._check(False) | |
| 492 | |
| 493 def testAllRO(self): | |
| 494 self._check(True) | |
| 495 | |
| 496 def testException(self): | 463 def testException(self): |
| 497 self._check_exception( | 464 self._check_exception( |
| 498 self._get_co(True), | 465 self._get_co(None), |
| 499 'patching file chrome/file.cc\n' | 466 'patching file chrome/file.cc\n' |
| 500 'Hunk #1 FAILED at 3.\n' | 467 'Hunk #1 FAILED at 3.\n' |
| 501 '1 out of 1 hunk FAILED -- saving rejects to file ' | 468 '1 out of 1 hunk FAILED -- saving rejects to file ' |
| 502 'chrome/file.cc.rej\n') | 469 'chrome/file.cc.rej\n') |
| 503 | 470 |
| 504 def testProcess(self): | 471 def testProcess(self): |
| 505 co = lambda x: checkout.SvnCheckout( | 472 self._test_process(self._get_co) |
| 506 self.root_dir, self.name, | |
| 507 None, None, | |
| 508 self.svn_url, x) | |
| 509 self._test_process(co) | |
| 510 | 473 |
| 511 def testPrepare(self): | 474 def testPrepare(self): |
| 512 co = checkout.SvnCheckout( | 475 # RawCheckout doesn't support prepare() but emulate it. |
| 513 self.root_dir, self.name, | 476 co = self._get_co(None) |
| 514 None, None, | 477 revs = [1] |
| 515 self.svn_url) | 478 def prepare(asked): |
| 479 self.assertEquals(1, asked) |
| 480 return revs.pop(0) |
| 481 co.prepare = prepare |
| 516 self._test_prepare(co) | 482 self._test_prepare(co) |
| 483 self.assertEquals([], revs) |
| 484 |
| 485 |
| 486 class ReadOnlyCheckout(SvnBaseTest): |
| 487 # Use SvnCheckout as the backed since it support read-only checkouts too. |
| 488 is_read_only = True |
| 489 |
| 490 def _get_co(self, post_processors): |
| 491 self.assertNotEqual(False, post_processors) |
| 492 return checkout.ReadOnlyCheckout( |
| 493 checkout.SvnCheckout( |
| 494 self.root_dir, self.name, None, None, self.svn_url, None), |
| 495 post_processors) |
| 496 |
| 497 def testAll(self): |
| 498 root = os.path.join(self.root_dir, self.name) |
| 499 self._check_base(self._get_co(None), root, False, None) |
| 500 |
| 501 def testException(self): |
| 502 self._check_exception( |
| 503 self._get_co(None), |
| 504 'While running patch -p1 --forward --force;\n' |
| 505 'patching file chrome/file.cc\n' |
| 506 'Hunk #1 FAILED at 3.\n' |
| 507 '1 out of 1 hunk FAILED -- saving rejects to file ' |
| 508 'chrome/file.cc.rej\n') |
| 509 |
| 510 def testProcess(self): |
| 511 self._test_process(self._get_co) |
| 512 |
| 513 def testPrepare(self): |
| 514 self._test_prepare(self._get_co(None)) |
| 517 | 515 |
| 518 | 516 |
| 519 if __name__ == '__main__': | 517 if __name__ == '__main__': |
| 520 if '-v' in sys.argv: | 518 if '-v' in sys.argv: |
| 521 DEBUGGING = True | 519 DEBUGGING = True |
| 522 logging.basicConfig( | 520 logging.basicConfig( |
| 523 level=logging.DEBUG, | 521 level=logging.DEBUG, |
| 524 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 522 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 525 else: | 523 else: |
| 526 logging.basicConfig( | 524 logging.basicConfig( |
| 527 level=logging.ERROR, | 525 level=logging.ERROR, |
| 528 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 526 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
| 529 unittest.main() | 527 unittest.main() |
| OLD | NEW |