diff tests/test_rebuildmeta.py @ 155:ba801f44d240

utility_commands: Implement rebuildmeta so that metadata can be rebuilt. hg_delta_editor: Fixed some longstanding branch_info bugs detected while rebuilding meta.
author Augie Fackler <durin42@gmail.com>
date Tue, 23 Dec 2008 22:19:26 -0600
parents
children 47d25d61abfa
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/tests/test_rebuildmeta.py
@@ -0,0 +1,85 @@
+import os
+import pickle
+import unittest
+
+from mercurial import hg
+from mercurial import ui
+
+import test_util
+import rebuildmeta
+import hg_delta_editor
+
+subdir = {'truncatedhistory.svndump': '/project2',
+          'fetch_missing_files_subdir.svndump': '/foo',
+          }
+# List of expected "missing" branches - these are really files that happen
+# to be in the branches dir. This will be fixed at a later date.
+expected_branch_deltas = {'unrelatedbranch.svndump': ['c', ],
+                          'file_mixed_with_branches.svndump': ['README', ],
+                          }
+
+def _do_case(self, name, stupid):
+    self._load_fixture_and_fetch(name, subdir=subdir.get(name, ''), stupid=stupid)
+    assert len(self.repo) > 0
+    wc2_path = self.wc_path + '_clone'
+    u = ui.ui()
+    src, dest = hg.clone(u, self.wc_path, wc2_path, update=False)
+    rebuildmeta.rebuildmeta(u,
+                            dest,
+                            os.path.dirname(dest.path),
+                            args=[test_util.fileurl(self.repo_path +
+                                                    subdir.get(name, '')), ])
+    dest = hg.repository(u, os.path.dirname(dest.path))
+    self.assert_(open(os.path.join(src.path, 'svn', 'last_rev')).read() >=
+                     open(os.path.join(dest.path, 'svn', 'last_rev')).read())
+    for tf in ('rev_map', 'uuid', 'url'):
+        self.assertEqual(open(os.path.join(src.path, 'svn', tf)).read(),
+                         open(os.path.join(dest.path, 'svn', tf)).read())
+    self.assertEqual(pickle.load(open(os.path.join(src.path, 'svn',
+                                                   'tag_info'))),
+                     pickle.load(open(os.path.join(dest.path, 'svn',
+                                                   'tag_info'))))
+    self.assertEqual(src.branchtags(), dest.branchtags())
+    srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info')))
+    for mustpop in expected_branch_deltas.get(name, []):
+        del srcbi[mustpop]
+    destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info')))
+    self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys()))
+    for branch in destbi:
+        srcinfo = srcbi[branch]
+        destinfo = destbi[branch]
+        hge = hg_delta_editor.HgChangeReceiver(path=os.path.dirname(dest.path),
+                                                   repo=dest,
+                                                   ui_=u)
+        if destinfo[:2] == (None, 0):
+            self.assert_(srcinfo[2] <= destinfo[2])
+            self.assertEqual(srcinfo[0], destinfo[0])
+        else:
+            pr = sorted(filter(lambda x: x[1] == srcinfo[0] and x[0] <= srcinfo[1],
+                        hge.revmap.keys()), reverse=True)[0][0]
+            self.assertEqual(pr, destinfo[1])
+            self.assertEqual(srcinfo[2], destinfo[2])
+
+
+def buildmethod(case, name, stupid):
+    m = lambda self: self._do_case(case, stupid)
+    m.__name__ = name
+    m.__doc__ = ('Test rebuildmeta on %s with %s replay.' %
+                 (case, (stupid and 'stupid') or 'real'))
+    return m
+
+
+attrs = {'_do_case': _do_case,
+         }
+for case in (f for f in os.listdir(test_util.FIXTURES) if f.endswith('.svndump')):
+    name = 'test_' + case[:-len('.svndump')]
+    attrs[name] = buildmethod(case, name, False)
+    name += '_stupid'
+    attrs[name] = buildmethod(case, name, True)
+RebuildMetaTests = type('RebuildMetaTests', (test_util.TestBase, ), attrs)
+
+
+def suite():
+    all = [unittest.TestLoader().loadTestsFromTestCase(RebuildMetaTests),
+          ]
+    return unittest.TestSuite(all)