Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: sky/tools/webkitpy/common/checkout/scm/scm_unittest.py

Issue 639883003: Get test_webkitpy to actually run again. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: merge to ToT Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2009 Google Inc. All rights reserved. 1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 # Copyright (C) 2009 Apple Inc. All rights reserved. 2 # Copyright (C) 2009 Apple Inc. All rights reserved.
3 # Copyright (C) 2011 Daniel Bates (dbates@intudata.com). All rights reserved. 3 # Copyright (C) 2011 Daniel Bates (dbates@intudata.com). All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are 6 # modification, are permitted provided that the following conditions are
7 # met: 7 # met:
8 # 8 #
9 # * Redistributions of source code must retain the above copyright 9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer. 10 # notice, this list of conditions and the following disclaimer.
(...skipping 22 matching lines...) Expand all
33 import shutil 33 import shutil
34 import unittest 34 import unittest
35 35
36 from webkitpy.common.system.executive import Executive, ScriptError 36 from webkitpy.common.system.executive import Executive, ScriptError
37 from webkitpy.common.system.executive_mock import MockExecutive 37 from webkitpy.common.system.executive_mock import MockExecutive
38 from webkitpy.common.system.filesystem import FileSystem 38 from webkitpy.common.system.filesystem import FileSystem
39 from webkitpy.common.system.filesystem_mock import MockFileSystem 39 from webkitpy.common.system.filesystem_mock import MockFileSystem
40 from webkitpy.common.checkout.scm.detection import detect_scm_system 40 from webkitpy.common.checkout.scm.detection import detect_scm_system
41 from webkitpy.common.checkout.scm.git import Git, AmbiguousCommitError 41 from webkitpy.common.checkout.scm.git import Git, AmbiguousCommitError
42 from webkitpy.common.checkout.scm.scm import SCM 42 from webkitpy.common.checkout.scm.scm import SCM
43 from webkitpy.common.checkout.scm.svn import SVN
44 43
45 44
46 # We cache the mock SVN repo so that we don't create it again for each call to a n SVNTest or GitTest test_ method. 45 # We cache the mock SVN repo so that we don't create it again for each call to a n SVNTest or GitTest test_ method.
47 # We store it in a global variable so that we can delete this cached repo on exi t(3). 46 # We store it in a global variable so that we can delete this cached repo on exi t(3).
48 original_cwd = None 47 original_cwd = None
49 cached_svn_repo_path = None 48 cached_svn_repo_path = None
50 49
51 @atexit.register 50 @atexit.register
52 def delete_cached_svn_repo_at_exit(): 51 def delete_cached_svn_repo_at_exit():
53 if cached_svn_repo_path: 52 if cached_svn_repo_path:
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 def _shared_test_move_recursive(self): 246 def _shared_test_move_recursive(self):
248 self._mkdir("added_dir") 247 self._mkdir("added_dir")
249 self._write_text_file('added_dir/added_file', 'new stuff') 248 self._write_text_file('added_dir/added_file', 'new stuff')
250 self._write_text_file('added_dir/another_added_file', 'more new stuff') 249 self._write_text_file('added_dir/another_added_file', 'more new stuff')
251 self.scm.add('added_dir') 250 self.scm.add('added_dir')
252 self.scm.move('added_dir', 'moved_dir') 251 self.scm.move('added_dir', 'moved_dir')
253 self.assertIn('moved_dir/added_file', self.scm._added_files()) 252 self.assertIn('moved_dir/added_file', self.scm._added_files())
254 self.assertIn('moved_dir/another_added_file', self.scm._added_files()) 253 self.assertIn('moved_dir/another_added_file', self.scm._added_files())
255 254
256 255
257 class SVNTest(SCMTestBase):
258 def setUp(self):
259 super(SVNTest, self).setUp()
260 self._set_up_svn_checkout()
261 self._chdir(self.svn_checkout_path)
262 self.scm = detect_scm_system(self.svn_checkout_path)
263 self.scm.svn_server_realm = None
264
265 def tearDown(self):
266 super(SVNTest, self).tearDown()
267 self._tear_down_svn_checkout()
268
269 def test_detect_scm_system_relative_url(self):
270 scm = detect_scm_system(".")
271 # I wanted to assert that we got the right path, but there was some
272 # crazy magic with temp folder names that I couldn't figure out.
273 self.assertTrue(scm.checkout_root)
274
275 def test_detection(self):
276 self.assertEqual(self.scm.display_name(), "svn")
277 self.assertEqual(self.scm.supports_local_commits(), False)
278
279 def test_add_recursively(self):
280 self._shared_test_add_recursively()
281
282 def test_delete(self):
283 self._chdir(self.svn_checkout_path)
284 self.scm.delete("test_file")
285 self.assertIn("test_file", self.scm._deleted_files())
286
287 def test_delete_list(self):
288 self._chdir(self.svn_checkout_path)
289 self.scm.delete_list(["test_file", "test_file2"])
290 self.assertIn("test_file", self.scm._deleted_files())
291 self.assertIn("test_file2", self.scm._deleted_files())
292
293 def test_delete_recursively(self):
294 self._shared_test_delete_recursively()
295
296 def test_delete_recursively_or_not(self):
297 self._shared_test_delete_recursively_or_not()
298
299 def test_move(self):
300 self._shared_test_move()
301
302 def test_move_recursive(self):
303 self._shared_test_move_recursive()
304
305
306 class GitTest(SCMTestBase): 256 class GitTest(SCMTestBase):
307 def setUp(self): 257 def setUp(self):
308 super(GitTest, self).setUp() 258 super(GitTest, self).setUp()
309 self._set_up_git_checkouts() 259 self._set_up_git_checkouts()
310 260
311 def tearDown(self): 261 def tearDown(self):
312 super(GitTest, self).tearDown() 262 super(GitTest, self).tearDown()
313 self._tear_down_git_checkouts() 263 self._tear_down_git_checkouts()
314 264
315 def _set_up_git_checkouts(self): 265 def _set_up_git_checkouts(self):
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 def test_exists(self): 305 def test_exists(self):
356 scm = self.untracking_scm 306 scm = self.untracking_scm
357 self._shared_test_exists(scm, scm.commit_locally_with_message) 307 self._shared_test_exists(scm, scm.commit_locally_with_message)
358 308
359 def test_rename_files(self): 309 def test_rename_files(self):
360 scm = self.tracking_scm 310 scm = self.tracking_scm
361 scm.move('foo_file', 'bar_file') 311 scm.move('foo_file', 'bar_file')
362 scm.commit_locally_with_message('message') 312 scm.commit_locally_with_message('message')
363 313
364 314
365 class GitSVNTest(SCMTestBase):
366 def setUp(self):
367 super(GitSVNTest, self).setUp()
368 self._set_up_svn_checkout()
369 self._set_up_gitsvn_checkout()
370 self.scm = detect_scm_system(self.git_checkout_path)
371 self.scm.svn_server_realm = None
372
373 def tearDown(self):
374 super(GitSVNTest, self).tearDown()
375 self._tear_down_svn_checkout()
376 self._tear_down_gitsvn_checkout()
377
378 def _set_up_gitsvn_checkout(self):
379 self.git_checkout_path = self._mkdtemp(suffix="git_test_checkout")
380 # --quiet doesn't make git svn silent
381 self._run_silent(['git', 'svn', 'clone', '-T', 'trunk', self.svn_repo_ur l, self.git_checkout_path])
382 self._chdir(self.git_checkout_path)
383 self.git_v2 = self._run(['git', '--version']).startswith('git version 2' )
384 if self.git_v2:
385 # The semantics of 'git svn clone -T' changed in v2 (apparently), so the branch names are different.
386 # This works around it, for compatibility w/ v1.
387 self._run_silent(['git', 'branch', 'trunk', 'origin/trunk'])
388
389 def _tear_down_gitsvn_checkout(self):
390 self._rmtree(self.git_checkout_path)
391
392 def test_detection(self):
393 self.assertEqual(self.scm.display_name(), "git")
394 self.assertEqual(self.scm.supports_local_commits(), True)
395
396 def test_read_git_config(self):
397 key = 'test.git-config'
398 value = 'git-config value'
399 self._run(['git', 'config', key, value])
400 self.assertEqual(self.scm.read_git_config(key), value)
401
402 def test_local_commits(self):
403 test_file = self._join(self.git_checkout_path, 'test_file')
404 self._write_text_file(test_file, 'foo')
405 self._run(['git', 'commit', '-a', '-m', 'local commit'])
406
407 self.assertEqual(len(self.scm._local_commits()), 1)
408
409 def test_discard_local_commits(self):
410 test_file = self._join(self.git_checkout_path, 'test_file')
411 self._write_text_file(test_file, 'foo')
412 self._run(['git', 'commit', '-a', '-m', 'local commit'])
413
414 self.assertEqual(len(self.scm._local_commits()), 1)
415 self.scm._discard_local_commits()
416 self.assertEqual(len(self.scm._local_commits()), 0)
417
418 def test_delete_branch(self):
419 new_branch = 'foo'
420
421 self._run(['git', 'checkout', '-b', new_branch])
422 self.assertEqual(self._run(['git', 'symbolic-ref', 'HEAD']).strip(), 're fs/heads/' + new_branch)
423
424 self._run(['git', 'checkout', '-b', 'bar'])
425 self.scm.delete_branch(new_branch)
426
427 self.assertNotRegexpMatches(self._run(['git', 'branch']), r'foo')
428
429 def test_rebase_in_progress(self):
430 svn_test_file = self._join(self.svn_checkout_path, 'test_file')
431 self._write_text_file(svn_test_file, "svn_checkout")
432 self._run(['svn', 'commit', '--message', 'commit to conflict with git co mmit'], cwd=self.svn_checkout_path)
433
434 git_test_file = self._join(self.git_checkout_path, 'test_file')
435 self._write_text_file(git_test_file, "git_checkout")
436 self._run(['git', 'commit', '-a', '-m', 'commit to be thrown away by reb ase abort'])
437
438 # Should fail due to a conflict leaving us mid-rebase.
439 # we use self._run_slient because --quiet doesn't actually make git svn silent.
440 self.assertRaises(ScriptError, self._run_silent, ['git', 'svn', '--quiet ', 'rebase'])
441
442 self.assertTrue(self.scm._rebase_in_progress())
443
444 # Make sure our cleanup works.
445 self.scm._discard_working_directory_changes()
446 self.assertFalse(self.scm._rebase_in_progress())
447
448 # Make sure cleanup doesn't throw when no rebase is in progress.
449 self.scm._discard_working_directory_changes()
450
451 def _local_commit(self, filename, contents, message):
452 self._write_text_file(filename, contents)
453 self._run(['git', 'add', filename])
454 self.scm.commit_locally_with_message(message)
455
456 def _one_local_commit(self):
457 self._local_commit('test_file_commit1', 'more test content', 'another te st commit')
458
459 def _one_local_commit_plus_working_copy_changes(self):
460 self._one_local_commit()
461 self._write_text_file('test_file_commit2', 'still more test content')
462 self._run(['git', 'add', 'test_file_commit2'])
463
464 def _second_local_commit(self):
465 self._local_commit('test_file_commit2', 'still more test content', 'yet another test commit')
466
467 def _two_local_commits(self):
468 self._one_local_commit()
469 self._second_local_commit()
470
471 def _three_local_commits(self):
472 self._local_commit('test_file_commit0', 'more test content', 'another te st commit')
473 self._two_local_commits()
474
475 def test_locally_commit_all_working_copy_changes(self):
476 self._local_commit('test_file', 'test content', 'test commit')
477 self._write_text_file('test_file', 'changed test content')
478 self.assertTrue(self.scm.has_working_directory_changes())
479 self.scm.commit_locally_with_message('all working copy changes')
480 self.assertFalse(self.scm.has_working_directory_changes())
481
482 def test_locally_commit_no_working_copy_changes(self):
483 self._local_commit('test_file', 'test content', 'test commit')
484 self._write_text_file('test_file', 'changed test content')
485 self.assertTrue(self.scm.has_working_directory_changes())
486 self.assertRaises(ScriptError, self.scm.commit_locally_with_message, 'no working copy changes', False)
487
488 def _test_upstream_branch(self):
489 self._run(['git', 'checkout', '-t', '-b', 'my-branch'])
490 self._run(['git', 'checkout', '-t', '-b', 'my-second-branch'])
491 self.assertEqual(self.scm._upstream_branch(), 'my-branch')
492
493 def test_remote_branch_ref(self):
494 remote_branch_ref = self.scm._remote_branch_ref()
495 if self.git_v2:
496 self.assertEqual(remote_branch_ref, 'refs/remotes/origin/trunk')
497 else:
498 self.assertEqual(remote_branch_ref, 'refs/remotes/trunk')
499
500 def test_create_patch_local_plus_working_copy(self):
501 self._one_local_commit_plus_working_copy_changes()
502 patch = self.scm.create_patch()
503 self.assertRegexpMatches(patch, r'test_file_commit1')
504 self.assertRegexpMatches(patch, r'test_file_commit2')
505
506 def test_create_patch(self):
507 self._one_local_commit_plus_working_copy_changes()
508 patch = self.scm.create_patch()
509 self.assertRegexpMatches(patch, r'test_file_commit2')
510 self.assertRegexpMatches(patch, r'test_file_commit1')
511 self.assertRegexpMatches(patch, r'Subversion Revision: 5')
512
513 def test_create_patch_after_merge(self):
514 self._run(['git', 'checkout', '-b', 'dummy-branch', 'trunk~3'])
515 self._one_local_commit()
516 self._run(['git', 'merge', 'trunk'])
517
518 patch = self.scm.create_patch()
519 self.assertRegexpMatches(patch, r'test_file_commit1')
520 self.assertRegexpMatches(patch, r'Subversion Revision: 5')
521
522 def test_create_patch_with_changed_files(self):
523 self._one_local_commit_plus_working_copy_changes()
524 patch = self.scm.create_patch(changed_files=['test_file_commit2'])
525 self.assertRegexpMatches(patch, r'test_file_commit2')
526
527 def test_create_patch_with_rm_and_changed_files(self):
528 self._one_local_commit_plus_working_copy_changes()
529 self._remove('test_file_commit1')
530 patch = self.scm.create_patch()
531 patch_with_changed_files = self.scm.create_patch(changed_files=['test_fi le_commit1', 'test_file_commit2'])
532 self.assertEqual(patch, patch_with_changed_files)
533
534 def test_create_patch_git_commit(self):
535 self._two_local_commits()
536 patch = self.scm.create_patch(git_commit="HEAD^")
537 self.assertRegexpMatches(patch, r'test_file_commit1')
538 self.assertNotRegexpMatches(patch, r'test_file_commit2')
539
540 def test_create_patch_git_commit_range(self):
541 self._three_local_commits()
542 patch = self.scm.create_patch(git_commit="HEAD~2..HEAD")
543 self.assertNotRegexpMatches(patch, r'test_file_commit0')
544 self.assertRegexpMatches(patch, r'test_file_commit2')
545 self.assertRegexpMatches(patch, r'test_file_commit1')
546
547 def test_create_patch_working_copy_only(self):
548 self._one_local_commit_plus_working_copy_changes()
549 patch = self.scm.create_patch(git_commit="HEAD....")
550 self.assertNotRegexpMatches(patch, r'test_file_commit1')
551 self.assertRegexpMatches(patch, r'test_file_commit2')
552
553 def test_create_patch_multiple_local_commits(self):
554 self._two_local_commits()
555 patch = self.scm.create_patch()
556 self.assertRegexpMatches(patch, r'test_file_commit2')
557 self.assertRegexpMatches(patch, r'test_file_commit1')
558
559 def test_create_patch_not_synced(self):
560 self._run(['git', 'checkout', '-b', 'my-branch', 'trunk~3'])
561 self._two_local_commits()
562 patch = self.scm.create_patch()
563 self.assertNotRegexpMatches(patch, r'test_file2')
564 self.assertRegexpMatches(patch, r'test_file_commit2')
565 self.assertRegexpMatches(patch, r'test_file_commit1')
566
567 def test_create_binary_patch(self):
568 # Create a git binary patch and check the contents.
569 test_file_name = 'binary_file'
570 test_file_path = self.fs.join(self.git_checkout_path, test_file_name)
571 file_contents = ''.join(map(chr, range(256)))
572 self._write_binary_file(test_file_path, file_contents)
573 self._run(['git', 'add', test_file_name])
574 patch = self.scm.create_patch()
575 self.assertRegexpMatches(patch, r'\nliteral 0\n')
576 self.assertRegexpMatches(patch, r'\nliteral 256\n')
577
578 # Check if we can create a patch from a local commit.
579 self._write_binary_file(test_file_path, file_contents)
580 self._run(['git', 'add', test_file_name])
581 self._run(['git', 'commit', '-m', 'binary diff'])
582
583 patch_from_local_commit = self.scm.create_patch('HEAD')
584 self.assertRegexpMatches(patch_from_local_commit, r'\nliteral 0\n')
585 self.assertRegexpMatches(patch_from_local_commit, r'\nliteral 256\n')
586
587
588 def test_changed_files_local_plus_working_copy(self):
589 self._one_local_commit_plus_working_copy_changes()
590 files = self.scm.changed_files()
591 self.assertIn('test_file_commit1', files)
592 self.assertIn('test_file_commit2', files)
593
594 # working copy should *not* be in the list.
595 files = self.scm.changed_files('trunk..')
596 self.assertIn('test_file_commit1', files)
597 self.assertNotIn('test_file_commit2', files)
598
599 # working copy *should* be in the list.
600 files = self.scm.changed_files('trunk....')
601 self.assertIn('test_file_commit1', files)
602 self.assertIn('test_file_commit2', files)
603
604 def test_changed_files_git_commit(self):
605 self._two_local_commits()
606 files = self.scm.changed_files(git_commit="HEAD^")
607 self.assertIn('test_file_commit1', files)
608 self.assertNotIn('test_file_commit2', files)
609
610 def test_changed_files_git_commit_range(self):
611 self._three_local_commits()
612 files = self.scm.changed_files(git_commit="HEAD~2..HEAD")
613 self.assertNotIn('test_file_commit0', files)
614 self.assertIn('test_file_commit1', files)
615 self.assertIn('test_file_commit2', files)
616
617 def test_changed_files_working_copy_only(self):
618 self._one_local_commit_plus_working_copy_changes()
619 files = self.scm.changed_files(git_commit="HEAD....")
620 self.assertNotIn('test_file_commit1', files)
621 self.assertIn('test_file_commit2', files)
622
623 def test_changed_files_multiple_local_commits(self):
624 self._two_local_commits()
625 files = self.scm.changed_files()
626 self.assertIn('test_file_commit2', files)
627 self.assertIn('test_file_commit1', files)
628
629 def test_changed_files_not_synced(self):
630 self._run(['git', 'checkout', '-b', 'my-branch', 'trunk~3'])
631 self._two_local_commits()
632 files = self.scm.changed_files()
633 self.assertNotIn('test_file2', files)
634 self.assertIn('test_file_commit2', files)
635 self.assertIn('test_file_commit1', files)
636
637 def test_changed_files_upstream(self):
638 self._run(['git', 'checkout', '-t', '-b', 'my-branch'])
639 self._one_local_commit()
640 self._run(['git', 'checkout', '-t', '-b', 'my-second-branch'])
641 self._second_local_commit()
642 self._write_text_file('test_file_commit0', 'more test content')
643 self._run(['git', 'add', 'test_file_commit0'])
644
645 # equivalent to 'git diff my-branch..HEAD, should not include working ch anges
646 files = self.scm.changed_files(git_commit='UPSTREAM..')
647 self.assertNotIn('test_file_commit1', files)
648 self.assertIn('test_file_commit2', files)
649 self.assertNotIn('test_file_commit0', files)
650
651 # equivalent to 'git diff my-branch', *should* include working changes
652 files = self.scm.changed_files(git_commit='UPSTREAM....')
653 self.assertNotIn('test_file_commit1', files)
654 self.assertIn('test_file_commit2', files)
655 self.assertIn('test_file_commit0', files)
656
657 def test_add_recursively(self):
658 self._shared_test_add_recursively()
659
660 def test_delete(self):
661 self._two_local_commits()
662 self.scm.delete('test_file_commit1')
663 self.assertIn("test_file_commit1", self.scm._deleted_files())
664
665 def test_delete_list(self):
666 self._two_local_commits()
667 self.scm.delete_list(["test_file_commit1", "test_file_commit2"])
668 self.assertIn("test_file_commit1", self.scm._deleted_files())
669 self.assertIn("test_file_commit2", self.scm._deleted_files())
670
671 def test_delete_recursively(self):
672 self._shared_test_delete_recursively()
673
674 def test_delete_recursively_or_not(self):
675 self._shared_test_delete_recursively_or_not()
676
677 def test_move(self):
678 self._shared_test_move()
679
680 def test_move_recursive(self):
681 self._shared_test_move_recursive()
682
683 def test_exists(self):
684 self._shared_test_exists(self.scm, self.scm.commit_locally_with_message)
685
686
687 class GitTestWithMock(SCMTestBase): 315 class GitTestWithMock(SCMTestBase):
688 def make_scm(self): 316 def make_scm(self):
689 scm = Git(cwd=".", executive=MockExecutive(), filesystem=MockFileSystem( )) 317 scm = Git(cwd=".", executive=MockExecutive(), filesystem=MockFileSystem( ))
690 scm.read_git_config = lambda *args, **kw: "MOCKKEY:MOCKVALUE" 318 scm.read_git_config = lambda *args, **kw: "MOCKKEY:MOCKVALUE"
691 return scm 319 return scm
692 320
693 def test_timestamp_of_revision(self): 321 def test_timestamp_of_revision(self):
694 scm = self.make_scm() 322 scm = self.make_scm()
695 scm.find_checkout_root = lambda path: '' 323 scm.find_checkout_root = lambda path: ''
696 scm._run_git = lambda args: 'Date: 2013-02-08 08:05:49 +0000' 324 scm._run_git = lambda args: 'Date: 2013-02-08 08:05:49 +0000'
697 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013- 02-08T08:05:49Z') 325 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013- 02-08T08:05:49Z')
698 326
699 scm._run_git = lambda args: 'Date: 2013-02-08 01:02:03 +0130' 327 scm._run_git = lambda args: 'Date: 2013-02-08 01:02:03 +0130'
700 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013- 02-07T23:32:03Z') 328 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013- 02-07T23:32:03Z')
701 329
702 scm._run_git = lambda args: 'Date: 2013-02-08 01:55:21 -0800' 330 scm._run_git = lambda args: 'Date: 2013-02-08 01:55:21 -0800'
703 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013- 02-08T09:55:21Z') 331 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013- 02-08T09:55:21Z')
OLDNEW
« no previous file with comments | « sky/tools/webkitpy/common/checkout/scm/detection.py ('k') | sky/tools/webkitpy/common/checkout/scm/svn.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698