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

Side by Side Diff: tests/gclient_scm_test.py

Issue 563873002: Revert "Make check for dirty index work." (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: 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
« 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
930 def setUp(self): 922 def setUp(self):
931 TestCaseUtils.setUp(self) 923 TestCaseUtils.setUp(self)
932 unittest.TestCase.setUp(self) 924 unittest.TestCase.setUp(self)
933 self.url = 'git://foo' 925 self.url = 'git://foo'
934 # The .git suffix allows gclient_scm to recognize the dir as a git repo 926 # The .git suffix allows gclient_scm to recognize the dir as a git repo
935 # when cloning it locally 927 # when cloning it locally
936 self.root_dir = tempfile.mkdtemp('.git') 928 self.root_dir = tempfile.mkdtemp('.git')
937 self.relpath = '.' 929 self.relpath = '.'
938 self.base_path = join(self.root_dir, self.relpath) 930 self.base_path = join(self.root_dir, self.relpath)
939 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) 931 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 file_path = join(self.base_path, 'b') 1193 file_path = join(self.base_path, 'b')
1202 open(file_path, 'w').writelines('conflict\n') 1194 open(file_path, 'w').writelines('conflict\n')
1203 scm._Run(['commit', '-am', 'test'], options) 1195 scm._Run(['commit', '-am', 'test'], options)
1204 scm._AskForData = self._GetAskForDataCallback( 1196 scm._AskForData = self._GetAskForDataCallback(
1205 'Cannot fast-forward merge, attempt to rebase? ' 1197 'Cannot fast-forward merge, attempt to rebase? '
1206 '(y)es / (q)uit / (s)kip : ', 'y') 1198 '(y)es / (q)uit / (s)kip : ', 'y')
1207 exception = ('Conflict while rebasing this branch.\n' 1199 exception = ('Conflict while rebasing this branch.\n'
1208 'Fix the conflict and run gclient again.\n' 1200 'Fix the conflict and run gclient again.\n'
1209 'See \'man git-rebase\' for details.\n') 1201 'See \'man git-rebase\' for details.\n')
1210 self.assertRaisesError(exception, scm.update, options, (), []) 1202 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).
1214 exception = ('\n____ . at refs/remotes/origin/master\n' 1203 exception = ('\n____ . at refs/remotes/origin/master\n'
1215 '\tYou have unstaged changes.\n' 1204 '\tYou have unstaged changes.\n'
1216 '\tPlease commit, stash, or reset.\n') 1205 '\tPlease commit, stash, or reset.\n')
1217 self.assertRaisesError(exception, scm.update, options, (), []) 1206 self.assertRaisesError(exception, scm.update, options, (), [])
1218 sys.stdout.close() 1207 sys.stdout.close()
1219 1208
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
1249 def testRevinfo(self): 1209 def testRevinfo(self):
1250 if not self.enabled: 1210 if not self.enabled:
1251 return 1211 return
1252 options = self.Options() 1212 options = self.Options()
1253 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1213 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1254 relpath=self.relpath) 1214 relpath=self.relpath)
1255 rev_info = scm.revinfo(options, (), None) 1215 rev_info = scm.revinfo(options, (), None)
1256 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') 1216 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
1257 1217
1258 1218
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 sys.stdout.close() 1422 sys.stdout.close()
1463 # pylint: disable=E1101 1423 # pylint: disable=E1101
1464 self.assertIn(expected, value) 1424 self.assertIn(expected, value)
1465 1425
1466 def checkNotInStdout(self, expected): 1426 def checkNotInStdout(self, expected):
1467 value = sys.stdout.getvalue() 1427 value = sys.stdout.getvalue()
1468 sys.stdout.close() 1428 sys.stdout.close()
1469 # pylint: disable=E1101 1429 # pylint: disable=E1101
1470 self.assertNotIn(expected, value) 1430 self.assertNotIn(expected, value)
1471 1431
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
1472 def testUpdateClone(self): 1440 def testUpdateClone(self):
1473 if not self.enabled: 1441 if not self.enabled:
1474 return 1442 return
1475 options = self.Options() 1443 options = self.Options()
1476 1444
1477 origin_root_dir = self.root_dir 1445 origin_root_dir = self.root_dir
1478 self.root_dir = tempfile.mkdtemp() 1446 self.root_dir = tempfile.mkdtemp()
1479 self.relpath = '.' 1447 self.relpath = '.'
1480 self.base_path = join(self.root_dir, self.relpath) 1448 self.base_path = join(self.root_dir, self.relpath)
1481 1449
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 1618
1651 if __name__ == '__main__': 1619 if __name__ == '__main__':
1652 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL 1620 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL
1653 logging.basicConfig( 1621 logging.basicConfig(
1654 level=level, 1622 level=level,
1655 format='%(asctime).19s %(levelname)s %(filename)s:' 1623 format='%(asctime).19s %(levelname)s %(filename)s:'
1656 '%(lineno)s %(message)s') 1624 '%(lineno)s %(message)s')
1657 unittest.main() 1625 unittest.main()
1658 1626
1659 # vim: ts=2:sw=2:tw=80:et: 1627 # 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