| OLD | NEW |
| 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 scm.py.""" | 6 """Unit tests for scm.py.""" |
| 7 | 7 |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 import tempfile |
| 11 import unittest | 12 import unittest |
| 12 | 13 |
| 13 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 14 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 14 | 15 |
| 15 from testing_support import fake_repos | 16 from testing_support import fake_repos |
| 16 from testing_support.super_mox import SuperMoxTestBase | 17 from testing_support.super_mox import SuperMoxTestBase |
| 17 | 18 |
| 18 import scm | 19 import scm |
| 19 import subprocess2 | 20 import subprocess2 |
| 20 | 21 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if not self.enabled: | 135 if not self.enabled: |
| 135 return | 136 return |
| 136 # Sha1's are [0-9a-z]{32}, so starting with a 'z' or 'r' should always fail. | 137 # Sha1's are [0-9a-z]{32}, so starting with a 'z' or 'r' should always fail. |
| 137 self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='zebra')) | 138 self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='zebra')) |
| 138 self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='r123456')) | 139 self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='r123456')) |
| 139 # Valid cases | 140 # Valid cases |
| 140 first_rev = self.githash('repo_1', 1) | 141 first_rev = self.githash('repo_1', 1) |
| 141 self.assertTrue(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev=first_rev)) | 142 self.assertTrue(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev=first_rev)) |
| 142 self.assertTrue(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='HEAD')) | 143 self.assertTrue(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='HEAD')) |
| 143 | 144 |
| 145 # Verify that IsValidRevision returns False for non-commit objects. |
| 146 tmp = tempfile.NamedTemporaryFile(delete=False) |
| 147 try: |
| 148 tmp.write('This is not a commit') |
| 149 tmp.close() |
| 150 hashval = scm.GIT.Capture(['hash-object', '-w', tmp.name], |
| 151 cwd=self.clone_dir) |
| 152 finally: |
| 153 os.remove(tmp.name) |
| 154 self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev=hashval)) |
| 155 |
| 144 | 156 |
| 145 class RealGitSvnTest(fake_repos.FakeReposTestBase): | 157 class RealGitSvnTest(fake_repos.FakeReposTestBase): |
| 146 def setUp(self): | 158 def setUp(self): |
| 147 super(RealGitSvnTest, self).setUp() | 159 super(RealGitSvnTest, self).setUp() |
| 148 self.enabled = self.FAKE_REPOS.set_up_git() and self.FAKE_REPOS.set_up_svn() | 160 self.enabled = self.FAKE_REPOS.set_up_git() and self.FAKE_REPOS.set_up_svn() |
| 149 if self.enabled: | 161 if self.enabled: |
| 150 self.tree_name = 'git-svn' | 162 self.tree_name = 'git-svn' |
| 151 self.svn_url = scm.os.path.join(self.FAKE_REPOS.svn_base, 'trunk') | 163 self.svn_url = scm.os.path.join(self.FAKE_REPOS.svn_base, 'trunk') |
| 152 self.clone_dir = scm.os.path.join(self.FAKE_REPOS.git_root, | 164 self.clone_dir = scm.os.path.join(self.FAKE_REPOS.git_root, |
| 153 self.tree_name) | 165 self.tree_name) |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 # Asserting the tree is not sufficient, svn status must come out clear too. | 494 # Asserting the tree is not sufficient, svn status must come out clear too. |
| 483 self.assertEquals('', self._capture(['status'])) | 495 self.assertEquals('', self._capture(['status'])) |
| 484 | 496 |
| 485 | 497 |
| 486 if __name__ == '__main__': | 498 if __name__ == '__main__': |
| 487 if '-v' in sys.argv: | 499 if '-v' in sys.argv: |
| 488 logging.basicConfig(level=logging.DEBUG) | 500 logging.basicConfig(level=logging.DEBUG) |
| 489 unittest.main() | 501 unittest.main() |
| 490 | 502 |
| 491 # vim: ts=2:sw=2:tw=80:et: | 503 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |