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

Side by Side Diff: tests/gclient_scm_test.py

Issue 548553003: Make check for dirty index work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: lint Created 6 years, 3 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_scm.py ('k') | no next file » | 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.
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 Popen(['git', 'config', 'user.name', 'Some User'], stdout=PIPE, 912 Popen(['git', 'config', 'user.name', 'Some User'], stdout=PIPE,
913 stderr=STDOUT, cwd=path).communicate() 913 stderr=STDOUT, cwd=path).communicate()
914 return True 914 return True
915 915
916 def _GetAskForDataCallback(self, expected_prompt, return_value): 916 def _GetAskForDataCallback(self, expected_prompt, return_value):
917 def AskForData(prompt, options): 917 def AskForData(prompt, options):
918 self.assertEquals(prompt, expected_prompt) 918 self.assertEquals(prompt, expected_prompt)
919 return return_value 919 return return_value
920 return AskForData 920 return AskForData
921 921
922 def getCurrentBranch(self):
923 # Returns name of current branch or HEAD for detached HEAD
924 branch = gclient_scm.scm.GIT.Capture(['rev-parse', '--abbrev-ref', 'HEAD'],
925 cwd=self.base_path)
926 if branch == 'HEAD':
927 return None
928 return branch
929
922 def setUp(self): 930 def setUp(self):
923 TestCaseUtils.setUp(self) 931 TestCaseUtils.setUp(self)
924 unittest.TestCase.setUp(self) 932 unittest.TestCase.setUp(self)
925 self.url = 'git://foo' 933 self.url = 'git://foo'
926 # The .git suffix allows gclient_scm to recognize the dir as a git repo 934 # The .git suffix allows gclient_scm to recognize the dir as a git repo
927 # when cloning it locally 935 # when cloning it locally
928 self.root_dir = tempfile.mkdtemp('.git') 936 self.root_dir = tempfile.mkdtemp('.git')
929 self.relpath = '.' 937 self.relpath = '.'
930 self.base_path = join(self.root_dir, self.relpath) 938 self.base_path = join(self.root_dir, self.relpath)
931 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) 939 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 file_path = join(self.base_path, 'b') 1201 file_path = join(self.base_path, 'b')
1194 open(file_path, 'w').writelines('conflict\n') 1202 open(file_path, 'w').writelines('conflict\n')
1195 scm._Run(['commit', '-am', 'test'], options) 1203 scm._Run(['commit', '-am', 'test'], options)
1196 scm._AskForData = self._GetAskForDataCallback( 1204 scm._AskForData = self._GetAskForDataCallback(
1197 'Cannot fast-forward merge, attempt to rebase? ' 1205 'Cannot fast-forward merge, attempt to rebase? '
1198 '(y)es / (q)uit / (s)kip : ', 'y') 1206 '(y)es / (q)uit / (s)kip : ', 'y')
1199 exception = ('Conflict while rebasing this branch.\n' 1207 exception = ('Conflict while rebasing this branch.\n'
1200 'Fix the conflict and run gclient again.\n' 1208 'Fix the conflict and run gclient again.\n'
1201 'See \'man git-rebase\' for details.\n') 1209 'See \'man git-rebase\' for details.\n')
1202 self.assertRaisesError(exception, scm.update, options, (), []) 1210 self.assertRaisesError(exception, scm.update, options, (), [])
1211 # The merge conflict creates a detached head with local changes, so another
1212 # scm.update attempt should fail (in a different way) because of that (a
1213 # rather roundabout way to test that condition).
1203 exception = ('\n____ . at refs/remotes/origin/master\n' 1214 exception = ('\n____ . at refs/remotes/origin/master\n'
1204 '\tYou have unstaged changes.\n' 1215 '\tYou have unstaged changes.\n'
1205 '\tPlease commit, stash, or reset.\n') 1216 '\tPlease commit, stash, or reset.\n')
1206 self.assertRaisesError(exception, scm.update, options, (), []) 1217 self.assertRaisesError(exception, scm.update, options, (), [])
1207 sys.stdout.close() 1218 sys.stdout.close()
1208 1219
1220 def testUpdateDetachedConflict(self):
1221 # Detached head mode should refuse to update when there are local changes
1222 # (staged or unstaged).
1223 if not self.enabled:
1224 return
1225 options = self.Options()
1226 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1227 relpath=self.relpath)
1228 scm._Run(['checkout', '-q', 'a7142dc9f0009350b96a11f372b6ea658592aa95'],
1229 options)
1230 # Make sure it checked out a detached HEAD
1231 self.assertEquals(self.getCurrentBranch(), None)
1232 file_path = join(self.base_path, 'b')
1233 open(file_path, 'w').writelines('conflict\n')
1234 # Unstaged
1235 # TODO(all): Ick. Gclient should really have exception subclasses or
1236 # something, so we can avoid this fragile exception message matching.
1237 exception = ('\n____ . at refs/remotes/origin/master\n'
1238 '\tYou have unstaged changes.\n'
1239 '\tPlease commit, stash, or reset.\n')
1240 self.assertRaisesError(exception, scm.update, options, (), [])
1241 # Staged
1242 scm._Run(['add', 'b'], options)
1243 exception = ('\n____ . at refs/remotes/origin/master\n'
1244 '\tYour index contains uncommitted changes\n'
1245 '\tPlease commit, stash, or reset.\n')
1246 self.assertRaisesError(exception, scm.update, options, (), [])
1247 sys.stdout.close()
1248
1209 def testRevinfo(self): 1249 def testRevinfo(self):
1210 if not self.enabled: 1250 if not self.enabled:
1211 return 1251 return
1212 options = self.Options() 1252 options = self.Options()
1213 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1253 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1214 relpath=self.relpath) 1254 relpath=self.relpath)
1215 rev_info = scm.revinfo(options, (), None) 1255 rev_info = scm.revinfo(options, (), None)
1216 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') 1256 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
1217 1257
1218 1258
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 sys.stdout.close() 1462 sys.stdout.close()
1423 # pylint: disable=E1101 1463 # pylint: disable=E1101
1424 self.assertIn(expected, value) 1464 self.assertIn(expected, value)
1425 1465
1426 def checkNotInStdout(self, expected): 1466 def checkNotInStdout(self, expected):
1427 value = sys.stdout.getvalue() 1467 value = sys.stdout.getvalue()
1428 sys.stdout.close() 1468 sys.stdout.close()
1429 # pylint: disable=E1101 1469 # pylint: disable=E1101
1430 self.assertNotIn(expected, value) 1470 self.assertNotIn(expected, value)
1431 1471
1432 def getCurrentBranch(self):
1433 # Returns name of current branch or HEAD for detached HEAD
1434 branch = gclient_scm.scm.GIT.Capture(['rev-parse', '--abbrev-ref', 'HEAD'],
1435 cwd=self.base_path)
1436 if branch == 'HEAD':
1437 return None
1438 return branch
1439
1440 def testUpdateClone(self): 1472 def testUpdateClone(self):
1441 if not self.enabled: 1473 if not self.enabled:
1442 return 1474 return
1443 options = self.Options() 1475 options = self.Options()
1444 1476
1445 origin_root_dir = self.root_dir 1477 origin_root_dir = self.root_dir
1446 self.root_dir = tempfile.mkdtemp() 1478 self.root_dir = tempfile.mkdtemp()
1447 self.relpath = '.' 1479 self.relpath = '.'
1448 self.base_path = join(self.root_dir, self.relpath) 1480 self.base_path = join(self.root_dir, self.relpath)
1449 1481
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 1642
1611 if __name__ == '__main__': 1643 if __name__ == '__main__':
1612 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL 1644 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL
1613 logging.basicConfig( 1645 logging.basicConfig(
1614 level=level, 1646 level=level,
1615 format='%(asctime).19s %(levelname)s %(filename)s:' 1647 format='%(asctime).19s %(levelname)s %(filename)s:'
1616 '%(lineno)s %(message)s') 1648 '%(lineno)s %(message)s')
1617 unittest.main() 1649 unittest.main()
1618 1650
1619 # vim: ts=2:sw=2:tw=80:et: 1651 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient_scm.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698