author | Georges Racinet <georges.racinet@octobus.net> |
Fri, 27 Oct 2023 22:11:05 +0200 | |
changeset 51239 | 7eea2e4109ae |
parent 51191 | 13f58ce70299 |
child 51249 | 2966b88d4531 |
permissions | -rw-r--r-- |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51190
diff
changeset
|
1 |
import struct |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
2 |
import unittest |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
3 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
4 |
try: |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
5 |
from mercurial import rustext |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
6 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
7 |
rustext.__name__ # trigger immediate actual import |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
8 |
except ImportError: |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
9 |
rustext = None |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
10 |
else: |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
11 |
from mercurial.rustext import revlog |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
12 |
|
44011
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
13 |
# this would fail already without appropriate ancestor.__package__ |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
14 |
from mercurial.rustext.ancestor import LazyAncestors |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
15 |
|
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
16 |
from mercurial.testing import revlog as revlogtesting |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
17 |
|
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51190
diff
changeset
|
18 |
header = struct.unpack(">I", revlogtesting.data_non_inlined[:4])[0] |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51190
diff
changeset
|
19 |
|
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
20 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
21 |
@unittest.skipIf( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44012
diff
changeset
|
22 |
rustext is None, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44012
diff
changeset
|
23 |
"rustext module revlog relies on is not available", |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
24 |
) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
25 |
class RustRevlogIndexTest(revlogtesting.RevlogBasedTestBase): |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
26 |
def test_heads(self): |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
27 |
idx = self.parseindex() |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51190
diff
changeset
|
28 |
rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined, header) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
29 |
self.assertEqual(rustidx.headrevs(), idx.headrevs()) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
30 |
|
44012
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
31 |
def test_get_cindex(self): |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
32 |
# drop me once we no longer need the method for shortest node |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
33 |
idx = self.parseindex() |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51190
diff
changeset
|
34 |
rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined, header) |
44012
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
35 |
cidx = rustidx.get_cindex() |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
36 |
self.assertTrue(idx is cidx) |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
37 |
|
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
38 |
def test_len(self): |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
39 |
idx = self.parseindex() |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51190
diff
changeset
|
40 |
rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined, header) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
41 |
self.assertEqual(len(rustidx), len(idx)) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
42 |
|
44011
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
43 |
def test_ancestors(self): |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
44 |
idx = self.parseindex() |
51191
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Raphaël Gomès <rgomes@octobus.net>
parents:
51190
diff
changeset
|
45 |
rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined, header) |
44011
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
46 |
lazy = LazyAncestors(rustidx, [3], 0, True) |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
47 |
# we have two more references to the index: |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
48 |
# - in its inner iterator for __contains__ and __bool__ |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
49 |
# - in the LazyAncestors instance itself (to spawn new iterators) |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
50 |
self.assertTrue(2 in lazy) |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
51 |
self.assertTrue(bool(lazy)) |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
52 |
self.assertEqual(list(lazy), [3, 2, 1, 0]) |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
53 |
# a second time to validate that we spawn new iterators |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
54 |
self.assertEqual(list(lazy), [3, 2, 1, 0]) |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
55 |
|
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
56 |
# let's check bool for an empty one |
51239
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51191
diff
changeset
|
57 |
self.assertFalse(LazyAncestors(rustidx, [0], 0, False)) |
44011
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43961
diff
changeset
|
58 |
|
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
59 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
60 |
if __name__ == '__main__': |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
61 |
import silenttestrunner |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
62 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
63 |
silenttestrunner.main(__name__) |