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