Show More
@@ -23,7 +23,10 data_non_inlined = ( | |||
|
23 | 23 | b'\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
|
24 | 24 | ) |
|
25 | 25 | |
|
26 |
from ..revlogutils.constants import |
|
|
26 | from ..revlogutils.constants import ( | |
|
27 | KIND_CHANGELOG, | |
|
28 | ) | |
|
29 | from .. import revlog | |
|
27 | 30 | |
|
28 | 31 | |
|
29 | 32 | try: |
@@ -32,11 +35,13 except ImportError: | |||
|
32 | 35 | cparsers = None |
|
33 | 36 | |
|
34 | 37 | try: |
|
35 |
from ..rustext |
|
|
36 |
|
|
|
38 | from ..rustext import ( # pytype: disable=import-error | |
|
39 | revlog as rust_revlog, | |
|
37 | 40 | ) |
|
41 | ||
|
42 | rust_revlog.__name__ # force actual import | |
|
38 | 43 | except ImportError: |
|
39 |
|
|
|
44 | rust_revlog = None | |
|
40 | 45 | |
|
41 | 46 | |
|
42 | 47 | @unittest.skipIf( |
@@ -51,14 +56,38 class RevlogBasedTestBase(unittest.TestC | |||
|
51 | 56 | |
|
52 | 57 | |
|
53 | 58 | @unittest.skipIf( |
|
54 |
|
|
|
55 |
'The Rust |
|
|
59 | rust_revlog is None, | |
|
60 | 'The Rust revlog module is not available. It is needed for this test.', | |
|
56 | 61 | ) |
|
57 | 62 | class RustRevlogBasedTestBase(unittest.TestCase): |
|
58 | def parserustindex(self, data=None): | |
|
63 | # defaults | |
|
64 | revlog_data_config = revlog.DataConfig() | |
|
65 | revlog_delta_config = revlog.DeltaConfig() | |
|
66 | revlog_feature_config = revlog.FeatureConfig() | |
|
67 | ||
|
68 | def make_inner_revlog( | |
|
69 | self, data=None, vfs_is_readonly=True, kind=KIND_CHANGELOG | |
|
70 | ): | |
|
59 | 71 | if data is None: |
|
60 | 72 | data = data_non_inlined |
|
61 | # not inheriting RevlogBasedTestCase to avoid having a | |
|
62 | # `parseindex` method that would be shadowed by future subclasses | |
|
63 | # this duplication will soon be removed | |
|
64 | return RustIndex(data, REVLOGV1) | |
|
73 | ||
|
74 | return rust_revlog.InnerRevlog( | |
|
75 | vfs_base=b"Just a path", | |
|
76 | fncache=None, # might be enough for now | |
|
77 | vfs_is_readonly=vfs_is_readonly, | |
|
78 | index_data=data, | |
|
79 | index_file=b'test.i', | |
|
80 | data_file=b'test.d', | |
|
81 | sidedata_file=None, | |
|
82 | inline=False, | |
|
83 | data_config=self.revlog_data_config, | |
|
84 | delta_config=self.revlog_delta_config, | |
|
85 | feature_config=self.revlog_feature_config, | |
|
86 | chunk_cache=None, | |
|
87 | default_compression_header=None, | |
|
88 | revlog_type=kind, | |
|
89 | use_persistent_nodemap=False, # until we cook one. | |
|
90 | ) | |
|
91 | ||
|
92 | def parserustindex(self, data=None): | |
|
93 | return revlog.RustIndexProxy(self.make_inner_revlog(data=data)) |
@@ -1,5 +1,4 | |||
|
1 | 1 | import sys |
|
2 | import unittest | |
|
3 | 2 | |
|
4 | 3 | from mercurial.node import wdirrev |
|
5 | 4 | |
@@ -26,16 +25,6 except ImportError: | |||
|
26 | 25 | cparsers = None |
|
27 | 26 | |
|
28 | 27 | |
|
29 | @unittest.skipIf( | |
|
30 | rustext is None, | |
|
31 | 'The Rust version of the "ancestor" module is not available. It is needed' | |
|
32 | ' for this test.', | |
|
33 | ) | |
|
34 | @unittest.skipIf( | |
|
35 | rustext is None, | |
|
36 | 'The Rust or C version of the "parsers" module, which the "ancestor" module' | |
|
37 | ' relies on, is not available.', | |
|
38 | ) | |
|
39 | 28 | class rustancestorstest(revlogtesting.RustRevlogBasedTestBase): |
|
40 | 29 | """Test the correctness of binding to Rust code. |
|
41 | 30 | |
@@ -64,16 +53,15 class rustancestorstest(revlogtesting.Ru | |||
|
64 | 53 | |
|
65 | 54 | def testlazyancestors(self): |
|
66 | 55 | idx = self.parserustindex() |
|
67 | start_count = sys.getrefcount(idx) # should be 2 (see Python doc) | |
|
56 | start_count = sys.getrefcount(idx.inner) # should be 2 (see Python doc) | |
|
68 | 57 | self.assertEqual( |
|
69 | 58 | {i: (r[5], r[6]) for i, r in enumerate(idx)}, |
|
70 | 59 | {0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)}, |
|
71 | 60 | ) |
|
72 | 61 | lazy = LazyAncestors(idx, [3], 0, True) |
|
73 | # we have two more references to the index: | |
|
74 | # - in its inner iterator for __contains__ and __bool__ | |
|
75 | # - in the LazyAncestors instance itself (to spawn new iterators) | |
|
76 | self.assertEqual(sys.getrefcount(idx), start_count + 2) | |
|
62 | # the LazyAncestors instance holds just one reference to the | |
|
63 | # inner revlog. | |
|
64 | self.assertEqual(sys.getrefcount(idx.inner), start_count + 1) | |
|
77 | 65 | |
|
78 | 66 | self.assertTrue(2 in lazy) |
|
79 | 67 | self.assertTrue(bool(lazy)) |
@@ -83,11 +71,11 class rustancestorstest(revlogtesting.Ru | |||
|
83 | 71 | |
|
84 | 72 | # now let's watch the refcounts closer |
|
85 | 73 | ait = iter(lazy) |
|
86 |
self.assertEqual(sys.getrefcount(idx), start_count + |
|
|
74 | self.assertEqual(sys.getrefcount(idx.inner), start_count + 2) | |
|
87 | 75 | del ait |
|
88 |
self.assertEqual(sys.getrefcount(idx), start_count + |
|
|
76 | self.assertEqual(sys.getrefcount(idx.inner), start_count + 1) | |
|
89 | 77 | del lazy |
|
90 | self.assertEqual(sys.getrefcount(idx), start_count) | |
|
78 | self.assertEqual(sys.getrefcount(idx.inner), start_count) | |
|
91 | 79 | |
|
92 | 80 | # let's check bool for an empty one |
|
93 | 81 | self.assertFalse(LazyAncestors(idx, [0], 0, False)) |
@@ -111,16 +99,16 class rustancestorstest(revlogtesting.Ru | |||
|
111 | 99 | |
|
112 | 100 | def testrefcount(self): |
|
113 | 101 | idx = self.parserustindex() |
|
114 | start_count = sys.getrefcount(idx) | |
|
102 | start_count = sys.getrefcount(idx.inner) | |
|
115 | 103 | |
|
116 | 104 | # refcount increases upon iterator init... |
|
117 | 105 | ait = AncestorsIterator(idx, [3], 0, True) |
|
118 | self.assertEqual(sys.getrefcount(idx), start_count + 1) | |
|
106 | self.assertEqual(sys.getrefcount(idx.inner), start_count + 1) | |
|
119 | 107 | self.assertEqual(next(ait), 3) |
|
120 | 108 | |
|
121 | 109 | # and decreases once the iterator is removed |
|
122 | 110 | del ait |
|
123 | self.assertEqual(sys.getrefcount(idx), start_count) | |
|
111 | self.assertEqual(sys.getrefcount(idx.inner), start_count) | |
|
124 | 112 | |
|
125 | 113 | # and removing ref to the index after iterator init is no issue |
|
126 | 114 | ait = AncestorsIterator(idx, [3], 0, True) |
General Comments 0
You need to be logged in to leave comments.
Login now