Mercurial > hgsubversion
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 154:6fa97cfbf62f | 155:ba801f44d240 |
|---|---|
| 1 import os | |
| 2 import pickle | |
| 3 import unittest | |
| 4 | |
| 5 from mercurial import hg | |
| 6 from mercurial import ui | |
| 7 | |
| 8 import test_util | |
| 9 import rebuildmeta | |
| 10 import hg_delta_editor | |
| 11 | |
| 12 subdir = {'truncatedhistory.svndump': '/project2', | |
| 13 'fetch_missing_files_subdir.svndump': '/foo', | |
| 14 } | |
| 15 # List of expected "missing" branches - these are really files that happen | |
| 16 # to be in the branches dir. This will be fixed at a later date. | |
| 17 expected_branch_deltas = {'unrelatedbranch.svndump': ['c', ], | |
| 18 'file_mixed_with_branches.svndump': ['README', ], | |
| 19 } | |
| 20 | |
| 21 def _do_case(self, name, stupid): | |
| 22 self._load_fixture_and_fetch(name, subdir=subdir.get(name, ''), stupid=stupid) | |
| 23 assert len(self.repo) > 0 | |
| 24 wc2_path = self.wc_path + '_clone' | |
| 25 u = ui.ui() | |
| 26 src, dest = hg.clone(u, self.wc_path, wc2_path, update=False) | |
| 27 rebuildmeta.rebuildmeta(u, | |
| 28 dest, | |
| 29 os.path.dirname(dest.path), | |
| 30 args=[test_util.fileurl(self.repo_path + | |
| 31 subdir.get(name, '')), ]) | |
| 32 dest = hg.repository(u, os.path.dirname(dest.path)) | |
| 33 self.assert_(open(os.path.join(src.path, 'svn', 'last_rev')).read() >= | |
| 34 open(os.path.join(dest.path, 'svn', 'last_rev')).read()) | |
| 35 for tf in ('rev_map', 'uuid', 'url'): | |
| 36 self.assertEqual(open(os.path.join(src.path, 'svn', tf)).read(), | |
| 37 open(os.path.join(dest.path, 'svn', tf)).read()) | |
| 38 self.assertEqual(pickle.load(open(os.path.join(src.path, 'svn', | |
| 39 'tag_info'))), | |
| 40 pickle.load(open(os.path.join(dest.path, 'svn', | |
| 41 'tag_info')))) | |
| 42 self.assertEqual(src.branchtags(), dest.branchtags()) | |
| 43 srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info'))) | |
| 44 for mustpop in expected_branch_deltas.get(name, []): | |
| 45 del srcbi[mustpop] | |
| 46 destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info'))) | |
| 47 self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys())) | |
| 48 for branch in destbi: | |
| 49 srcinfo = srcbi[branch] | |
| 50 destinfo = destbi[branch] | |
| 51 hge = hg_delta_editor.HgChangeReceiver(path=os.path.dirname(dest.path), | |
| 52 repo=dest, | |
| 53 ui_=u) | |
| 54 if destinfo[:2] == (None, 0): | |
| 55 self.assert_(srcinfo[2] <= destinfo[2]) | |
| 56 self.assertEqual(srcinfo[0], destinfo[0]) | |
| 57 else: | |
| 58 pr = sorted(filter(lambda x: x[1] == srcinfo[0] and x[0] <= srcinfo[1], | |
| 59 hge.revmap.keys()), reverse=True)[0][0] | |
| 60 self.assertEqual(pr, destinfo[1]) | |
| 61 self.assertEqual(srcinfo[2], destinfo[2]) | |
| 62 | |
| 63 | |
| 64 def buildmethod(case, name, stupid): | |
| 65 m = lambda self: self._do_case(case, stupid) | |
| 66 m.__name__ = name | |
| 67 m.__doc__ = ('Test rebuildmeta on %s with %s replay.' % | |
| 68 (case, (stupid and 'stupid') or 'real')) | |
| 69 return m | |
| 70 | |
| 71 | |
| 72 attrs = {'_do_case': _do_case, | |
| 73 } | |
| 74 for case in (f for f in os.listdir(test_util.FIXTURES) if f.endswith('.svndump')): | |
| 75 name = 'test_' + case[:-len('.svndump')] | |
| 76 attrs[name] = buildmethod(case, name, False) | |
| 77 name += '_stupid' | |
| 78 attrs[name] = buildmethod(case, name, True) | |
| 79 RebuildMetaTests = type('RebuildMetaTests', (test_util.TestBase, ), attrs) | |
| 80 | |
| 81 | |
| 82 def suite(): | |
| 83 all = [unittest.TestLoader().loadTestsFromTestCase(RebuildMetaTests), | |
| 84 ] | |
| 85 return unittest.TestSuite(all) |
