annotate tests/test-rust-ancestor.py @ 52413:20fe0bf9a9a5

rust-pyo3: dagop submodule implementation This is the first demonstration that the passing of objects through the Python interpreter from `rustext` to `pyo3_rustext` actually works. In the Python tests, we conflate the presence of the `pyo3_rustext` package with that of `rustext`, as we do not plan to support building one and not the other (we hope to convert fully to PyO3 soon). The skipping is actually done by the base test class. The implementation of `rank` is as trivial as it was in `hg-cpython`, yet it required to be able to convert exceptions from `vcsgraph`.
author Georges Racinet <georges.racinet@cloudcrane.io>
date Sat, 30 Nov 2024 20:58:09 +0100
parents cf5b47b885b1
children 3ffcdbf0b432
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
1 import sys
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
2
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 43944
diff changeset
3 from mercurial.node import wdirrev
41350
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
4
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
5 from mercurial.testing import revlog as revlogtesting
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
6
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
7 try:
52413
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
8 from mercurial import pyo3_rustext, rustext
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
9
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
10 rustext.__name__ # trigger immediate actual import
52413
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
11 pyo3_rustext.__name__
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
12 except ImportError:
52413
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
13 rustext = pyo3_rustext = None
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
14 else:
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
15 # this would fail already without appropriate ancestor.__package__
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
16 from mercurial.rustext.ancestor import (
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
17 AncestorsIterator,
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
18 LazyAncestors,
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
19 MissingAncestors,
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
20 )
41694
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
21 from mercurial.rustext import dagop
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
22
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
23 try:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
24 from mercurial.cext import parsers as cparsers
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
25 except ImportError:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
26 cparsers = None
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
27
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
28
51241
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51238
diff changeset
29 class rustancestorstest(revlogtesting.RustRevlogBasedTestBase):
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
30 """Test the correctness of binding to Rust code.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
31
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
32 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
33 Python variable, giving back the results etc.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
34
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
35 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
36 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
37 good enough.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
38
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
39 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
40 """
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
41
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
42 def testiteratorrevlist(self):
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50976
diff changeset
43 idx = self.parserustindex()
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
44 # checking test assumption about the index binary data:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
45 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
46 {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
47 {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
48 )
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
49 ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
50 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
51
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
52 ait = AncestorsIterator(idx, [3], 0, False)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
53 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
54
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
55 def testlazyancestors(self):
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50976
diff changeset
56 idx = self.parserustindex()
52405
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
57 start_count = sys.getrefcount(idx.inner) # should be 2 (see Python doc)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
58 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
59 {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
60 {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
61 )
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
62 lazy = LazyAncestors(idx, [3], 0, True)
52405
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
63 # the LazyAncestors instance holds just one reference to the
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
64 # inner revlog.
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
65 self.assertEqual(sys.getrefcount(idx.inner), start_count + 1)
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
66
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
67 self.assertTrue(2 in lazy)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
68 self.assertTrue(bool(lazy))
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
69 self.assertEqual(list(lazy), [3, 2, 1, 0])
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
70 # 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
71 self.assertEqual(list(lazy), [3, 2, 1, 0])
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
72
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
73 # now let's watch the refcounts closer
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
74 ait = iter(lazy)
52405
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
75 self.assertEqual(sys.getrefcount(idx.inner), start_count + 2)
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
76 del ait
52405
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
77 self.assertEqual(sys.getrefcount(idx.inner), start_count + 1)
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
78 del lazy
52405
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
79 self.assertEqual(sys.getrefcount(idx.inner), start_count)
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
80
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
81 # let's check bool for an empty one
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
82 self.assertFalse(LazyAncestors(idx, [0], 0, False))
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
83
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
84 def testmissingancestors(self):
51237
59d81768ad6d rust-index: using `hg::index::Index` in MissingAncestors
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51236
diff changeset
85 idx = self.parserustindex()
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
86 missanc = MissingAncestors(idx, [1])
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
87 self.assertTrue(missanc.hasbases())
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
88 self.assertEqual(missanc.missingancestors([3]), [2, 3])
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
89 missanc.addbases({2})
41243
5257e6299d4c rust-cpython: set conversion for MissingAncestors.bases()
Georges Racinet <georges.racinet@octobus.net>
parents: 41188
diff changeset
90 self.assertEqual(missanc.bases(), {1, 2})
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
91 self.assertEqual(missanc.missingancestors([3]), [3])
41246
619ee4039bd4 rust: MissingAncestors.basesheads()
Georges Racinet <georges.racinet@octobus.net>
parents: 41243
diff changeset
92 self.assertEqual(missanc.basesheads(), {2})
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
93
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
94 def testmissingancestorsremove(self):
51237
59d81768ad6d rust-index: using `hg::index::Index` in MissingAncestors
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51236
diff changeset
95 idx = self.parserustindex()
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
96 missanc = MissingAncestors(idx, [1])
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
97 revs = {0, 1, 2, 3}
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
98 missanc.removeancestorsfrom(revs)
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
99 self.assertEqual(revs, {2, 3})
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
100
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
101 def testrefcount(self):
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50976
diff changeset
102 idx = self.parserustindex()
52405
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
103 start_count = sys.getrefcount(idx.inner)
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
104
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
105 # refcount increases upon iterator init...
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
106 ait = AncestorsIterator(idx, [3], 0, True)
52405
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
107 self.assertEqual(sys.getrefcount(idx.inner), start_count + 1)
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
108 self.assertEqual(next(ait), 3)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
109
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
110 # and decreases once the iterator is removed
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
111 del ait
52405
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51241
diff changeset
112 self.assertEqual(sys.getrefcount(idx.inner), start_count)
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
113
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
114 # 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
115 ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
116 del idx
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
117 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
118
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50976
diff changeset
119 # the index is not tracked by the GC, hence there is nothing more
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50976
diff changeset
120 # we can assert to check that it is properly deleted once its refcount
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50976
diff changeset
121 # drops to 0
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50976
diff changeset
122
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
123 def testgrapherror(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
124 data = (
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
125 revlogtesting.data_non_inlined[: 64 + 27]
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
126 + b'\xf2'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
127 + revlogtesting.data_non_inlined[64 + 28 :]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
128 )
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50976
diff changeset
129 idx = self.parserustindex(data=data)
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
130 with self.assertRaises(rustext.GraphError) as arc:
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
131 AncestorsIterator(idx, [1], -1, False)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
132 exc = arc.exception
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
133 self.assertIsInstance(exc, ValueError)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
134 # 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
135 self.assertEqual(exc.args, ('ParentOutOfRange', 1))
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
136
41350
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
137 def testwdirunsupported(self):
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
138 # trying to access ancestors of the working directory raises
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50976
diff changeset
139 idx = self.parserustindex()
50976
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48875
diff changeset
140 with self.assertRaises(rustext.GraphError) as arc:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 43944
diff changeset
141 list(AncestorsIterator(idx, [wdirrev], -1, False))
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
142
50976
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48875
diff changeset
143 exc = arc.exception
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48875
diff changeset
144 self.assertIsInstance(exc, ValueError)
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48875
diff changeset
145 # rust-cpython issues appropriate str instances for Python 2 and 3
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48875
diff changeset
146 self.assertEqual(exc.args, ('InvalidRevision', wdirrev))
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48875
diff changeset
147
41694
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
148 def testheadrevs(self):
51238
578c049f0408 rust-index: using `hg::index::Index` in `hg-cpython::dagops`
Georges Racinet <georges.racinet@octobus.net>
parents: 51237
diff changeset
149 idx = self.parserustindex()
41694
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
150 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
151
52413
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
152 def testpyo3_headrevs(self):
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
153 idx = self.parserustindex()
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
154 self.assertEqual(pyo3_rustext.dagop.headrevs(idx, [1, 2, 3]), {3})
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
155
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
156 def testpyo3_rank(self):
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
157 idx = self.parserustindex()
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
158 try:
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
159 pyo3_rustext.dagop.rank(idx, 1, 2)
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
160 except pyo3_rustext.GraphError as exc:
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
161 self.assertEqual(exc.args, ("InconsistentGraphData",))
20fe0bf9a9a5 rust-pyo3: dagop submodule implementation
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52405
diff changeset
162
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
163
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
164 if __name__ == '__main__':
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
165 import silenttestrunner
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
166
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
167 silenttestrunner.main(__name__)