author | Gregory Szorc <gregory.szorc@gmail.com> |
Wed, 23 Oct 2019 13:21:35 -0700 | |
changeset 43607 | a2f28a8746bf |
parent 43076 | 2372284d9457 |
child 43944 | 8a8305f557d0 |
permissions | -rw-r--r-- |
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 |
|
41350
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
5 |
from mercurial import ( |
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
6 |
error, |
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
7 |
node, |
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
8 |
) |
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
9 |
|
40968
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
10 |
try: |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
11 |
from mercurial import rustext |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
12 |
|
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
13 |
rustext.__name__ # trigger immediate actual import |
40968
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
14 |
except ImportError: |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
15 |
rustext = None |
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
16 |
else: |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
17 |
# this would fail already without appropriate ancestor.__package__ |
41114
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
18 |
from mercurial.rustext.ancestor import ( |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
19 |
AncestorsIterator, |
41188
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
20 |
LazyAncestors, |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
21 |
MissingAncestors, |
41114
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
22 |
) |
41694
0c7b353ce100
rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41350
diff
changeset
|
23 |
from mercurial.rustext import dagop |
40968
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
24 |
|
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
25 |
try: |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
26 |
from mercurial.cext import parsers as cparsers |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
27 |
except ImportError: |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
28 |
cparsers = None |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
29 |
|
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
30 |
# picked from test-parse-index2, copied rather than imported |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
31 |
# 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
|
32 |
data_non_inlined = ( |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
49 |
) |
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
50 |
|
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
51 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
52 |
@unittest.skipIf( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
53 |
rustext is None or cparsers is None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
54 |
"rustext or the C Extension parsers module " |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
55 |
"ancestor relies on is not available", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
56 |
) |
40968
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
57 |
class rustancestorstest(unittest.TestCase): |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
58 |
"""Test the correctness of binding to Rust code. |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
59 |
|
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
60 |
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
|
61 |
Python variable, giving back the results etc. |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
62 |
|
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
good enough. |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
66 |
|
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
67 |
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
|
68 |
""" |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
69 |
|
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
70 |
def parseindex(self): |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
71 |
return cparsers.parse_index2(data_non_inlined, False)[0] |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
72 |
|
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
73 |
def testiteratorrevlist(self): |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
74 |
idx = self.parseindex() |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
75 |
# checking test assumption about the index binary data: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
76 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
77 |
{i: (r[5], r[6]) for i, r in enumerate(idx)}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
78 |
{0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
79 |
) |
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
80 |
ait = AncestorsIterator(idx, [3], 0, True) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
81 |
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
|
82 |
|
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
83 |
ait = AncestorsIterator(idx, [3], 0, False) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
84 |
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
|
85 |
|
41114
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
86 |
def testlazyancestors(self): |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
87 |
idx = self.parseindex() |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
88 |
start_count = sys.getrefcount(idx) # should be 2 (see Python doc) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
89 |
self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
90 |
{i: (r[5], r[6]) for i, r in enumerate(idx)}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
91 |
{0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
92 |
) |
41114
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
93 |
lazy = LazyAncestors(idx, [3], 0, True) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
94 |
# we have two more references to the index: |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
95 |
# - in its inner iterator for __contains__ and __bool__ |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
96 |
# - in the LazyAncestors instance itself (to spawn new iterators) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
97 |
self.assertEqual(sys.getrefcount(idx), start_count + 2) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
98 |
|
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
99 |
self.assertTrue(2 in lazy) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
100 |
self.assertTrue(bool(lazy)) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
101 |
self.assertEqual(list(lazy), [3, 2, 1, 0]) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
102 |
# a second time to validate that we spawn new iterators |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
103 |
self.assertEqual(list(lazy), [3, 2, 1, 0]) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
104 |
|
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
105 |
# now let's watch the refcounts closer |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
106 |
ait = iter(lazy) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
107 |
self.assertEqual(sys.getrefcount(idx), start_count + 3) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
108 |
del ait |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
109 |
self.assertEqual(sys.getrefcount(idx), start_count + 2) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
110 |
del lazy |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
111 |
self.assertEqual(sys.getrefcount(idx), start_count) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
112 |
|
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
113 |
# let's check bool for an empty one |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
114 |
self.assertFalse(LazyAncestors(idx, [0], 0, False)) |
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
115 |
|
41188
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
116 |
def testmissingancestors(self): |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
117 |
idx = self.parseindex() |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
118 |
missanc = MissingAncestors(idx, [1]) |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
119 |
self.assertTrue(missanc.hasbases()) |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
120 |
self.assertEqual(missanc.missingancestors([3]), [2, 3]) |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
121 |
missanc.addbases({2}) |
41243
5257e6299d4c
rust-cpython: set conversion for MissingAncestors.bases()
Georges Racinet <georges.racinet@octobus.net>
parents:
41188
diff
changeset
|
122 |
self.assertEqual(missanc.bases(), {1, 2}) |
41188
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
123 |
self.assertEqual(missanc.missingancestors([3]), [3]) |
41246
619ee4039bd4
rust: MissingAncestors.basesheads()
Georges Racinet <georges.racinet@octobus.net>
parents:
41243
diff
changeset
|
124 |
self.assertEqual(missanc.basesheads(), {2}) |
41188
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
125 |
|
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
126 |
def testmissingancestorsremove(self): |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
127 |
idx = self.parseindex() |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
128 |
missanc = MissingAncestors(idx, [1]) |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
129 |
revs = {0, 1, 2, 3} |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
130 |
missanc.removeancestorsfrom(revs) |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
131 |
self.assertEqual(revs, {2, 3}) |
006c9ce486fa
rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents:
41114
diff
changeset
|
132 |
|
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
133 |
def testrefcount(self): |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
134 |
idx = self.parseindex() |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
135 |
start_count = sys.getrefcount(idx) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
136 |
|
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
137 |
# refcount increases upon iterator init... |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
138 |
ait = AncestorsIterator(idx, [3], 0, True) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
139 |
self.assertEqual(sys.getrefcount(idx), start_count + 1) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
140 |
self.assertEqual(next(ait), 3) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
141 |
|
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
142 |
# and decreases once the iterator is removed |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
143 |
del ait |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
144 |
self.assertEqual(sys.getrefcount(idx), start_count) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
145 |
|
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
146 |
# 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
|
147 |
ait = AncestorsIterator(idx, [3], 0, True) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
148 |
del idx |
41114
b31a41f24864
rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents:
41053
diff
changeset
|
149 |
self.assertEqual(list(ait), [3, 2, 1, 0]) |
40968
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
150 |
|
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
151 |
def testgrapherror(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
152 |
data = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
153 |
data_non_inlined[: 64 + 27] + b'\xf2' + data_non_inlined[64 + 28 :] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
154 |
) |
41053
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
155 |
idx = cparsers.parse_index2(data, False)[0] |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
156 |
with self.assertRaises(rustext.GraphError) as arc: |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
157 |
AncestorsIterator(idx, [1], -1, False) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
158 |
exc = arc.exception |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
159 |
self.assertIsInstance(exc, ValueError) |
d9f439fcdb4c
rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents:
40968
diff
changeset
|
160 |
# 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
|
161 |
self.assertEqual(exc.args, ('ParentOutOfRange', 1)) |
40968
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
162 |
|
41350
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
163 |
def testwdirunsupported(self): |
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
164 |
# trying to access ancestors of the working directory raises |
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
165 |
# WdirUnsupported directly |
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
166 |
idx = self.parseindex() |
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
167 |
with self.assertRaises(error.WdirUnsupported): |
ab0d762d89ef
rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents:
41246
diff
changeset
|
168 |
list(AncestorsIterator(idx, [node.wdirrev], -1, False)) |
40968
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
169 |
|
41694
0c7b353ce100
rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41350
diff
changeset
|
170 |
def testheadrevs(self): |
0c7b353ce100
rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41350
diff
changeset
|
171 |
idx = self.parseindex() |
0c7b353ce100
rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41350
diff
changeset
|
172 |
self.assertEqual(dagop.headrevs(idx, [1, 2, 3]), {3}) |
0c7b353ce100
rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41350
diff
changeset
|
173 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
174 |
|
40968
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
175 |
if __name__ == '__main__': |
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
176 |
import silenttestrunner |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41694
diff
changeset
|
177 |
|
40968
74f41329bf55
rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
178 |
silenttestrunner.main(__name__) |