annotate mercurial/testing/revlog.py @ 52436:cf5b47b885b1

testing: stop skipping all Python tests of Rust revlog This base class was not adapted for the introduction of `InnerRevlog`, which also stopped exposing an `Index` class from `rustext`. As a consequence, `test-rust-ancestor.py` was always skipped (and would have been slightly broken). We remove the skipping conditions from `rustancestorstest`, as they now contradict or repeat those of the base class. Also, `LazyAncestors` objects apparently hold only one reference to the inner revlog (they had previously two references on the Rust index). What matters most of course is the return to `start_count` in these tests, i.e., that there is no memory leak nor double frees. In the Python test, 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.
author Georges Racinet <georges.racinet@cloudcrane.io>
date Sat, 30 Nov 2024 19:12:02 +0100
parents f4733654f144
children 07740bd86fd9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51901
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51275
diff changeset
1 from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51275
diff changeset
2
43950
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3 import unittest
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 # picked from test-parse-index2, copied rather than imported
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6 # so that it stays stable even if test-parse-index2 changes or disappears.
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
7 data_non_inlined = (
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8 b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01D\x19'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
9 b'\x00\x07e\x12\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
10 b'\xff\xff\xff\xff\xd1\xf4\xbb\xb0\xbe\xfc\x13\xbd\x8c\xd3\x9d'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
11 b'\x0f\xcd\xd9;\x8c\x07\x8cJ/\x00\x00\x00\x00\x00\x00\x00\x00\x00'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
12 b'\x00\x00\x00\x00\x00\x00\x01D\x19\x00\x00\x00\x00\x00\xdf\x00'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
13 b'\x00\x01q\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\xff'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
14 b'\xff\xff\xff\xc1\x12\xb9\x04\x96\xa4Z1t\x91\xdfsJ\x90\xf0\x9bh'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
15 b'\x07l&\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
16 b'\x00\x01D\xf8\x00\x00\x00\x00\x01\x1b\x00\x00\x01\xb8\x00\x00'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
17 b'\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\xff\xff\xff\xff\x02\n'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
18 b'\x0e\xc6&\xa1\x92\xae6\x0b\x02i\xfe-\xe5\xbao\x05\xd1\xe7\x00'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
19 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01F'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
20 b'\x13\x00\x00\x00\x00\x01\xec\x00\x00\x03\x06\x00\x00\x00\x01'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
21 b'\x00\x00\x00\x03\x00\x00\x00\x02\xff\xff\xff\xff\x12\xcb\xeby1'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
22 b'\xb6\r\x98B\xcb\x07\xbd`\x8f\x92\xd9\xc4\x84\xbdK\x00\x00\x00'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
23 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
24 )
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
25
52436
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
26 from ..revlogutils.constants import (
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
27 KIND_CHANGELOG,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
28 )
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
29 from .. import revlog
51260
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
30
43950
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
31
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
32 try:
46413
521ac0d7047f typing: disable import error warnings that are already handled
Matt Harbison <matt_harbison@yahoo.com>
parents: 43950
diff changeset
33 from ..cext import parsers as cparsers # pytype: disable=import-error
43950
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
34 except ImportError:
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
35 cparsers = None
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
36
51260
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
37 try:
52436
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
38 from ..rustext import ( # pytype: disable=import-error
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
39 revlog as rust_revlog,
51275
f94c10334bcb rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51274
diff changeset
40 )
52436
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
41
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
42 rust_revlog.__name__ # force actual import
51260
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
43 except ImportError:
52436
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
44 rust_revlog = None
51260
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
45
43950
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
46
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
47 @unittest.skipIf(
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
48 cparsers is None,
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
49 'The C version of the "parsers" module is not available. It is needed for this test.',
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
50 )
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
51 class RevlogBasedTestBase(unittest.TestCase):
51260
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
52 def parseindex(self, data=None):
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
53 if data is None:
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
54 data = data_non_inlined
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
55 return cparsers.parse_index2(data, False)[0]
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
56
51265
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51260
diff changeset
57
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51260
diff changeset
58 @unittest.skipIf(
52436
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
59 rust_revlog is None,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
60 'The Rust revlog module is not available. It is needed for this test.',
51265
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51260
diff changeset
61 )
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51260
diff changeset
62 class RustRevlogBasedTestBase(unittest.TestCase):
52436
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
63 # defaults
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
64 revlog_data_config = revlog.DataConfig()
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
65 revlog_delta_config = revlog.DeltaConfig()
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
66 revlog_feature_config = revlog.FeatureConfig()
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
67
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
68 def make_inner_revlog(
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
69 self, data=None, vfs_is_readonly=True, kind=KIND_CHANGELOG
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
70 ):
51260
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
71 if data is None:
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48966
diff changeset
72 data = data_non_inlined
52436
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
73
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
74 return rust_revlog.InnerRevlog(
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
75 vfs_base=b"Just a path",
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
76 fncache=None, # might be enough for now
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
77 vfs_is_readonly=vfs_is_readonly,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
78 index_data=data,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
79 index_file=b'test.i',
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
80 data_file=b'test.d',
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
81 sidedata_file=None,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
82 inline=False,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
83 data_config=self.revlog_data_config,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
84 delta_config=self.revlog_delta_config,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
85 feature_config=self.revlog_feature_config,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
86 chunk_cache=None,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
87 default_compression_header=None,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
88 revlog_type=kind,
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
89 use_persistent_nodemap=False, # until we cook one.
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
90 )
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
91
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
92 def parserustindex(self, data=None):
cf5b47b885b1 testing: stop skipping all Python tests of Rust revlog
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
93 return revlog.RustIndexProxy(self.make_inner_revlog(data=data))