diff tests/test-rust-revlog.py @ 52805: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
line wrap: on
line diff
--- a/tests/test-rust-revlog.py	Sun Dec 22 21:37:29 2024 +0100
+++ b/tests/test-rust-revlog.py	Sun Dec 22 17:02:09 2024 +0100
@@ -126,6 +126,36 @@
         del idx[0::17]
         self.assertEqual(len(idx), 0)
 
+    def test_standalone_nodetree(self):
+        idx = self.parserustindex()
+        nt = self.nodetree(idx)
+        for i in range(4):
+            nt.insert(i)
+
+        # invalidation is upon mutation *of the index*
+        self.assertFalse(nt.is_invalidated())
+
+        bin_nodes = [entry[7] for entry in idx]
+        hex_nodes = [hex(n) for n in bin_nodes]
+
+        for i, node in enumerate(hex_nodes):
+            self.assertEqual(nt.prefix_rev_lookup(node), i)
+            self.assertEqual(nt.prefix_rev_lookup(node[:5]), i)
+
+        # all 4 revisions in idx (standard data set) have different
+        # first nybbles in their Node IDs,
+        # hence `nt.shortest()` should return 1 for them, except when
+        # the leading nybble is 0 (ambiguity with NULL_NODE)
+        for i, (bin_node, hex_node) in enumerate(zip(bin_nodes, hex_nodes)):
+            shortest = nt.shortest(bin_node)
+            expected = 2 if hex_node[0] == ord('0') else 1
+            self.assertEqual(shortest, expected)
+            self.assertEqual(nt.prefix_rev_lookup(hex_node[:shortest]), i)
+
+        # test invalidation (generation poisoning) detection
+        del idx[3]
+        self.assertTrue(nt.is_invalidated())
+
 
 # Conditional skipping done by the base class
 class RustInnerRevlogTest(
@@ -152,33 +182,6 @@
         # let's check bool for an empty one
         self.assertFalse(LazyAncestors(rustidx, [0], 0, False))
 
-    def test_standalone_nodetree(self):
-        idx = self.parserustindex()
-        nt = self.nodetree(idx)
-        for i in range(4):
-            nt.insert(i)
-
-        bin_nodes = [entry[7] for entry in idx]
-        hex_nodes = [hex(n) for n in bin_nodes]
-
-        for i, node in enumerate(hex_nodes):
-            self.assertEqual(nt.prefix_rev_lookup(node), i)
-            self.assertEqual(nt.prefix_rev_lookup(node[:5]), i)
-
-        # all 4 revisions in idx (standard data set) have different
-        # first nybbles in their Node IDs,
-        # hence `nt.shortest()` should return 1 for them, except when
-        # the leading nybble is 0 (ambiguity with NULL_NODE)
-        for i, (bin_node, hex_node) in enumerate(zip(bin_nodes, hex_nodes)):
-            shortest = nt.shortest(bin_node)
-            expected = 2 if hex_node[0] == ord('0') else 1
-            self.assertEqual(shortest, expected)
-            self.assertEqual(nt.prefix_rev_lookup(hex_node[:shortest]), i)
-
-        # test invalidation (generation poisoning) detection
-        del idx[3]
-        self.assertTrue(nt.is_invalidated())
-
 
 # Conditional skipping done by the base class
 class PyO3InnerRevlogTest(