annotate tests/test_revmap_migrate.py @ 1549:8410a978c650

compathacks: be compatible with upstream 8a0cac20a1ad memfilectx change See hg change 8a0cac20a1ad. Since the interface has changed more than one time, switch to explicit keywords arguments to avoid surprises. Since hgsubversion targets hg >= 3.2.4, drop support for hg 3.0 and 3.1 here.
author Jun Wu <quark@fb.com>
date Tue, 19 Dec 2017 14:29:55 -0800
parents 8937f19586fe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1473
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
1 import test_util
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
2
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
3 from mercurial import util as hgutil
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
4 from hgsubversion import svnmeta, maps
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
5 from mercurial.node import hex
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
6
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
7 class TestRevMapMigrate(test_util.TestBase):
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
8
1491
8937f19586fe test_revmap_migrate: restore revmap class in tearDown
Jun Wu <quark@fb.com>
parents: 1473
diff changeset
9 def tearDown(self):
8937f19586fe test_revmap_migrate: restore revmap class in tearDown
Jun Wu <quark@fb.com>
parents: 1473
diff changeset
10 # revert changes to defaultrevmapclass
8937f19586fe test_revmap_migrate: restore revmap class in tearDown
Jun Wu <quark@fb.com>
parents: 1473
diff changeset
11 svnmeta.SVNMeta._defaultrevmapclass = maps.RevMap
8937f19586fe test_revmap_migrate: restore revmap class in tearDown
Jun Wu <quark@fb.com>
parents: 1473
diff changeset
12
1473
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
13 def _test_revmap_migrate(self, fromclass, toclass):
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
14 # revmap interfaces to test
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
15 getters = [
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
16 lambda x: x.branchedits('the_branch', 3),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
17 lambda x: x.branchedits('the_branch', 4),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
18 lambda x: x.branchedits('the_branch', 5),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
19 lambda x: x.branchedits('the_branch', 6),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
20 lambda x: x.branchedits(None, 5),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
21 lambda x: x.branchedits('non_existed', 10),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
22 lambda x: x.branchmaxrevnum('the_branch', 3),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
23 lambda x: x.branchmaxrevnum('the_branch', 4),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
24 lambda x: x.branchmaxrevnum('the_branch', 5),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
25 lambda x: x.branchmaxrevnum('the_branch', 6),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
26 lambda x: x.branchmaxrevnum(None, 5),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
27 lambda x: x.branchmaxrevnum('non_existed', 10),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
28 lambda x: list(x.revhashes(3)),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
29 lambda x: list(x.revhashes(4)),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
30 lambda x: list(x.revhashes(42)),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
31 lambda x: list(x.revhashes(105)),
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
32 lambda x: x.firstpulled,
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
33 lambda x: x.lastpulled,
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
34 lambda x: x.lasthash,
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
35 ]
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
36
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
37 svnmeta.SVNMeta._defaultrevmapclass = fromclass
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
38 repo = self._load_fixture_and_fetch('two_heads.svndump')
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
39 meta = svnmeta.SVNMeta(repo)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
40 self.assertEqual(meta.revmap.__class__, fromclass)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
41 origrevmap = meta.revmap
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
42
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
43 # insert fake special (duplicated, with '\0') data
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
44 origrevmap[103, None] = b'\0' * 20
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
45 origrevmap[104, None] = b'\0' * 18 + b'cd'
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
46 origrevmap[105, None] = b'ab\0cdefghijklmnopqrs'
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
47 origrevmap[104, None] = b'\0' * 18 + b'\xff\0'
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
48 origrevmap[105, 'ab'] = origrevmap[105, None]
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
49
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
50 origvalues = [f(meta.revmap) for f in getters]
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
51
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
52 # migrate to another format (transparently)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
53 svnmeta.SVNMeta._defaultrevmapclass = toclass
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
54 meta = svnmeta.SVNMeta(repo)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
55 self.assertEqual(meta.revmap.__class__, toclass)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
56
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
57 # enable iteration otherwise we cannot use iteritems
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
58 origrevmap._allowiter = True
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
59 for k, v in origrevmap.iteritems():
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
60 newv = meta.revmap[k]
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
61 self.assertEqual(newv, v)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
62 self.assertEqual(len(newv), 20)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
63 self.assertEqual(meta.revmap[meta.revmap.hashes()[v]], v)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
64
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
65 newvalues = [f(meta.revmap) for f in getters]
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
66 self.assertEqual(origvalues, newvalues)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
67
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
68 def test_revmap_migrate_up(self):
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
69 self._test_revmap_migrate(maps.RevMap, maps.SqliteRevMap)
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
70
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
71 def test_revmap_migrate_down(self):
623af04c6e06 tests: new test about revmap two-way migrations
Jun Wu <quark@fb.com>
parents:
diff changeset
72 self._test_revmap_migrate(maps.SqliteRevMap, maps.RevMap)