Index: tests/scm_unittest.py |
diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py |
index 2fbfe3dcfeef58c00b590809046b6bcf18ef51b8..cb07639eaf9e16490c87541fe3840eebcca5cc57 100755 |
--- a/tests/scm_unittest.py |
+++ b/tests/scm_unittest.py |
@@ -48,10 +48,24 @@ class RootTestCase(BaseSCMTestCase): |
def testMembersChanged(self): |
self.mox.ReplayAll() |
members = [ |
- 'ElementTree', 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', |
+ 'cStringIO', |
+ 'determine_scm', |
+ 'ElementTree', |
+ 'gclient_utils', |
+ 'GenFakeDiff', |
+ 'GetCasedPath', |
+ 'GIT', |
+ 'glob', |
+ 'logging', |
+ 'only_int', |
+ 'os', |
+ 're', |
+ 'subprocess2', |
+ 'SVN', |
+ 'sys', |
+ 'tempfile', |
+ 'time', |
'ValidateEmail', |
- 'cStringIO', 'determine_scm', 'gclient_utils', 'glob', 'logging', |
- 'only_int', 'os', 're', 'subprocess2', 'sys', 'tempfile', 'time', |
] |
# If this test fails, you should add the relevant test. |
self.compareMembers(scm, members) |
@@ -60,12 +74,26 @@ class RootTestCase(BaseSCMTestCase): |
class GitWrapperTestCase(BaseSCMTestCase): |
def testMembersChanged(self): |
members = [ |
- 'AssertVersion', 'Capture', 'CaptureStatus', |
- 'FetchUpstreamTuple', |
- 'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot', |
- 'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch', |
- 'GetUpstreamBranch', 'IsGitSvn', 'MatchSvnGlob', 'ShortBranchName', |
+ 'AssertVersion', |
+ 'Capture', |
+ 'CaptureStatus', |
'current_version', |
+ 'FetchUpstreamTuple', |
+ 'GenerateDiff', |
+ 'GetBranch', |
+ 'GetBranchRef', |
+ 'GetCheckoutRoot', |
+ 'GetDifferentFiles', |
+ 'GetEmail', |
+ 'GetGitSVNHeadRev', |
+ 'GetPatchName', |
+ 'GetSha1ForSVNRev', |
+ 'GetSVNBranch', |
+ 'GetUpstreamBranch', |
+ 'IsGitSvn', |
+ 'IsValidRevision', |
+ 'MatchSvnGlob', |
+ 'ShortBranchName', |
] |
# If this test fails, you should add the relevant test. |
self.compareMembers(scm.GIT, members) |
@@ -89,6 +117,63 @@ class GitWrapperTestCase(BaseSCMTestCase): |
'branches/*:refs/remotes/*', |
True), 'refs/remotes/bleeding_edge') |
M-A Ruel
2011/12/16 15:03:31
add another line
Dan Beam
2011/12/16 18:05:53
Done.
|
+class RealGitTest(fake_repos.FakeReposTestBase): |
+ def setUp(self): |
+ super(RealGitTest, self).setUp() |
+ self.enabled = self.FAKE_REPOS.set_up_git() |
+ if self.enabled: |
+ self.clone_dir = scm.os.path.join(self.FAKE_REPOS.git_root, 'repo_1') |
+ |
+ def testIsValidRevision(self): |
+ if not self.enabled: |
+ return |
+ # Sha1's are [0-9a-z]{32}, so starting with a 'z' or 'r' should always fail. |
+ self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='zebra')) |
+ self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='r123456')) |
+ # Valid cases |
+ first_rev = self.githash('repo_1', 1) |
+ self.assertTrue(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev=first_rev)) |
+ self.assertTrue(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='HEAD')) |
+ |
M-A Ruel
2011/12/16 15:03:31
add another line here
Dan Beam
2011/12/16 18:05:53
Done.
|
+class RealGitSVNTest(fake_repos.FakeReposTestBase): |
+ def setUp(self): |
+ super(RealGitSVNTest, self).setUp() |
+ self.enabled = self.FAKE_REPOS.set_up_git() and self.FAKE_REPOS.set_up_svn() |
+ if self.enabled: |
+ self.tree_name = 'git-svn' |
+ self.svn_url = scm.os.path.join(self.FAKE_REPOS.svn_base, 'trunk') |
+ self.clone_dir = scm.os.path.join(self.FAKE_REPOS.git_root, |
+ self.tree_name) |
+ scm.gclient_utils.rmtree(self.clone_dir) |
+ scm.os.makedirs(self.clone_dir) |
+ self._capture(['svn', 'clone', '-q', '-q', self.svn_url, self.clone_dir]) |
+ hashes = self._capture(['rev-list', 'HEAD']).splitlines() |
M-A Ruel
2011/12/16 15:03:31
# We insert a null value at 0 to do 1-based indexi
Dan Beam
2011/12/16 18:05:53
Done. (yay, knew there had to be a way to do this!
|
+ # git rev-list gives revisions in reverse chronological order. |
+ hashes.reverse() |
+ # We insert a null value at 0 to do 1-based indexing, not 0-based, as SVN |
+ # revisions are 1-based (i.e. they start at r1, not r0). |
+ hashes.insert(0, None) |
+ self.git_hashes = hashes |
+ |
+ def _capture(self, cmd, **kwargs): |
+ kwargs.setdefault('cwd', self.clone_dir) |
+ return scm.GIT.Capture(cmd, **kwargs) |
+ |
+ def testGetGitSVNHeadRev(self): |
+ if not self.enabled: |
+ return |
+ self.assertEquals(scm.GIT.GetGitSVNHeadRev(cwd=self.clone_dir), 2) |
+ self._capture(['reset', '--hard', 'HEAD^']) |
+ self.assertEquals(scm.GIT.GetGitSVNHeadRev(cwd=self.clone_dir), 1) |
+ |
+ def testGetGetSha1ForSVNRev(self): |
+ if not self.enabled: |
+ return |
+ self.assertEquals(scm.GIT.GetSha1ForSVNRev(cwd=self.clone_dir, rev=1), |
+ self.git_hashes[1]) |
+ self.assertEquals(scm.GIT.GetSha1ForSVNRev(cwd=self.clone_dir, rev=2), |
+ self.git_hashes[2]) |
+ |
class SVNTestCase(BaseSCMTestCase): |
def setUp(self): |
BaseSCMTestCase.setUp(self) |
@@ -98,11 +183,24 @@ class SVNTestCase(BaseSCMTestCase): |
def testMembersChanged(self): |
self.mox.ReplayAll() |
members = [ |
- 'AssertVersion', 'Capture', 'CaptureRevision', 'CaptureLocalInfo', |
+ 'AssertVersion', |
+ 'Capture', |
+ 'CaptureLocalInfo', |
'CaptureRemoteInfo', |
- 'CaptureStatus', 'current_version', 'DiffItem', 'GenerateDiff', |
- 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved', |
- 'IsMovedInfo', 'ReadSimpleAuth', 'Revert', 'RunAndGetFileList', |
+ 'CaptureRevision', |
+ 'CaptureStatus', |
+ 'current_version', |
+ 'DiffItem', |
+ 'GenerateDiff', |
+ 'GetCheckoutRoot', |
+ 'GetEmail', |
+ 'GetFileProperty', |
+ 'IsMoved', |
+ 'IsMovedInfo', |
+ 'IsValidRevision', |
+ 'ReadSimpleAuth', |
+ 'Revert', |
+ 'RunAndGetFileList', |
] |
# If this test fails, you should add the relevant test. |
self.compareMembers(scm.SVN, members) |