# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1376061770 14400 # Node ID 903c9c9dfe6a0e0673aa3cafccc715fea7f49922 # Parent 3092b3c109a8e2ac501b1392ae97d9b79d10fbdb 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... diff --git a/tests/comprehensive/test_rebuildmeta.py b/tests/comprehensive/test_rebuildmeta.py --- 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) diff --git a/tests/comprehensive/test_stupid_pull.py b/tests/comprehensive/test_stupid_pull.py --- 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 diff --git a/tests/comprehensive/test_updatemeta.py b/tests/comprehensive/test_updatemeta.py --- 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) diff --git a/tests/comprehensive/test_verify_and_startrev.py b/tests/comprehensive/test_verify_and_startrev.py --- 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'] diff --git a/tests/test_fetch_branches.py b/tests/test_fetch_branches.py --- 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')) diff --git a/tests/test_fetch_command.py b/tests/test_fetch_command.py --- 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()) diff --git a/tests/test_push_command.py b/tests/test_push_command.py --- 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'] diff --git a/tests/test_unaffected_core.py b/tests/test_unaffected_core.py --- 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', diff --git a/tests/test_util.py b/tests/test_util.py --- 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