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

Side by Side Diff: tests/gclient_scm_test.py

Issue 227163002: Revamped terminal output for update. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: rebase Created 6 years, 8 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) 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 gclient_scm.py.""" 6 """Unit tests for gclient_scm.py."""
7 7
8 # pylint: disable=E1103 8 # pylint: disable=E1103
9 9
10 # Import before super_mox to keep valid references. 10 # Import before super_mox to keep valid references.
11 from shutil import rmtree 11 from shutil import rmtree
12 from subprocess import Popen, PIPE, STDOUT 12 from subprocess import Popen, PIPE, STDOUT
13 13
14 import logging 14 import logging
15 import os 15 import os
16 import re
16 import sys 17 import sys
17 import tempfile 18 import tempfile
18 import unittest 19 import unittest
19 20
20 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 21 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21 22
22 from testing_support.super_mox import mox, StdoutCheck, SuperMoxTestBase 23 from testing_support.super_mox import mox, StdoutCheck, SuperMoxTestBase
23 from testing_support.super_mox import TestCaseUtils 24 from testing_support.super_mox import TestCaseUtils
24 25
25 import gclient_scm 26 import gclient_scm
26 import subprocess2 27 import subprocess2
27 28
28 # Shortcut since this function is used often 29 # Shortcut since this function is used often
29 join = gclient_scm.os.path.join 30 join = gclient_scm.os.path.join
30 31
32 TIMESTAMP_RE = re.compile('\[[0-9]{1,2}:[0-9]{2}:[0-9]{2}\] (.*)', re.DOTALL)
33 def strip_timestamps(value):
34 lines = value.splitlines(True)
35 for i in xrange(len(lines)):
36 m = TIMESTAMP_RE.match(lines[i])
37 if m:
38 lines[i] = m.group(1)
39 return ''.join(lines)
31 40
32 # Access to a protected member XXX of a client class 41 # Access to a protected member XXX of a client class
33 # pylint: disable=W0212 42 # pylint: disable=W0212
34 43
35 44
36 class GCBaseTestCase(object): 45 class GCBaseTestCase(object):
37 def assertRaisesError(self, msg, fn, *args, **kwargs): 46 def assertRaisesError(self, msg, fn, *args, **kwargs):
38 """Like unittest's assertRaises() but checks for Gclient.Error.""" 47 """Like unittest's assertRaises() but checks for Gclient.Error."""
39 # pylint: disable=E1101 48 # pylint: disable=E1101
40 try: 49 try:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 self.revision = revision 91 self.revision = revision
83 self.manually_grab_svn_rev = True 92 self.manually_grab_svn_rev = True
84 self.deps_os = None 93 self.deps_os = None
85 self.force = force 94 self.force = force
86 self.reset = False 95 self.reset = False
87 self.nohooks = False 96 self.nohooks = False
88 # TODO(maruel): Test --jobs > 1. 97 # TODO(maruel): Test --jobs > 1.
89 self.jobs = 1 98 self.jobs = 1
90 self.delete_unversioned_trees = False 99 self.delete_unversioned_trees = False
91 100
101 def checkstdout(self, expected):
102 value = sys.stdout.getvalue()
103 sys.stdout.close()
104 # pylint: disable=E1101
105 self.assertEquals(expected, strip_timestamps(value))
106
92 def Options(self, *args, **kwargs): 107 def Options(self, *args, **kwargs):
93 return self.OptionsObject(*args, **kwargs) 108 return self.OptionsObject(*args, **kwargs)
94 109
95 def setUp(self): 110 def setUp(self):
96 BaseTestCase.setUp(self) 111 BaseTestCase.setUp(self)
97 self.url = self.SvnUrl() 112 self.url = self.SvnUrl()
98 113
99 def testUnsupportedSCM(self): 114 def testUnsupportedSCM(self):
100 args = ['gopher://foo', self.root_dir, self.relpath] 115 args = ['gopher://foo', self.root_dir, self.relpath]
101 exception_msg = 'No SCM found for url gopher://foo' 116 exception_msg = 'No SCM found for url gopher://foo'
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 file_list=files_list) 187 file_list=files_list)
173 188
174 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 189 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
175 ).AndReturn({'Revision': 100}) 190 ).AndReturn({'Revision': 100})
176 191
177 self.mox.ReplayAll() 192 self.mox.ReplayAll()
178 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 193 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
179 relpath=self.relpath) 194 relpath=self.relpath)
180 scm.revert(options, self.args, files_list) 195 scm.revert(options, self.args, files_list)
181 self.checkstdout( 196 self.checkstdout(
182 ('\n_____ %s is missing, synching instead\n' % self.relpath)) 197 ('_____ %s is missing, synching instead\n' % self.relpath))
183 198
184 def testRevertNoDotSvn(self): 199 def testRevertNoDotSvn(self):
185 options = self.Options(verbose=True, force=True) 200 options = self.Options(verbose=True, force=True)
186 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 201 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
187 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) 202 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False)
188 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) 203 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
189 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) 204 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
190 # Checkout. 205 # Checkout.
191 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 206 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
192 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 207 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 ).AndReturn(file_info) 424 ).AndReturn(file_info)
410 425
411 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 426 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
412 ).AndReturn({'Revision': 100}) 427 ).AndReturn({'Revision': 100})
413 428
414 self.mox.ReplayAll() 429 self.mox.ReplayAll()
415 files_list = [] 430 files_list = []
416 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 431 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
417 relpath=self.relpath) 432 relpath=self.relpath)
418 scm.update(options, (), files_list) 433 scm.update(options, (), files_list)
419 self.checkstdout('\n_____ %s at 42\n' % self.relpath) 434 self.checkstdout('_____ %s at 42\n' % self.relpath)
420 435
421 def testUpdateResetDeleteUnversionedTrees(self): 436 def testUpdateResetDeleteUnversionedTrees(self):
422 options = self.Options(verbose=True) 437 options = self.Options(verbose=True)
423 options.reset = True 438 options.reset = True
424 options.delete_unversioned_trees = True 439 options.delete_unversioned_trees = True
425 440
426 file_info = { 441 file_info = {
427 'Repository Root': 'blah', 442 'Repository Root': 'blah',
428 'URL': self.url, 443 'URL': self.url,
429 'UUID': 'ABC', 444 'UUID': 'ABC',
(...skipping 24 matching lines...) Expand all
454 469
455 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 470 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
456 ).AndReturn({'Revision': 100}) 471 ).AndReturn({'Revision': 100})
457 472
458 self.mox.ReplayAll() 473 self.mox.ReplayAll()
459 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 474 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
460 relpath=self.relpath) 475 relpath=self.relpath)
461 files_list = [] 476 files_list = []
462 scm.update(options, (), files_list) 477 scm.update(options, (), files_list)
463 self.checkstdout( 478 self.checkstdout(
464 ('\n_____ %s at 42\n' 479 ('_____ %s at 42\n'
465 '\n_____ removing unversioned directory dir\n') % self.relpath) 480 '_____ removing unversioned directory dir\n') % self.relpath)
466 481
467 def testUpdateSingleCheckout(self): 482 def testUpdateSingleCheckout(self):
468 options = self.Options(verbose=True) 483 options = self.Options(verbose=True)
469 file_info = { 484 file_info = {
470 'URL': self.url, 485 'URL': self.url,
471 'Revision': 42, 486 'Revision': 42,
472 } 487 }
473 488
474 # Checks to make sure that we support svn co --depth. 489 # Checks to make sure that we support svn co --depth.
475 gclient_scm.scm.SVN.current_version = None 490 gclient_scm.scm.SVN.current_version = None
(...skipping 26 matching lines...) Expand all
502 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 517 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
503 ).AndReturn(file_info) 518 ).AndReturn(file_info)
504 519
505 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 520 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
506 ).AndReturn({'Revision': 100}) 521 ).AndReturn({'Revision': 100})
507 522
508 self.mox.ReplayAll() 523 self.mox.ReplayAll()
509 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 524 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
510 relpath=self.relpath) 525 relpath=self.relpath)
511 scm.updatesingle(options, ['DEPS'], files_list) 526 scm.updatesingle(options, ['DEPS'], files_list)
512 self.checkstdout('\n_____ %s at 42\n' % self.relpath) 527 self.checkstdout('_____ %s at 42\n' % self.relpath)
513 528
514 def testUpdateSingleCheckoutSVN14(self): 529 def testUpdateSingleCheckoutSVN14(self):
515 options = self.Options(verbose=True) 530 options = self.Options(verbose=True)
516 531
517 # Checks to make sure that we support svn co --depth. 532 # Checks to make sure that we support svn co --depth.
518 gclient_scm.scm.SVN.current_version = None 533 gclient_scm.scm.SVN.current_version = None
519 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 534 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
520 ).AndReturn('1.4.4') 535 ).AndReturn('1.4.4')
521 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 536 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
522 537
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 ).AndReturn(file_info) 589 ).AndReturn(file_info)
575 590
576 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 591 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
577 ).AndReturn({'Revision': 100}) 592 ).AndReturn({'Revision': 100})
578 593
579 self.mox.ReplayAll() 594 self.mox.ReplayAll()
580 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 595 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
581 relpath=self.relpath) 596 relpath=self.relpath)
582 scm.updatesingle(options, ['DEPS'], files_list) 597 scm.updatesingle(options, ['DEPS'], files_list)
583 self.checkstdout( 598 self.checkstdout(
584 ('\n_____ %s at 42\n' % self.relpath)) 599 ('_____ %s at 42\n' % self.relpath))
585 600
586 def testUpdateSingleUpdate(self): 601 def testUpdateSingleUpdate(self):
587 options = self.Options(verbose=True) 602 options = self.Options(verbose=True)
588 file_info = { 603 file_info = {
589 'URL': self.url, 604 'URL': self.url,
590 'Revision': 42, 605 'Revision': 42,
591 } 606 }
592 # Checks to make sure that we support svn co --depth. 607 # Checks to make sure that we support svn co --depth.
593 gclient_scm.scm.SVN.current_version = None 608 gclient_scm.scm.SVN.current_version = None
594 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 609 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
(...skipping 14 matching lines...) Expand all
609 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 624 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
610 ).AndReturn(file_info) 625 ).AndReturn(file_info)
611 626
612 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 627 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
613 ).AndReturn({'Revision': 100}) 628 ).AndReturn({'Revision': 100})
614 629
615 self.mox.ReplayAll() 630 self.mox.ReplayAll()
616 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 631 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
617 relpath=self.relpath) 632 relpath=self.relpath)
618 scm.updatesingle(options, ['DEPS'], files_list) 633 scm.updatesingle(options, ['DEPS'], files_list)
619 self.checkstdout('\n_____ %s at 42\n' % self.relpath) 634 self.checkstdout('_____ %s at 42\n' % self.relpath)
620 635
621 def testUpdateGit(self): 636 def testUpdateGit(self):
622 options = self.Options(verbose=True) 637 options = self.Options(verbose=True)
623 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') 638 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
624 gclient_scm.os.path.exists(file_path).AndReturn(True) 639 gclient_scm.os.path.exists(file_path).AndReturn(True)
625 640
626 self.mox.ReplayAll() 641 self.mox.ReplayAll()
627 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 642 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
628 relpath=self.relpath) 643 relpath=self.relpath)
629 file_list = [] 644 file_list = []
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 Add C 753 Add C
739 from :3 754 from :3
740 M 100644 :7 c 755 M 100644 :7 c
741 756
742 reset refs/heads/master 757 reset refs/heads/master
743 from :3 758 from :3
744 """ 759 """
745 def Options(self, *args, **kwargs): 760 def Options(self, *args, **kwargs):
746 return self.OptionsObject(*args, **kwargs) 761 return self.OptionsObject(*args, **kwargs)
747 762
763 def checkstdout(self, expected):
764 value = sys.stdout.getvalue()
765 sys.stdout.close()
766 # pylint: disable=E1101
767 self.assertEquals(expected, strip_timestamps(value))
768
748 @staticmethod 769 @staticmethod
749 def CreateGitRepo(git_import, path): 770 def CreateGitRepo(git_import, path):
750 """Do it for real.""" 771 """Do it for real."""
751 try: 772 try:
752 Popen(['git', 'init', '-q'], stdout=PIPE, stderr=STDOUT, 773 Popen(['git', 'init', '-q'], stdout=PIPE, stderr=STDOUT,
753 cwd=path).communicate() 774 cwd=path).communicate()
754 except OSError: 775 except OSError:
755 # git is not available, skip this test. 776 # git is not available, skip this test.
756 return False 777 return False
757 Popen(['git', 'fast-import', '--quiet'], stdin=PIPE, stdout=PIPE, 778 Popen(['git', 'fast-import', '--quiet'], stdin=PIPE, stdout=PIPE,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 return 909 return
889 options = self.Options() 910 options = self.Options()
890 file_path = join(self.base_path, 'a') 911 file_path = join(self.base_path, 'a')
891 open(file_path, 'a').writelines('touched\n') 912 open(file_path, 'a').writelines('touched\n')
892 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 913 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
893 relpath=self.relpath) 914 relpath=self.relpath)
894 file_list = [] 915 file_list = []
895 scm.status(options, self.args, file_list) 916 scm.status(options, self.args, file_list)
896 self.assertEquals(file_list, [file_path]) 917 self.assertEquals(file_list, [file_path])
897 self.checkstdout( 918 self.checkstdout(
898 ('\n________ running \'git diff --name-status ' 919 ('running \'git diff --name-status '
899 '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\n') % 920 '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\n') %
900 join(self.root_dir, '.')) 921 join(self.root_dir, '.'))
901 922
902 def testStatus2New(self): 923 def testStatus2New(self):
903 if not self.enabled: 924 if not self.enabled:
904 return 925 return
905 options = self.Options() 926 options = self.Options()
906 expected_file_list = [] 927 expected_file_list = []
907 for f in ['a', 'b']: 928 for f in ['a', 'b']:
908 file_path = join(self.base_path, f) 929 file_path = join(self.base_path, f)
909 open(file_path, 'a').writelines('touched\n') 930 open(file_path, 'a').writelines('touched\n')
910 expected_file_list.extend([file_path]) 931 expected_file_list.extend([file_path])
911 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 932 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
912 relpath=self.relpath) 933 relpath=self.relpath)
913 file_list = [] 934 file_list = []
914 scm.status(options, self.args, file_list) 935 scm.status(options, self.args, file_list)
915 expected_file_list = [join(self.base_path, x) for x in ['a', 'b']] 936 expected_file_list = [join(self.base_path, x) for x in ['a', 'b']]
916 self.assertEquals(sorted(file_list), expected_file_list) 937 self.assertEquals(sorted(file_list), expected_file_list)
917 self.checkstdout( 938 self.checkstdout(
918 ('\n________ running \'git diff --name-status ' 939 ('running \'git diff --name-status '
919 '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\nM\tb\n') % 940 '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\nM\tb\n') %
920 join(self.root_dir, '.')) 941 join(self.root_dir, '.'))
921 942
922 def testUpdateUpdate(self): 943 def testUpdateUpdate(self):
923 if not self.enabled: 944 if not self.enabled:
924 return 945 return
925 options = self.Options() 946 options = self.Options()
926 expected_file_list = [join(self.base_path, x) for x in ['a', 'b']] 947 expected_file_list = [join(self.base_path, x) for x in ['a', 'b']]
927 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 948 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
928 relpath=self.relpath) 949 relpath=self.relpath)
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 1239
1219 if __name__ == '__main__': 1240 if __name__ == '__main__':
1220 if '-v' in sys.argv: 1241 if '-v' in sys.argv:
1221 logging.basicConfig( 1242 logging.basicConfig(
1222 level=logging.DEBUG, 1243 level=logging.DEBUG,
1223 format='%(asctime).19s %(levelname)s %(filename)s:' 1244 format='%(asctime).19s %(levelname)s %(filename)s:'
1224 '%(lineno)s %(message)s') 1245 '%(lineno)s %(message)s')
1225 unittest.main() 1246 unittest.main()
1226 1247
1227 # vim: ts=2:sw=2:tw=80:et: 1248 # 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