annotate tests/test-rust-ancestor.py @ 41091:d9b6b9ed96d8

vfs: add a `_auditpath` to abstract vfs We are about to make `rename` audit path. Since rename lives in the `abstractvfs` layer, we need it to be aware of auditing to some extent. The default implementation is no-op because multiple existing vfs are not using auditing at all right now (eg: fncachevfs).
author Boris Feld <boris.feld@octobus.net>
date Wed, 26 Dec 2018 13:44:23 +0100
parents d9f439fcdb4c
children b31a41f24864
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
1 from __future__ import absolute_import
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
2 import sys
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
3 import unittest
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
4
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
5 try:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
6 from mercurial import rustext
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
7 rustext.__name__ # trigger immediate actual import
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
8 except ImportError:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
9 rustext = None
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
10 else:
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
11 # this would fail already without appropriate ancestor.__package__
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
12 from mercurial.rustext.ancestor import AncestorsIterator
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
13
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
14 try:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
15 from mercurial.cext import parsers as cparsers
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
16 except ImportError:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
17 cparsers = None
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
18
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
19 # picked from test-parse-index2, copied rather than imported
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
20 # so that it stays stable even if test-parse-index2 changes or disappears.
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
21 data_non_inlined = (
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
22 b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01D\x19'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
23 b'\x00\x07e\x12\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
24 b'\xff\xff\xff\xff\xd1\xf4\xbb\xb0\xbe\xfc\x13\xbd\x8c\xd3\x9d'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
25 b'\x0f\xcd\xd9;\x8c\x07\x8cJ/\x00\x00\x00\x00\x00\x00\x00\x00\x00'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
26 b'\x00\x00\x00\x00\x00\x00\x01D\x19\x00\x00\x00\x00\x00\xdf\x00'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
27 b'\x00\x01q\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\xff'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
28 b'\xff\xff\xff\xc1\x12\xb9\x04\x96\xa4Z1t\x91\xdfsJ\x90\xf0\x9bh'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
29 b'\x07l&\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
30 b'\x00\x01D\xf8\x00\x00\x00\x00\x01\x1b\x00\x00\x01\xb8\x00\x00'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
31 b'\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\xff\xff\xff\xff\x02\n'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
32 b'\x0e\xc6&\xa1\x92\xae6\x0b\x02i\xfe-\xe5\xbao\x05\xd1\xe7\x00'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
33 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01F'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
34 b'\x13\x00\x00\x00\x00\x01\xec\x00\x00\x03\x06\x00\x00\x00\x01'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
35 b'\x00\x00\x00\x03\x00\x00\x00\x02\xff\xff\xff\xff\x12\xcb\xeby1'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
36 b'\xb6\r\x98B\xcb\x07\xbd`\x8f\x92\xd9\xc4\x84\xbdK\x00\x00\x00'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
37 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00'
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
38 )
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
39
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
40
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
41 @unittest.skipIf(rustext is None or cparsers is None,
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
42 "rustext or the C Extension parsers module "
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
43 "ancestor relies on is not available")
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
44 class rustancestorstest(unittest.TestCase):
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
45 """Test the correctness of binding to Rust code.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
46
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
47 This test is merely for the binding to Rust itself: extraction of
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
48 Python variable, giving back the results etc.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
49
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
50 It is not meant to test the algorithmic correctness of the operations
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
51 on ancestors it provides. Hence the very simple embedded index data is
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
52 good enough.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
53
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
54 Algorithmic correctness is asserted by the Rust unit tests.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
55 """
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
56
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
57 def parseindex(self):
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
58 return cparsers.parse_index2(data_non_inlined, False)[0]
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
59
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
60 def testiteratorrevlist(self):
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
61 idx = self.parseindex()
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
62 # checking test assumption about the index binary data:
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
63 self.assertEqual({i: (r[5], r[6]) for i, r in enumerate(idx)},
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
64 {0: (-1, -1),
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
65 1: (0, -1),
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
66 2: (1, -1),
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
67 3: (2, -1)})
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
68 ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
69 self.assertEqual([r for r in ait], [3, 2, 1, 0])
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
70
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
71 ait = AncestorsIterator(idx, [3], 0, False)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
72 self.assertEqual([r for r in ait], [2, 1, 0])
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
73
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
74 def testrefcount(self):
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
75 idx = self.parseindex()
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
76 start_count = sys.getrefcount(idx)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
77
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
78 # refcount increases upon iterator init...
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
79 ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
80 self.assertEqual(sys.getrefcount(idx), start_count + 1)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
81 self.assertEqual(next(ait), 3)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
82
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
83 # and decreases once the iterator is removed
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
84 del ait
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
85 self.assertEqual(sys.getrefcount(idx), start_count)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
86
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
87 # and removing ref to the index after iterator init is no issue
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
88 ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
89 del idx
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
90 self.assertEqual([r for r in ait], [3, 2, 1, 0])
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
91
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
92 def testgrapherror(self):
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
93 data = (data_non_inlined[:64 + 27] +
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
94 b'\xf2' +
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
95 data_non_inlined[64 + 28:])
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
96 idx = cparsers.parse_index2(data, False)[0]
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
97 with self.assertRaises(rustext.GraphError) as arc:
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
98 AncestorsIterator(idx, [1], -1, False)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
99 exc = arc.exception
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
100 self.assertIsInstance(exc, ValueError)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
101 # rust-cpython issues appropriate str instances for Python 2 and 3
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
102 self.assertEqual(exc.args, ('ParentOutOfRange', 1))
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
103
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
104
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
105 if __name__ == '__main__':
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
106 import silenttestrunner
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
107 silenttestrunner.main(__name__)