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

Side by Side Diff: tests/gclient_scm_test.py

Issue 8161009: Restore 103787 (fix git progress message), and update test expectations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 9 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « gclient_utils.py ('k') | tests/gclient_smoketest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 gclient_scm.py.""" 6 """Unit tests for gclient_scm.py."""
7 7
8 # pylint: disable=E1101,E1103,W0403 8 # pylint: disable=E1101,E1103,W0403
9 9
10 # Import before super_mox to keep valid references. 10 # Import before super_mox to keep valid references.
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 relpath=self.relpath) 564 relpath=self.relpath)
565 file_list = [] 565 file_list = []
566 scm.update(options, None, file_list) 566 scm.update(options, None, file_list)
567 gclient_scm.os.remove(file_path) 567 gclient_scm.os.remove(file_path)
568 file_list = [] 568 file_list = []
569 scm.revert(options, self.args, file_list) 569 scm.revert(options, self.args, file_list)
570 self.assertEquals(file_list, [file_path]) 570 self.assertEquals(file_list, [file_path])
571 file_list = [] 571 file_list = []
572 scm.diff(options, self.args, file_list) 572 scm.diff(options, self.args, file_list)
573 self.assertEquals(file_list, []) 573 self.assertEquals(file_list, [])
574 self.checkstdout( 574 expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n'
575 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n'
576 'Fast-forward\n a | 1 +\n b | 1 +\n' 575 'Fast-forward\n a | 1 +\n b | 1 +\n'
577 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' 576 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n'
578 '________ running \'git reset --hard origin/master\' in \'%s\'\n' 577 '________ running \'git reset --hard origin/master\' in \'%s\'\n'
579 'HEAD is now at a7142dc Personalized\n') % 578 'HEAD is now at a7142dc Personalized\n') % join(self.root_dir, '.')
580 join(self.root_dir, '.')) 579 self.assertTrue(sys.stdout.getvalue().startswith(expectation))
580 sys.stdout.close()
581 581
582 def testRevertNone(self): 582 def testRevertNone(self):
583 if not self.enabled: 583 if not self.enabled:
584 return 584 return
585 options = self.Options() 585 options = self.Options()
586 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 586 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
587 relpath=self.relpath) 587 relpath=self.relpath)
588 file_list = [] 588 file_list = []
589 scm.update(options, None, file_list) 589 scm.update(options, None, file_list)
590 file_list = [] 590 file_list = []
(...skipping 20 matching lines...) Expand all
611 file_path = join(self.base_path, 'a') 611 file_path = join(self.base_path, 'a')
612 open(file_path, 'a').writelines('touched\n') 612 open(file_path, 'a').writelines('touched\n')
613 file_list = [] 613 file_list = []
614 scm.revert(options, self.args, file_list) 614 scm.revert(options, self.args, file_list)
615 self.assertEquals(file_list, [file_path]) 615 self.assertEquals(file_list, [file_path])
616 file_list = [] 616 file_list = []
617 scm.diff(options, self.args, file_list) 617 scm.diff(options, self.args, file_list)
618 self.assertEquals(file_list, []) 618 self.assertEquals(file_list, [])
619 self.assertEquals(scm.revinfo(options, self.args, None), 619 self.assertEquals(scm.revinfo(options, self.args, None),
620 'a7142dc9f0009350b96a11f372b6ea658592aa95') 620 'a7142dc9f0009350b96a11f372b6ea658592aa95')
621 self.checkstdout( 621 expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n'
622 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n'
623 'Fast-forward\n a | 1 +\n b | 1 +\n' 622 'Fast-forward\n a | 1 +\n b | 1 +\n'
624 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' 623 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n'
625 '________ running \'git reset --hard origin/master\' in \'%s\'\n' 624 '________ running \'git reset --hard origin/master\' in \'%s\'\n'
626 'HEAD is now at a7142dc Personalized\n') % 625 'HEAD is now at a7142dc Personalized\n') % join(self.root_dir, '.')
627 join(self.root_dir, '.')) 626 self.assertTrue(sys.stdout.getvalue().startswith(expectation))
627 sys.stdout.close()
628 628
629 def testRevertNew(self): 629 def testRevertNew(self):
630 if not self.enabled: 630 if not self.enabled:
631 return 631 return
632 options = self.Options() 632 options = self.Options()
633 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 633 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
634 relpath=self.relpath) 634 relpath=self.relpath)
635 file_list = [] 635 file_list = []
636 scm.update(options, None, file_list) 636 scm.update(options, None, file_list)
637 file_path = join(self.base_path, 'c') 637 file_path = join(self.base_path, 'c')
638 f = open(file_path, 'w') 638 f = open(file_path, 'w')
639 f.writelines('new\n') 639 f.writelines('new\n')
640 f.close() 640 f.close()
641 Popen(['git', 'add', 'c'], stdout=PIPE, 641 Popen(['git', 'add', 'c'], stdout=PIPE,
642 stderr=STDOUT, cwd=self.base_path).communicate() 642 stderr=STDOUT, cwd=self.base_path).communicate()
643 file_list = [] 643 file_list = []
644 scm.revert(options, self.args, file_list) 644 scm.revert(options, self.args, file_list)
645 self.assertEquals(file_list, [file_path]) 645 self.assertEquals(file_list, [file_path])
646 file_list = [] 646 file_list = []
647 scm.diff(options, self.args, file_list) 647 scm.diff(options, self.args, file_list)
648 self.assertEquals(file_list, []) 648 self.assertEquals(file_list, [])
649 self.assertEquals(scm.revinfo(options, self.args, None), 649 self.assertEquals(scm.revinfo(options, self.args, None),
650 'a7142dc9f0009350b96a11f372b6ea658592aa95') 650 'a7142dc9f0009350b96a11f372b6ea658592aa95')
651 self.checkstdout( 651 expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n'
652 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n'
653 'Fast-forward\n a | 1 +\n b | 1 +\n' 652 'Fast-forward\n a | 1 +\n b | 1 +\n'
654 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' 653 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n'
655 '________ running \'git reset --hard origin/master\' in \'%s\'\n' 654 '________ running \'git reset --hard origin/master\' in \'%s\'\n'
656 'HEAD is now at a7142dc Personalized\n') % 655 'HEAD is now at a7142dc Personalized\n') % join(self.root_dir, '.')
657 join(self.root_dir, '.')) 656 self.assertTrue(sys.stdout.getvalue().startswith(expectation))
657 sys.stdout.close()
658 658
659 def testStatusNew(self): 659 def testStatusNew(self):
660 if not self.enabled: 660 if not self.enabled:
661 return 661 return
662 options = self.Options() 662 options = self.Options()
663 file_path = join(self.base_path, 'a') 663 file_path = join(self.base_path, 'a')
664 open(file_path, 'a').writelines('touched\n') 664 open(file_path, 'a').writelines('touched\n')
665 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 665 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
666 relpath=self.relpath) 666 relpath=self.relpath)
667 file_list = [] 667 file_list = []
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 file_list = [] 706 file_list = []
707 scm.update(options, (), file_list) 707 scm.update(options, (), file_list)
708 self.assertEquals(len(file_list), 2) 708 self.assertEquals(len(file_list), 2)
709 self.assert_(gclient_scm.os.path.isfile(join(base_path, 'a'))) 709 self.assert_(gclient_scm.os.path.isfile(join(base_path, 'a')))
710 self.assertEquals(scm.revinfo(options, (), None), 710 self.assertEquals(scm.revinfo(options, (), None),
711 '069c602044c5388d2d15c3f875b057c852003458') 711 '069c602044c5388d2d15c3f875b057c852003458')
712 finally: 712 finally:
713 rmtree(root_dir) 713 rmtree(root_dir)
714 msg1 = ( 714 msg1 = (
715 "\n_____ foo at refs/heads/master\n\n" 715 "\n_____ foo at refs/heads/master\n\n"
716 "________ running 'git clone -b master --verbose %s %s' in '%s'\n" 716 "________ running 'git clone --progress -b master --verbose %s %s' "
717 "in '%s'\n"
717 "Initialized empty Git repository in %s\n") % ( 718 "Initialized empty Git repository in %s\n") % (
718 join(self.root_dir, '.', '.git'), 719 join(self.root_dir, '.', '.git'),
719 join(root_dir, 'foo'), 720 join(root_dir, 'foo'),
720 root_dir, 721 root_dir,
721 join(gclient_scm.os.path.realpath(root_dir), 'foo', '.git') + '/') 722 join(gclient_scm.os.path.realpath(root_dir), 'foo', '.git') + '/')
722 msg2 = ( 723 msg2 = (
723 "\n_____ foo at refs/heads/master\n\n" 724 "\n_____ foo at refs/heads/master\n\n"
724 "________ running 'git clone -b master --verbose %s %s' in '%s'\n" 725 "________ running 'git clone --progress -b master --verbose %s %s'"
726 " in '%s'\n"
725 "Cloning into %s...\ndone.\n") % ( 727 "Cloning into %s...\ndone.\n") % (
726 join(self.root_dir, '.', '.git'), 728 join(self.root_dir, '.', '.git'),
727 join(root_dir, 'foo'), 729 join(root_dir, 'foo'),
728 root_dir, 730 root_dir,
729 join(gclient_scm.os.path.realpath(root_dir), 'foo')) 731 join(gclient_scm.os.path.realpath(root_dir), 'foo'))
730 out = sys.stdout.getvalue() 732 out = sys.stdout.getvalue()
731 sys.stdout.close() 733 sys.stdout.close()
732 sys.stdout = self._old_stdout 734 sys.stdout = self._old_stdout
733 self.assertTrue(out in (msg1, msg2), (out, msg1, msg2)) 735 self.assertTrue(out in (msg1, msg2), (out, msg1, msg2))
734 736
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 options.revision = 'unmanaged' 843 options.revision = 'unmanaged'
842 scm.update(options, (), file_list) 844 scm.update(options, (), file_list)
843 self.assertEquals(len(file_list), 2) 845 self.assertEquals(len(file_list), 2)
844 self.assert_(gclient_scm.os.path.isfile(join(base_path, 'a'))) 846 self.assert_(gclient_scm.os.path.isfile(join(base_path, 'a')))
845 self.assertEquals(scm.revinfo(options, (), None), 847 self.assertEquals(scm.revinfo(options, (), None),
846 '069c602044c5388d2d15c3f875b057c852003458') 848 '069c602044c5388d2d15c3f875b057c852003458')
847 finally: 849 finally:
848 rmtree(root_dir) 850 rmtree(root_dir)
849 msg1 = ( 851 msg1 = (
850 "\n_____ foo at refs/heads/master\n\n" 852 "\n_____ foo at refs/heads/master\n\n"
851 "________ running 'git clone -b master --verbose %s %s' in '%s'\n" 853 "________ running 'git clone --progress -b master --verbose %s %s'"
854 " in '%s'\n"
852 "Initialized empty Git repository in %s\n") % ( 855 "Initialized empty Git repository in %s\n") % (
853 join(self.root_dir, '.', '.git'), 856 join(self.root_dir, '.', '.git'),
854 join(root_dir, 'foo'), 857 join(root_dir, 'foo'),
855 root_dir, 858 root_dir,
856 join(gclient_scm.os.path.realpath(root_dir), 'foo', '.git') + '/') 859 join(gclient_scm.os.path.realpath(root_dir), 'foo', '.git') + '/')
857 msg2 = ( 860 msg2 = (
858 "\n_____ foo at refs/heads/master\n\n" 861 "\n_____ foo at refs/heads/master\n\n"
859 "________ running 'git clone -b master --verbose %s %s' in '%s'\n" 862 "________ running 'git clone --progress -b master --verbose %s %s'"
863 " in '%s'\n"
860 "Cloning into %s...\ndone.\n") % ( 864 "Cloning into %s...\ndone.\n") % (
861 join(self.root_dir, '.', '.git'), 865 join(self.root_dir, '.', '.git'),
862 join(root_dir, 'foo'), 866 join(root_dir, 'foo'),
863 root_dir, 867 root_dir,
864 join(gclient_scm.os.path.realpath(root_dir), 'foo')) 868 join(gclient_scm.os.path.realpath(root_dir), 'foo'))
865 out = sys.stdout.getvalue() 869 out = sys.stdout.getvalue()
866 sys.stdout.close() 870 sys.stdout.close()
867 sys.stdout = self._old_stdout 871 sys.stdout = self._old_stdout
868 self.assertTrue(out in (msg1, msg2), (out, msg1, msg2)) 872 self.assertTrue(out in (msg1, msg2), (out, msg1, msg2))
869 873
(...skipping 15 matching lines...) Expand all
885 889
886 if __name__ == '__main__': 890 if __name__ == '__main__':
887 if '-v' in sys.argv: 891 if '-v' in sys.argv:
888 logging.basicConfig( 892 logging.basicConfig(
889 level=logging.DEBUG, 893 level=logging.DEBUG,
890 format='%(asctime).19s %(levelname)s %(filename)s:' 894 format='%(asctime).19s %(levelname)s %(filename)s:'
891 '%(lineno)s %(message)s') 895 '%(lineno)s %(message)s')
892 unittest.main() 896 unittest.main()
893 897
894 # vim: ts=2:sw=2:tw=80:et: 898 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient_utils.py ('k') | tests/gclient_smoketest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698