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