Mercurial > public > mercurial-scm > hg
comparison tests/test-rust-revlog.py @ 52792:acae91fad6be
rust-pyo3-revlog: standalone NodeTree class
This is the actual first usage of `PyShareable`, but perhaps
it could be not so much necessary in this case (we could just
reference the `InnerRevlog` python object, and we do not need
to keep additional state).
author | Georges Racinet <georges.racinet@cloudcrane.io> |
---|---|
date | Sun, 22 Dec 2024 17:02:09 +0100 |
parents | 0ac956db7ea7 |
children | 6a70e4931773 |
comparison
equal
deleted
inserted
replaced
52791:0ac956db7ea7 | 52792:acae91fad6be |
---|---|
124 | 124 |
125 # although the upper bound is way too big, this is not an error: | 125 # although the upper bound is way too big, this is not an error: |
126 del idx[0::17] | 126 del idx[0::17] |
127 self.assertEqual(len(idx), 0) | 127 self.assertEqual(len(idx), 0) |
128 | 128 |
129 def test_standalone_nodetree(self): | |
130 idx = self.parserustindex() | |
131 nt = self.nodetree(idx) | |
132 for i in range(4): | |
133 nt.insert(i) | |
134 | |
135 # invalidation is upon mutation *of the index* | |
136 self.assertFalse(nt.is_invalidated()) | |
137 | |
138 bin_nodes = [entry[7] for entry in idx] | |
139 hex_nodes = [hex(n) for n in bin_nodes] | |
140 | |
141 for i, node in enumerate(hex_nodes): | |
142 self.assertEqual(nt.prefix_rev_lookup(node), i) | |
143 self.assertEqual(nt.prefix_rev_lookup(node[:5]), i) | |
144 | |
145 # all 4 revisions in idx (standard data set) have different | |
146 # first nybbles in their Node IDs, | |
147 # hence `nt.shortest()` should return 1 for them, except when | |
148 # the leading nybble is 0 (ambiguity with NULL_NODE) | |
149 for i, (bin_node, hex_node) in enumerate(zip(bin_nodes, hex_nodes)): | |
150 shortest = nt.shortest(bin_node) | |
151 expected = 2 if hex_node[0] == ord('0') else 1 | |
152 self.assertEqual(shortest, expected) | |
153 self.assertEqual(nt.prefix_rev_lookup(hex_node[:shortest]), i) | |
154 | |
155 # test invalidation (generation poisoning) detection | |
156 del idx[3] | |
157 self.assertTrue(nt.is_invalidated()) | |
158 | |
129 | 159 |
130 # Conditional skipping done by the base class | 160 # Conditional skipping done by the base class |
131 class RustInnerRevlogTest( | 161 class RustInnerRevlogTest( |
132 revlogtesting.RustRevlogBasedTestBase, RustInnerRevlogTestMixin | 162 revlogtesting.RustRevlogBasedTestBase, RustInnerRevlogTestMixin |
133 ): | 163 ): |
150 self.assertEqual(list(lazy), [3, 2, 1, 0]) | 180 self.assertEqual(list(lazy), [3, 2, 1, 0]) |
151 | 181 |
152 # let's check bool for an empty one | 182 # let's check bool for an empty one |
153 self.assertFalse(LazyAncestors(rustidx, [0], 0, False)) | 183 self.assertFalse(LazyAncestors(rustidx, [0], 0, False)) |
154 | 184 |
155 def test_standalone_nodetree(self): | |
156 idx = self.parserustindex() | |
157 nt = self.nodetree(idx) | |
158 for i in range(4): | |
159 nt.insert(i) | |
160 | |
161 bin_nodes = [entry[7] for entry in idx] | |
162 hex_nodes = [hex(n) for n in bin_nodes] | |
163 | |
164 for i, node in enumerate(hex_nodes): | |
165 self.assertEqual(nt.prefix_rev_lookup(node), i) | |
166 self.assertEqual(nt.prefix_rev_lookup(node[:5]), i) | |
167 | |
168 # all 4 revisions in idx (standard data set) have different | |
169 # first nybbles in their Node IDs, | |
170 # hence `nt.shortest()` should return 1 for them, except when | |
171 # the leading nybble is 0 (ambiguity with NULL_NODE) | |
172 for i, (bin_node, hex_node) in enumerate(zip(bin_nodes, hex_nodes)): | |
173 shortest = nt.shortest(bin_node) | |
174 expected = 2 if hex_node[0] == ord('0') else 1 | |
175 self.assertEqual(shortest, expected) | |
176 self.assertEqual(nt.prefix_rev_lookup(hex_node[:shortest]), i) | |
177 | |
178 # test invalidation (generation poisoning) detection | |
179 del idx[3] | |
180 self.assertTrue(nt.is_invalidated()) | |
181 | |
182 | 185 |
183 # Conditional skipping done by the base class | 186 # Conditional skipping done by the base class |
184 class PyO3InnerRevlogTest( | 187 class PyO3InnerRevlogTest( |
185 revlogtesting.PyO3RevlogBasedTestBase, RustInnerRevlogTestMixin | 188 revlogtesting.PyO3RevlogBasedTestBase, RustInnerRevlogTestMixin |
186 ): | 189 ): |