changeset 1048:903c9c9dfe6a

tests: count revisions explicitly The assumption that len(repo) corresponds to the count of actual, usable revision in the repository fails in presence of hidden revisions. Instead, we use a dedicated method in test_util, and change all tests to use this for obtaining repository length -- just to be safe...
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 09 Aug 2013 11:22:50 -0400
parents 3092b3c109a8
children 608e7c8740af
files tests/comprehensive/test_rebuildmeta.py tests/comprehensive/test_stupid_pull.py tests/comprehensive/test_updatemeta.py tests/comprehensive/test_verify_and_startrev.py tests/test_fetch_branches.py tests/test_fetch_command.py tests/test_push_command.py tests/test_unaffected_core.py tests/test_util.py
diffstat 9 files changed, 28 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/tests/comprehensive/test_rebuildmeta.py
+++ b/tests/comprehensive/test_rebuildmeta.py
@@ -37,7 +37,7 @@ def _do_case(self, name, stupid, single)
         layout = 'single'
     repo, repo_path = self.load_and_fetch(name, subdir=subdir, stupid=stupid,
                                           layout=layout)
-    assert len(self.repo) > 0
+    assert test_util.repolen(self.repo) > 0
     wc2_path = self.wc_path + '_clone'
     u = ui.ui()
     src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False)
--- a/tests/comprehensive/test_stupid_pull.py
+++ b/tests/comprehensive/test_stupid_pull.py
@@ -21,7 +21,8 @@ def _do_case(self, name, layout):
     subdir = test_util.subdir.get(name, '')
     repo, repo_path = self.load_and_fetch(name, subdir=subdir, stupid=False,
                                           layout=layout)
-    assert len(self.repo) > 0, 'Repo had no changes, maybe you need to add a subdir entry in test_util?'
+    assert test_util.repolen(self.repo) > 0, \
+        'Repo had no changes, maybe you need to add a subdir entry in test_util?'
     wc2_path = self.wc_path + '_stupid'
     u = ui.ui()
     checkout_path = repo_path
--- a/tests/comprehensive/test_updatemeta.py
+++ b/tests/comprehensive/test_updatemeta.py
@@ -29,7 +29,7 @@ def _do_case(self, name, stupid, single)
         layout = 'single'
     repo, repo_path = self.load_and_fetch(name, subdir=subdir, stupid=stupid,
                                           layout=layout)
-    assert len(self.repo) > 0
+    assert test_util.repolen(self.repo) > 0
     wc2_path = self.wc_path + '_clone'
     u = ui.ui()
     src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False)
--- a/tests/comprehensive/test_verify_and_startrev.py
+++ b/tests/comprehensive/test_verify_and_startrev.py
@@ -41,7 +41,7 @@ def _do_case(self, name, stupid, layout)
     subdir = test_util.subdir.get(name, '')
     repo, svnpath = self.load_and_fetch(name, subdir=subdir, stupid=stupid,
                                         layout=layout)
-    assert len(self.repo) > 0
+    assert test_util.repolen(self.repo) > 0
     for i in repo:
         ctx = repo[i]
         self.assertEqual(verify.verify(repo.ui, repo, rev=ctx.node(),
@@ -55,9 +55,9 @@ def _do_case(self, name, stupid, layout)
         shallowrepo = self.fetch(svnpath, subdir=subdir, stupid=stupid,
                                  layout='single', startrev='HEAD')
 
-        self.assertEqual(len(shallowrepo), 1,
+        self.assertEqual(test_util.repolen(shallowrepo), 1,
                          "shallow clone should have just one revision, not %d"
-                         % len(shallowrepo))
+                         % test_util.repolen(shallowrepo))
 
         fulltip = repo['tip']
         shallowtip = shallowrepo['tip']
--- a/tests/test_fetch_branches.py
+++ b/tests/test_fetch_branches.py
@@ -140,7 +140,7 @@ class TestFetchBranches(test_util.TestBa
     def test_replace_branch_with_branch(self, stupid=False):
         repo = self._load_fixture_and_fetch('replace_branch_with_branch.svndump',
                                             stupid=stupid)
-        self.assertEqual(7, len(repo))
+        self.assertEqual(7, test_util.repolen(repo))
         # tip is former topological branch1 being closed
         ctx = repo['tip']
         self.assertEqual('1', ctx.extra().get('close', '0'))
--- a/tests/test_fetch_command.py
+++ b/tests/test_fetch_command.py
@@ -100,7 +100,7 @@ class TestBasicRepoLayout(test_util.Test
             'test_files_copied_from_outside_btt.svndump', stupid=stupid)
         self.assertEqual(node.hex(repo['tip'].node()),
                          '3c78170e30ddd35f2c32faa0d8646ab75bba4f73')
-        self.assertEqual(len(repo.changelog), 2)
+        self.assertEqual(test_util.repolen(repo.changelog), 2)
 
     def test_files_copied_from_outside_btt_stupid(self):
         self.test_files_copied_from_outside_btt(stupid=True)
@@ -173,7 +173,7 @@ class TestBasicRepoLayout(test_util.Test
 
         self.assertEqual(repo['tip'].extra()['convert_revision'],
                          repo2['tip'].extra()['convert_revision'])
-        self.assertEqual(len(repo), len(repo2))
+        self.assertEqual(test_util.repolen(repo), test_util.repolen(repo2))
 
         for r in repo:
             self.assertEqual(repo[r].hex(), repo2[r].hex())
--- a/tests/test_push_command.py
+++ b/tests/test_push_command.py
@@ -578,7 +578,7 @@ class PushTests(test_util.TestBase):
         on top of the pushed commit.
         '''
 
-        oldlen = len(self.repo)
+        oldlen = test_util.repolen(self.repo)
         oldtiphash = self.repo['default'].node()
 
         changes = [('gamma', 'gamma', 'sometext')]
@@ -591,7 +591,7 @@ class PushTests(test_util.TestBase):
         repo = self.repo
         hg.update(repo, newhash1)
         commands.push(repo.ui, repo)
-        self.assertEqual(len(self.repo), oldlen + 2)
+        self.assertEqual(test_util.repolen(self.repo), oldlen + 2)
 
         # verify that the first commit is pushed, and the second is not
         commit2 = self.repo['tip']
@@ -609,7 +609,7 @@ class PushTests(test_util.TestBase):
         This test verifies that code path works.
         '''
 
-        oldlen = len(self.repo)
+        oldlen = test_util.repolen(self.repo)
         oldtiphash = self.repo['default'].node()
 
         changes = [('gamma', 'gamma', 'sometext')]
@@ -622,7 +622,7 @@ class PushTests(test_util.TestBase):
         repo = self.repo
         hg.update(repo, newhash)
         commands.push(repo.ui, repo)
-        self.assertEqual(len(self.repo), oldlen + 2)
+        self.assertEqual(test_util.repolen(self.repo), oldlen + 2)
 
         # verify that both commits are pushed
         commit1 = self.repo['tip']
--- a/tests/test_unaffected_core.py
+++ b/tests/test_unaffected_core.py
@@ -43,7 +43,7 @@ class TestMercurialCore(test_util.TestBa
         f.flush()
         commands.commit(ui, repo, message="C3")
 
-        self.assertEqual(len(repo), 3)
+        self.assertEqual(test_util.repolen(repo), 3)
 
         updaterev = 1
         _dispatch(ui, ['clone', self.wc_path, self.wc_path + '2',
@@ -77,7 +77,7 @@ class TestMercurialCore(test_util.TestBa
         commands.branch(ui, repo, label="B2")
         commands.commit(ui, repo, message="C3")
 
-        self.assertEqual(len(repo), 3)
+        self.assertEqual(test_util.repolen(repo), 3)
 
         branch = 'B1'
         _dispatch(ui, ['clone', self.wc_path, self.wc_path + '2',
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -111,6 +111,16 @@ def getlocalpeer(repo):
         localrepo = repo
     return localrepo
 
+def repolen(repo):
+    """Naively calculate the amount of available revisions in a repository.
+
+    this is usually equal to len(repo) -- except in the face of
+    obsolete revisions.
+    """
+    # kind of nasty way of calculating the length, but fortunately,
+    # our test repositories tend to be rather small
+    return len([r for r in repo])
+
 def _makeskip(name, message):
     if SkipTest:
         def skip(*args, **kwargs):
@@ -417,10 +427,10 @@ class TestBase(unittest.TestCase):
         return hg.repository(testui(), self.wc_path)
 
     def pushrevisions(self, stupid=False, expected_extra_back=0):
-        before = len(self.repo)
+        before = repolen(self.repo)
         self.repo.ui.setconfig('hgsubversion', 'stupid', str(stupid))
         res = commands.push(self.repo.ui, self.repo)
-        after = len(self.repo)
+        after = repolen(self.repo)
         self.assertEqual(expected_extra_back, after - before)
         return res