comparison tests/test-rust-ancestor.py @ 43944:8a8305f557d0

test: extract some generic data and utility from test-rust-ancestor.py We will reuse this for more tests related to revlog index. In pratice this series of changesets add an index implementation provided from Rust and we want to be able to test it. Differential Revision: https://phab.mercurial-scm.org/D7652
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 11 Dec 2019 18:40:04 +0100
parents 2372284d9457
children 59fa3890d40a
comparison
equal deleted inserted replaced
43943:0671f0a19d93 43944:8a8305f557d0
4 4
5 from mercurial import ( 5 from mercurial import (
6 error, 6 error,
7 node, 7 node,
8 ) 8 )
9
10 from mercurial.testing import revlog as revlogtesting
9 11
10 try: 12 try:
11 from mercurial import rustext 13 from mercurial import rustext
12 14
13 rustext.__name__ # trigger immediate actual import 15 rustext.__name__ # trigger immediate actual import
25 try: 27 try:
26 from mercurial.cext import parsers as cparsers 28 from mercurial.cext import parsers as cparsers
27 except ImportError: 29 except ImportError:
28 cparsers = None 30 cparsers = None
29 31
30 # picked from test-parse-index2, copied rather than imported
31 # so that it stays stable even if test-parse-index2 changes or disappears.
32 data_non_inlined = (
33 b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01D\x19'
34 b'\x00\x07e\x12\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff'
35 b'\xff\xff\xff\xff\xd1\xf4\xbb\xb0\xbe\xfc\x13\xbd\x8c\xd3\x9d'
36 b'\x0f\xcd\xd9;\x8c\x07\x8cJ/\x00\x00\x00\x00\x00\x00\x00\x00\x00'
37 b'\x00\x00\x00\x00\x00\x00\x01D\x19\x00\x00\x00\x00\x00\xdf\x00'
38 b'\x00\x01q\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\xff'
39 b'\xff\xff\xff\xc1\x12\xb9\x04\x96\xa4Z1t\x91\xdfsJ\x90\xf0\x9bh'
40 b'\x07l&\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
41 b'\x00\x01D\xf8\x00\x00\x00\x00\x01\x1b\x00\x00\x01\xb8\x00\x00'
42 b'\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\xff\xff\xff\xff\x02\n'
43 b'\x0e\xc6&\xa1\x92\xae6\x0b\x02i\xfe-\xe5\xbao\x05\xd1\xe7\x00'
44 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01F'
45 b'\x13\x00\x00\x00\x00\x01\xec\x00\x00\x03\x06\x00\x00\x00\x01'
46 b'\x00\x00\x00\x03\x00\x00\x00\x02\xff\xff\xff\xff\x12\xcb\xeby1'
47 b'\xb6\r\x98B\xcb\x07\xbd`\x8f\x92\xd9\xc4\x84\xbdK\x00\x00\x00'
48 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00'
49 )
50
51 32
52 @unittest.skipIf( 33 @unittest.skipIf(
53 rustext is None or cparsers is None, 34 rustext is None,
54 "rustext or the C Extension parsers module " 35 'The Rust version of the "ancestor" module is not available. It is needed'
55 "ancestor relies on is not available", 36 ' for this test.',
56 ) 37 )
57 class rustancestorstest(unittest.TestCase): 38 @unittest.skipIf(
39 rustext is None,
40 'The Rust or C version of the "parsers" module, which the "ancestor" module'
41 ' relies on, is not available.',
42 )
43 class rustancestorstest(revlogtesting.RevlogBasedTestBase):
58 """Test the correctness of binding to Rust code. 44 """Test the correctness of binding to Rust code.
59 45
60 This test is merely for the binding to Rust itself: extraction of 46 This test is merely for the binding to Rust itself: extraction of
61 Python variable, giving back the results etc. 47 Python variable, giving back the results etc.
62 48
64 on ancestors it provides. Hence the very simple embedded index data is 50 on ancestors it provides. Hence the very simple embedded index data is
65 good enough. 51 good enough.
66 52
67 Algorithmic correctness is asserted by the Rust unit tests. 53 Algorithmic correctness is asserted by the Rust unit tests.
68 """ 54 """
69
70 def parseindex(self):
71 return cparsers.parse_index2(data_non_inlined, False)[0]
72 55
73 def testiteratorrevlist(self): 56 def testiteratorrevlist(self):
74 idx = self.parseindex() 57 idx = self.parseindex()
75 # checking test assumption about the index binary data: 58 # checking test assumption about the index binary data:
76 self.assertEqual( 59 self.assertEqual(
148 del idx 131 del idx
149 self.assertEqual(list(ait), [3, 2, 1, 0]) 132 self.assertEqual(list(ait), [3, 2, 1, 0])
150 133
151 def testgrapherror(self): 134 def testgrapherror(self):
152 data = ( 135 data = (
153 data_non_inlined[: 64 + 27] + b'\xf2' + data_non_inlined[64 + 28 :] 136 revlogtesting.data_non_inlined[: 64 + 27]
137 + b'\xf2'
138 + revlogtesting.data_non_inlined[64 + 28 :]
154 ) 139 )
155 idx = cparsers.parse_index2(data, False)[0] 140 idx = cparsers.parse_index2(data, False)[0]
156 with self.assertRaises(rustext.GraphError) as arc: 141 with self.assertRaises(rustext.GraphError) as arc:
157 AncestorsIterator(idx, [1], -1, False) 142 AncestorsIterator(idx, [1], -1, False)
158 exc = arc.exception 143 exc = arc.exception