Show More
@@ -15,7 +15,10 b' use std::cell::RefCell;' | |||||
15 |
|
15 | |||
16 | /// Return a Struct implementing the Graph trait |
|
16 | /// Return a Struct implementing the Graph trait | |
17 | pub(crate) fn pyindex_to_graph(py: Python, index: PyObject) -> PyResult<cindex::Index> { |
|
17 | pub(crate) fn pyindex_to_graph(py: Python, index: PyObject) -> PyResult<cindex::Index> { | |
18 | cindex::Index::new(py, index) |
|
18 | match index.extract::<MixedIndex>(py) { | |
|
19 | Ok(midx) => Ok(midx.clone_cindex(py)), | |||
|
20 | Err(_) => cindex::Index::new(py, index), | |||
|
21 | } | |||
19 | } |
|
22 | } | |
20 |
|
23 | |||
21 | py_class!(pub class MixedIndex |py| { |
|
24 | py_class!(pub class MixedIndex |py| { |
@@ -10,6 +10,9 b' except ImportError:' | |||||
10 | else: |
|
10 | else: | |
11 | from mercurial.rustext import revlog |
|
11 | from mercurial.rustext import revlog | |
12 |
|
12 | |||
|
13 | # this would fail already without appropriate ancestor.__package__ | |||
|
14 | from mercurial.rustext.ancestor import LazyAncestors | |||
|
15 | ||||
13 | from mercurial.testing import revlog as revlogtesting |
|
16 | from mercurial.testing import revlog as revlogtesting | |
14 |
|
17 | |||
15 |
|
18 | |||
@@ -27,6 +30,22 b' class RustRevlogIndexTest(revlogtesting.' | |||||
27 | rustidx = revlog.MixedIndex(idx) |
|
30 | rustidx = revlog.MixedIndex(idx) | |
28 | self.assertEqual(len(rustidx), len(idx)) |
|
31 | self.assertEqual(len(rustidx), len(idx)) | |
29 |
|
32 | |||
|
33 | def test_ancestors(self): | |||
|
34 | idx = self.parseindex() | |||
|
35 | rustidx = revlog.MixedIndex(idx) | |||
|
36 | lazy = LazyAncestors(rustidx, [3], 0, True) | |||
|
37 | # we have two more references to the index: | |||
|
38 | # - in its inner iterator for __contains__ and __bool__ | |||
|
39 | # - in the LazyAncestors instance itself (to spawn new iterators) | |||
|
40 | self.assertTrue(2 in lazy) | |||
|
41 | self.assertTrue(bool(lazy)) | |||
|
42 | self.assertEqual(list(lazy), [3, 2, 1, 0]) | |||
|
43 | # a second time to validate that we spawn new iterators | |||
|
44 | self.assertEqual(list(lazy), [3, 2, 1, 0]) | |||
|
45 | ||||
|
46 | # let's check bool for an empty one | |||
|
47 | self.assertFalse(LazyAncestors(idx, [0], 0, False)) | |||
|
48 | ||||
30 |
|
49 | |||
31 | if __name__ == '__main__': |
|
50 | if __name__ == '__main__': | |
32 | import silenttestrunner |
|
51 | import silenttestrunner |
General Comments 0
You need to be logged in to leave comments.
Login now