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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 # pass -v to enable it. | 26 # pass -v to enable it. |
27 DEBUGGING = False | 27 DEBUGGING = False |
28 | 28 |
29 # A patch that will fail to apply. | 29 # A patch that will fail to apply. |
30 BAD_PATCH = ''.join( | 30 BAD_PATCH = ''.join( |
31 [l for l in GIT.PATCH.splitlines(True) if l.strip() != 'e']) | 31 [l for l in GIT.PATCH.splitlines(True) if l.strip() != 'e']) |
32 | 32 |
33 | 33 |
34 class FakeRepos(fake_repos.FakeReposBase): | 34 class FakeRepos(fake_repos.FakeReposBase): |
| 35 TEST_GIT_REPO = 'repo_1' |
| 36 |
35 def populateSvn(self): | 37 def populateSvn(self): |
36 """Creates a few revisions of changes files.""" | 38 """Creates a few revisions of changes files.""" |
37 subprocess2.check_call( | 39 subprocess2.check_call( |
38 ['svn', 'checkout', self.svn_base, self.svn_checkout, '-q', | 40 ['svn', 'checkout', self.svn_base, self.svn_checkout, '-q', |
39 '--non-interactive', '--no-auth-cache', | 41 '--non-interactive', '--no-auth-cache', |
40 '--username', self.USERS[0][0], '--password', self.USERS[0][1]]) | 42 '--username', self.USERS[0][0], '--password', self.USERS[0][1]]) |
41 assert os.path.isdir(os.path.join(self.svn_checkout, '.svn')) | 43 assert os.path.isdir(os.path.join(self.svn_checkout, '.svn')) |
42 self._commit_svn(self._tree_1()) | 44 self._commit_svn(self._svn_tree_1()) |
43 self._commit_svn(self._tree_2()) | 45 self._commit_svn(self._svn_tree_2()) |
| 46 |
| 47 def populateGit(self): |
| 48 """Creates a few revisions of changes files.""" |
| 49 self._commit_git(self.TEST_GIT_REPO, self._git_tree()) |
| 50 # Fix for the remote rejected error. For more details see: |
| 51 # http://stackoverflow.com/questions/2816369/git-push-error-remote |
| 52 subprocess2.check_output( |
| 53 ['git', '--git-dir', |
| 54 os.path.join(self.git_root, self.TEST_GIT_REPO, '.git'), |
| 55 'config', '--bool', 'core.bare', 'true']) |
| 56 |
| 57 assert os.path.isdir( |
| 58 os.path.join(self.git_root, self.TEST_GIT_REPO, '.git')) |
44 | 59 |
45 @staticmethod | 60 @staticmethod |
46 def _tree_1(): | 61 def _git_tree(): |
| 62 fs = {} |
| 63 fs['origin'] = 'git@1' |
| 64 fs['extra'] = 'dummy\n' # new |
| 65 fs['codereview.settings'] = ( |
| 66 '# Test data\n' |
| 67 'bar: pouet\n') |
| 68 fs['chrome/file.cc'] = ( |
| 69 'a\n' |
| 70 'bb\n' |
| 71 'ccc\n' |
| 72 'dd\n' |
| 73 'e\n' |
| 74 'ff\n' |
| 75 'ggg\n' |
| 76 'hh\n' |
| 77 'i\n' |
| 78 'jj\n' |
| 79 'kkk\n' |
| 80 'll\n' |
| 81 'm\n' |
| 82 'nn\n' |
| 83 'ooo\n' |
| 84 'pp\n' |
| 85 'q\n') |
| 86 fs['chromeos/views/DOMui_menu_widget.h'] = ( |
| 87 '// Copyright (c) 2010\n' |
| 88 '// Use of this source code\n' |
| 89 '// found in the LICENSE file.\n' |
| 90 '\n' |
| 91 '#ifndef DOM\n' |
| 92 '#define DOM\n' |
| 93 '#pragma once\n' |
| 94 '\n' |
| 95 '#include <string>\n' |
| 96 '#endif\n') |
| 97 return fs |
| 98 |
| 99 @staticmethod |
| 100 def _svn_tree_1(): |
47 fs = {} | 101 fs = {} |
48 fs['trunk/origin'] = 'svn@1' | 102 fs['trunk/origin'] = 'svn@1' |
49 fs['trunk/codereview.settings'] = ( | 103 fs['trunk/codereview.settings'] = ( |
50 '# Test data\n' | 104 '# Test data\n' |
51 'bar: pouet\n') | 105 'bar: pouet\n') |
52 fs['trunk/chrome/file.cc'] = ( | 106 fs['trunk/chrome/file.cc'] = ( |
53 'a\n' | 107 'a\n' |
54 'bb\n' | 108 'bb\n' |
55 'ccc\n' | 109 'ccc\n' |
56 'dd\n' | 110 'dd\n' |
57 'e\n' | 111 'e\n' |
58 'ff\n' | 112 'ff\n' |
59 'ggg\n' | 113 'ggg\n' |
60 'hh\n' | 114 'hh\n' |
61 'i\n' | 115 'i\n' |
62 'jj\n' | 116 'jj\n' |
63 'kkk\n' | 117 'kkk\n' |
64 'll\n' | 118 'll\n' |
65 'm\n' | 119 'm\n' |
66 'nn\n' | 120 'nn\n' |
67 'ooo\n' | 121 'ooo\n' |
68 'pp\n' | 122 'pp\n' |
69 'q\n') | 123 'q\n') |
70 return fs | 124 return fs |
71 | 125 |
72 @classmethod | 126 @classmethod |
73 def _tree_2(cls): | 127 def _svn_tree_2(cls): |
74 fs = cls._tree_1() | 128 fs = cls._svn_tree_1() |
75 fs['trunk/origin'] = 'svn@2\n' | 129 fs['trunk/origin'] = 'svn@2\n' |
76 fs['trunk/extra'] = 'dummy\n' | 130 fs['trunk/extra'] = 'dummy\n' |
77 fs['trunk/bin_file'] = '\x00' | 131 fs['trunk/bin_file'] = '\x00' |
78 fs['trunk/chromeos/views/DOMui_menu_widget.h'] = ( | 132 fs['trunk/chromeos/views/DOMui_menu_widget.h'] = ( |
79 '// Copyright (c) 2010\n' | 133 '// Copyright (c) 2010\n' |
80 '// Use of this source code\n' | 134 '// Use of this source code\n' |
81 '// found in the LICENSE file.\n' | 135 '// found in the LICENSE file.\n' |
82 '\n' | 136 '\n' |
83 '#ifndef DOM\n' | 137 '#ifndef DOM\n' |
84 '#define DOM\n' | 138 '#define DOM\n' |
85 '#pragma once\n' | 139 '#pragma once\n' |
86 '\n' | 140 '\n' |
87 '#include <string>\n' | 141 '#include <string>\n' |
88 '#endif\n') | 142 '#endif\n') |
89 return fs | 143 return fs |
90 | 144 |
91 def populateGit(self): | |
92 raise NotImplementedError() | |
93 | |
94 | 145 |
95 # pylint: disable=R0201 | 146 # pylint: disable=R0201 |
96 class BaseTest(fake_repos.FakeReposTestBase): | 147 class BaseTest(fake_repos.FakeReposTestBase): |
97 name = 'foo' | 148 name = 'foo' |
98 FAKE_REPOS_CLASS = FakeRepos | 149 FAKE_REPOS_CLASS = FakeRepos |
99 is_read_only = False | 150 is_read_only = False |
100 | 151 |
101 def setUp(self): | 152 def setUp(self): |
102 # Need to enforce subversion_config first. | 153 # Need to enforce subversion_config first. |
103 checkout.SvnMixIn.svn_config_dir = os.path.join( | 154 checkout.SvnMixIn.svn_config_dir = os.path.join( |
(...skipping 16 matching lines...) Expand all Loading... |
120 def get_patches(self): | 171 def get_patches(self): |
121 return patch.PatchSet([ | 172 return patch.PatchSet([ |
122 patch.FilePatchDiff('new_dir/subdir/new_file', GIT.NEW_SUBDIR, []), | 173 patch.FilePatchDiff('new_dir/subdir/new_file', GIT.NEW_SUBDIR, []), |
123 patch.FilePatchDiff('chrome/file.cc', GIT.PATCH, []), | 174 patch.FilePatchDiff('chrome/file.cc', GIT.PATCH, []), |
124 # TODO(maruel): Test with is_new == False. | 175 # TODO(maruel): Test with is_new == False. |
125 patch.FilePatchBinary('bin_file', '\x00', [], is_new=True), | 176 patch.FilePatchBinary('bin_file', '\x00', [], is_new=True), |
126 patch.FilePatchDelete('extra', False), | 177 patch.FilePatchDelete('extra', False), |
127 ]) | 178 ]) |
128 | 179 |
129 def get_trunk(self, modified): | 180 def get_trunk(self, modified): |
130 tree = {} | 181 raise NotImplementedError() |
131 subroot = 'trunk/' | |
132 for k, v in self.FAKE_REPOS.svn_revs[-1].iteritems(): | |
133 if k.startswith(subroot): | |
134 f = k[len(subroot):] | |
135 assert f not in tree | |
136 tree[f] = v | |
137 | 182 |
138 if modified: | 183 def _check_base(self, co, root, expected): |
139 content_lines = tree['chrome/file.cc'].splitlines(True) | 184 raise NotImplementedError() |
140 tree['chrome/file.cc'] = ''.join( | |
141 content_lines[0:5] + ['FOO!\n'] + content_lines[5:]) | |
142 del tree['extra'] | |
143 tree['new_dir/subdir/new_file'] = 'A new file\nshould exist.\n' | |
144 return tree | |
145 | |
146 def _check_base(self, co, root, git, expected): | |
147 read_only = isinstance(co, checkout.ReadOnlyCheckout) | |
148 self.assertEquals(not read_only, bool(expected)) | |
149 self.assertEquals(read_only, self.is_read_only) | |
150 if not read_only: | |
151 self.FAKE_REPOS.svn_dirty = True | |
152 | |
153 self.assertEquals(root, co.project_path) | |
154 self.assertEquals(self.previous_log['revision'], co.prepare(None)) | |
155 self.assertEquals('pouet', co.get_settings('bar')) | |
156 self.assertTree(self.get_trunk(False), root) | |
157 patches = self.get_patches() | |
158 co.apply_patch(patches) | |
159 self.assertEquals( | |
160 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], | |
161 patches.filenames) | |
162 | |
163 if git: | |
164 # Hackish to verify _branches() internal function. | |
165 # pylint: disable=W0212 | |
166 self.assertEquals( | |
167 (['master', 'working_branch'], 'working_branch'), | |
168 co._branches()) | |
169 | |
170 # Verify that the patch is applied even for read only checkout. | |
171 self.assertTree(self.get_trunk(True), root) | |
172 fake_author = self.FAKE_REPOS.USERS[1][0] | |
173 revision = co.commit(u'msg', fake_author) | |
174 # Nothing changed. | |
175 self.assertTree(self.get_trunk(True), root) | |
176 | |
177 if read_only: | |
178 self.assertEquals('FAKE', revision) | |
179 self.assertEquals(self.previous_log['revision'], co.prepare(None)) | |
180 # Changes should be reverted now. | |
181 self.assertTree(self.get_trunk(False), root) | |
182 expected = self.previous_log | |
183 else: | |
184 self.assertEquals(self.previous_log['revision'] + 1, revision) | |
185 self.assertEquals(self.previous_log['revision'] + 1, co.prepare(None)) | |
186 self.assertTree(self.get_trunk(True), root) | |
187 expected = expected.copy() | |
188 expected['msg'] = 'msg' | |
189 expected['revision'] = self.previous_log['revision'] + 1 | |
190 expected.setdefault('author', fake_author) | |
191 | |
192 actual = self._log() | |
193 self.assertEquals(expected, actual) | |
194 | 185 |
195 def _check_exception(self, co, err_msg): | 186 def _check_exception(self, co, err_msg): |
196 co.prepare(None) | 187 co.prepare(None) |
197 try: | 188 try: |
198 co.apply_patch([patch.FilePatchDiff('chrome/file.cc', BAD_PATCH, [])]) | 189 co.apply_patch([patch.FilePatchDiff('chrome/file.cc', BAD_PATCH, [])]) |
199 self.fail() | 190 self.fail() |
200 except checkout.PatchApplicationFailed, e: | 191 except checkout.PatchApplicationFailed, e: |
201 self.assertEquals(e.filename, 'chrome/file.cc') | 192 self.assertEquals(e.filename, 'chrome/file.cc') |
202 self.assertEquals(e.status, err_msg) | 193 self.assertEquals(e.status, err_msg) |
203 | 194 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 data[name] = item.text | 269 data[name] = item.text |
279 set_item('author') | 270 set_item('author') |
280 set_item('msg') | 271 set_item('msg') |
281 revprops = logentry.find('revprops') | 272 revprops = logentry.find('revprops') |
282 if revprops != None: | 273 if revprops != None: |
283 data['revprops'] = [] | 274 data['revprops'] = [] |
284 for prop in revprops.getiterator('property'): | 275 for prop in revprops.getiterator('property'): |
285 data['revprops'].append((prop.attrib['name'], prop.text)) | 276 data['revprops'].append((prop.attrib['name'], prop.text)) |
286 return data | 277 return data |
287 | 278 |
| 279 def _check_base(self, co, root, expected): |
| 280 read_only = isinstance(co, checkout.ReadOnlyCheckout) |
| 281 self.assertEquals(not read_only, bool(expected)) |
| 282 self.assertEquals(read_only, self.is_read_only) |
| 283 if not read_only: |
| 284 self.FAKE_REPOS.svn_dirty = True |
| 285 |
| 286 self.assertEquals(root, co.project_path) |
| 287 self.assertEquals(self.previous_log['revision'], co.prepare(None)) |
| 288 self.assertEquals('pouet', co.get_settings('bar')) |
| 289 self.assertTree(self.get_trunk(False), root) |
| 290 patches = self.get_patches() |
| 291 co.apply_patch(patches) |
| 292 self.assertEquals( |
| 293 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], |
| 294 patches.filenames) |
| 295 |
| 296 # Verify that the patch is applied even for read only checkout. |
| 297 self.assertTree(self.get_trunk(True), root) |
| 298 fake_author = self.FAKE_REPOS.USERS[1][0] |
| 299 revision = co.commit(u'msg', fake_author) |
| 300 # Nothing changed. |
| 301 self.assertTree(self.get_trunk(True), root) |
| 302 |
| 303 if read_only: |
| 304 self.assertEquals('FAKE', revision) |
| 305 self.assertEquals(self.previous_log['revision'], co.prepare(None)) |
| 306 # Changes should be reverted now. |
| 307 self.assertTree(self.get_trunk(False), root) |
| 308 expected = self.previous_log |
| 309 else: |
| 310 self.assertEquals(self.previous_log['revision'] + 1, revision) |
| 311 self.assertEquals(self.previous_log['revision'] + 1, co.prepare(None)) |
| 312 self.assertTree(self.get_trunk(True), root) |
| 313 expected = expected.copy() |
| 314 expected['msg'] = 'msg' |
| 315 expected['revision'] = self.previous_log['revision'] + 1 |
| 316 expected.setdefault('author', fake_author) |
| 317 |
| 318 actual = self._log() |
| 319 self.assertEquals(expected, actual) |
| 320 |
288 def _test_prepare(self, co): | 321 def _test_prepare(self, co): |
289 self.assertEquals(1, co.prepare(1)) | 322 self.assertEquals(1, co.prepare(1)) |
290 | 323 |
| 324 def get_trunk(self, modified): |
| 325 tree = {} |
| 326 subroot = 'trunk/' |
| 327 for k, v in self.FAKE_REPOS.svn_revs[-1].iteritems(): |
| 328 if k.startswith(subroot): |
| 329 f = k[len(subroot):] |
| 330 assert f not in tree |
| 331 tree[f] = v |
| 332 |
| 333 if modified: |
| 334 content_lines = tree['chrome/file.cc'].splitlines(True) |
| 335 tree['chrome/file.cc'] = ''.join( |
| 336 content_lines[0:5] + ['FOO!\n'] + content_lines[5:]) |
| 337 del tree['extra'] |
| 338 tree['new_dir/subdir/new_file'] = 'A new file\nshould exist.\n' |
| 339 return tree |
| 340 |
| 341 |
| 342 class GitBaseTest(BaseTest): |
| 343 def setUp(self): |
| 344 super(GitBaseTest, self).setUp() |
| 345 self.enabled = self.FAKE_REPOS.set_up_git() |
| 346 self.assertTrue(self.enabled) |
| 347 self.previous_log = self._log() |
| 348 |
| 349 # pylint: disable=W0221 |
| 350 def _log(self, log_from_local_repo=False): |
| 351 if log_from_local_repo: |
| 352 repo_root = os.path.join(self.root_dir, self.name) |
| 353 else: |
| 354 repo_root = os.path.join(self.FAKE_REPOS.git_root, |
| 355 self.FAKE_REPOS.TEST_GIT_REPO) |
| 356 out = subprocess2.check_output( |
| 357 ['git', |
| 358 '--git-dir', |
| 359 os.path.join(repo_root, '.git'), |
| 360 'log', '--pretty=format:"%H%x09%ae%x09%ad%x09%s"', |
| 361 '--max-count=1']).strip('"') |
| 362 if out and len(out.split()) != 0: |
| 363 revision = out.split()[0] |
| 364 else: |
| 365 return {'revision': 0} |
| 366 |
| 367 return { |
| 368 'revision': revision, |
| 369 'author': out.split()[1], |
| 370 'msg': out.split()[-1], |
| 371 } |
| 372 |
| 373 def _check_base(self, co, root, expected): |
| 374 read_only = isinstance(co, checkout.ReadOnlyCheckout) |
| 375 self.assertEquals(read_only, self.is_read_only) |
| 376 if not read_only: |
| 377 self.FAKE_REPOS.git_dirty = True |
| 378 |
| 379 self.assertEquals(root, co.project_path) |
| 380 self.assertEquals(self.previous_log['revision'], co.prepare(None)) |
| 381 self.assertEquals('pouet', co.get_settings('bar')) |
| 382 self.assertTree(self.get_trunk(False), root) |
| 383 patches = self.get_patches() |
| 384 co.apply_patch(patches) |
| 385 self.assertEquals( |
| 386 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], |
| 387 patches.filenames) |
| 388 |
| 389 # Hackish to verify _branches() internal function. |
| 390 # pylint: disable=W0212 |
| 391 self.assertEquals( |
| 392 (['master', 'working_branch'], 'working_branch'), |
| 393 co._branches()) |
| 394 |
| 395 # Verify that the patch is applied even for read only checkout. |
| 396 self.assertTree(self.get_trunk(True), root) |
| 397 fake_author = self.FAKE_REPOS.USERS[1][0] |
| 398 revision = co.commit(u'msg', fake_author) |
| 399 # Nothing changed. |
| 400 self.assertTree(self.get_trunk(True), root) |
| 401 |
| 402 if read_only: |
| 403 self.assertEquals('FAKE', revision) |
| 404 self.assertEquals(self.previous_log['revision'], co.prepare(None)) |
| 405 # Changes should be reverted now. |
| 406 self.assertTree(self.get_trunk(False), root) |
| 407 expected = self.previous_log |
| 408 else: |
| 409 self.assertEquals(self._log()['revision'], revision) |
| 410 self.assertEquals(self._log()['revision'], co.prepare(None)) |
| 411 self.assertTree(self.get_trunk(True), root) |
| 412 expected = self._log() |
| 413 |
| 414 actual = self._log(log_from_local_repo=True) |
| 415 self.assertEquals(expected, actual) |
| 416 |
| 417 def get_trunk(self, modified): |
| 418 tree = {} |
| 419 for k, v in self.FAKE_REPOS.git_hashes[ |
| 420 self.FAKE_REPOS.TEST_GIT_REPO][1][1].iteritems(): |
| 421 assert k not in tree |
| 422 tree[k] = v |
| 423 |
| 424 if modified: |
| 425 content_lines = tree['chrome/file.cc'].splitlines(True) |
| 426 tree['chrome/file.cc'] = ''.join( |
| 427 content_lines[0:5] + ['FOO!\n'] + content_lines[5:]) |
| 428 tree['bin_file'] = '\x00' |
| 429 del tree['extra'] |
| 430 tree['new_dir/subdir/new_file'] = 'A new file\nshould exist.\n' |
| 431 return tree |
| 432 |
| 433 def _test_prepare(self, co): |
| 434 print co.prepare(None) |
| 435 |
| 436 |
| 437 class GitCheckout(GitBaseTest): |
| 438 def _get_co(self, post_processors): |
| 439 self.assertNotEqual(False, post_processors) |
| 440 return checkout.GitCheckout( |
| 441 root_dir=self.root_dir, |
| 442 project_name=self.name, |
| 443 remote_branch='master', |
| 444 git_url=os.path.join(self.FAKE_REPOS.git_root, |
| 445 self.FAKE_REPOS.TEST_GIT_REPO), |
| 446 commit_user=self.usr, |
| 447 post_processors=post_processors) |
| 448 |
| 449 def testAll(self): |
| 450 root = os.path.join(self.root_dir, self.name) |
| 451 self._check_base(self._get_co(None), root, None) |
| 452 |
| 453 def testException(self): |
| 454 self._check_exception( |
| 455 self._get_co(None), |
| 456 'While running git apply --index -p1;\n fatal: corrupt patch at line ' |
| 457 '12\n') |
| 458 |
| 459 def testProcess(self): |
| 460 self._test_process(self._get_co) |
| 461 |
| 462 def _testPrepare(self): |
| 463 self._test_prepare(self._get_co(None)) |
| 464 |
| 465 def testMove(self): |
| 466 co = self._get_co(None) |
| 467 self._check_move(co) |
| 468 out = subprocess2.check_output( |
| 469 ['git', 'diff', 'HEAD~', '--name-status'], cwd=co.project_path) |
| 470 out = sorted(out.splitlines()) |
| 471 expected = sorted( |
| 472 [ |
| 473 'A\tchromeos/views/webui_menu_widget.h', |
| 474 'D\tchromeos/views/DOMui_menu_widget.h', |
| 475 ]) |
| 476 self.assertEquals(expected, out) |
| 477 |
291 | 478 |
292 class SvnCheckout(SvnBaseTest): | 479 class SvnCheckout(SvnBaseTest): |
293 def _get_co(self, post_processors): | 480 def _get_co(self, post_processors): |
294 self.assertNotEqual(False, post_processors) | 481 self.assertNotEqual(False, post_processors) |
295 return checkout.SvnCheckout( | 482 return checkout.SvnCheckout( |
296 self.root_dir, self.name, self.usr, self.pwd, self.svn_url, | 483 self.root_dir, self.name, self.usr, self.pwd, self.svn_url, |
297 post_processors) | 484 post_processors) |
298 | 485 |
299 def testAll(self): | 486 def testAll(self): |
300 expected = { | 487 expected = { |
301 'author': self.FAKE_REPOS.USERS[0][0], | 488 'author': self.FAKE_REPOS.USERS[0][0], |
302 'revprops': [('realauthor', self.FAKE_REPOS.USERS[1][0])] | 489 'revprops': [('realauthor', self.FAKE_REPOS.USERS[1][0])] |
303 } | 490 } |
304 root = os.path.join(self.root_dir, self.name) | 491 root = os.path.join(self.root_dir, self.name) |
305 self._check_base(self._get_co(None), root, False, expected) | 492 self._check_base(self._get_co(None), root, expected) |
306 | 493 |
307 def testException(self): | 494 def testException(self): |
308 self._check_exception( | 495 self._check_exception( |
309 self._get_co(None), | 496 self._get_co(None), |
310 'While running patch -p1 --forward --force --no-backup-if-mismatch;\n' | 497 'While running patch -p1 --forward --force --no-backup-if-mismatch;\n' |
311 ' patching file chrome/file.cc\n' | 498 ' patching file chrome/file.cc\n' |
312 ' Hunk #1 FAILED at 3.\n' | 499 ' Hunk #1 FAILED at 3.\n' |
313 ' 1 out of 1 hunk FAILED -- saving rejects to file ' | 500 ' 1 out of 1 hunk FAILED -- saving rejects to file ' |
314 'chrome/file.cc.rej\n') | 501 'chrome/file.cc.rej\n') |
315 | 502 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 537 |
351 def testWithRevPropsSupport(self): | 538 def testWithRevPropsSupport(self): |
352 # Add the hook that will commit in a way that removes the race condition. | 539 # Add the hook that will commit in a way that removes the race condition. |
353 hook = os.path.join(self.FAKE_REPOS.svn_repo, 'hooks', 'pre-commit') | 540 hook = os.path.join(self.FAKE_REPOS.svn_repo, 'hooks', 'pre-commit') |
354 shutil.copyfile(os.path.join(ROOT_DIR, 'sample_pre_commit_hook'), hook) | 541 shutil.copyfile(os.path.join(ROOT_DIR, 'sample_pre_commit_hook'), hook) |
355 os.chmod(hook, 0755) | 542 os.chmod(hook, 0755) |
356 expected = { | 543 expected = { |
357 'revprops': [('commit-bot', 'user1@example.com')], | 544 'revprops': [('commit-bot', 'user1@example.com')], |
358 } | 545 } |
359 root = os.path.join(self.root_dir, self.name) | 546 root = os.path.join(self.root_dir, self.name) |
360 self._check_base(self._get_co(None), root, False, expected) | 547 self._check_base(self._get_co(None), root, expected) |
361 | 548 |
362 def testWithRevPropsSupportNotCommitBot(self): | 549 def testWithRevPropsSupportNotCommitBot(self): |
363 # Add the hook that will commit in a way that removes the race condition. | 550 # Add the hook that will commit in a way that removes the race condition. |
364 hook = os.path.join(self.FAKE_REPOS.svn_repo, 'hooks', 'pre-commit') | 551 hook = os.path.join(self.FAKE_REPOS.svn_repo, 'hooks', 'pre-commit') |
365 shutil.copyfile(os.path.join(ROOT_DIR, 'sample_pre_commit_hook'), hook) | 552 shutil.copyfile(os.path.join(ROOT_DIR, 'sample_pre_commit_hook'), hook) |
366 os.chmod(hook, 0755) | 553 os.chmod(hook, 0755) |
367 co = checkout.SvnCheckout( | 554 co = checkout.SvnCheckout( |
368 self.root_dir, self.name, | 555 self.root_dir, self.name, |
369 self.FAKE_REPOS.USERS[1][0], self.FAKE_REPOS.USERS[1][1], | 556 self.FAKE_REPOS.USERS[1][0], self.FAKE_REPOS.USERS[1][1], |
370 self.svn_url) | 557 self.svn_url) |
371 root = os.path.join(self.root_dir, self.name) | 558 root = os.path.join(self.root_dir, self.name) |
372 expected = { | 559 expected = { |
373 'author': self.FAKE_REPOS.USERS[1][0], | 560 'author': self.FAKE_REPOS.USERS[1][0], |
374 } | 561 } |
375 self._check_base(co, root, False, expected) | 562 self._check_base(co, root, expected) |
376 | 563 |
377 def testAutoProps(self): | 564 def testAutoProps(self): |
378 co = self._get_co(None) | 565 co = self._get_co(None) |
379 co.svn_config = checkout.SvnConfig( | 566 co.svn_config = checkout.SvnConfig( |
380 os.path.join(ROOT_DIR, 'subversion_config')) | 567 os.path.join(ROOT_DIR, 'subversion_config')) |
381 co.prepare(None) | 568 co.prepare(None) |
382 patches = self.get_patches() | 569 patches = self.get_patches() |
383 co.apply_patch(patches) | 570 co.apply_patch(patches) |
384 self.assertEquals( | 571 self.assertEquals( |
385 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], | 572 ['bin_file', 'chrome/file.cc', 'new_dir/subdir/new_file', 'extra'], |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 692 |
506 def _get_co(self, post_processors): | 693 def _get_co(self, post_processors): |
507 self.assertNotEqual(False, post_processors) | 694 self.assertNotEqual(False, post_processors) |
508 return checkout.ReadOnlyCheckout( | 695 return checkout.ReadOnlyCheckout( |
509 checkout.SvnCheckout( | 696 checkout.SvnCheckout( |
510 self.root_dir, self.name, None, None, self.svn_url, None), | 697 self.root_dir, self.name, None, None, self.svn_url, None), |
511 post_processors) | 698 post_processors) |
512 | 699 |
513 def testAll(self): | 700 def testAll(self): |
514 root = os.path.join(self.root_dir, self.name) | 701 root = os.path.join(self.root_dir, self.name) |
515 self._check_base(self._get_co(None), root, False, None) | 702 self._check_base(self._get_co(None), root, None) |
516 | 703 |
517 def testException(self): | 704 def testException(self): |
518 self._check_exception( | 705 self._check_exception( |
519 self._get_co(None), | 706 self._get_co(None), |
520 'While running patch -p1 --forward --force --no-backup-if-mismatch;\n' | 707 'While running patch -p1 --forward --force --no-backup-if-mismatch;\n' |
521 ' patching file chrome/file.cc\n' | 708 ' patching file chrome/file.cc\n' |
522 ' Hunk #1 FAILED at 3.\n' | 709 ' Hunk #1 FAILED at 3.\n' |
523 ' 1 out of 1 hunk FAILED -- saving rejects to file ' | 710 ' 1 out of 1 hunk FAILED -- saving rejects to file ' |
524 'chrome/file.cc.rej\n') | 711 'chrome/file.cc.rej\n') |
525 | 712 |
(...skipping 11 matching lines...) Expand all Loading... |
537 if '-v' in sys.argv: | 724 if '-v' in sys.argv: |
538 DEBUGGING = True | 725 DEBUGGING = True |
539 logging.basicConfig( | 726 logging.basicConfig( |
540 level=logging.DEBUG, | 727 level=logging.DEBUG, |
541 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 728 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
542 else: | 729 else: |
543 logging.basicConfig( | 730 logging.basicConfig( |
544 level=logging.ERROR, | 731 level=logging.ERROR, |
545 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 732 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
546 unittest.main() | 733 unittest.main() |
OLD | NEW |