mercurial/testing/revlog.py
author Matt Harbison <matt_harbison@yahoo.com>
Mon, 16 Sep 2024 15:36:44 +0200
changeset 51863 f4733654f144
parent 51254 f94c10334bcb
permissions -rw-r--r--
typing: add `from __future__ import annotations` to most files Now that py36 is no longer supported, we can postpone annotation evaluation. This means that the quoting is usually optional (for things imported under the guard of `if typing.TYPE_CHECKING:` to avoid circular imports), and there's less overhead on startup[1]. There may be some missing here. I backed out 6000f5b25c9b (which removed the `from __future__ import ...` that was supporting py2), reverted the changes in `contrib/`, `doc/`, and `tests/`, and then ran: $ hg status -n --change . | \ xargs sed -i -e 's/from __future__ import .*$/from __future__ import annotations/' There were some minor tweaks needed when reviewing (mostly making the spacing around the import consistent, and `mercurial/testing/__init__.py` had a multiline import that wasn't fully rewritten. [1] https://docs.python.org/3/whatsnew/3.7.html#pep-563-postponed-evaluation-of-annotations
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51863
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51254
diff changeset
     1
from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51254
diff changeset
     2
43944
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
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48875
diff changeset
    26
from ..revlogutils.constants import REVLOGV1
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48875
diff changeset
    27
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    28
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    29
try:
46785
521ac0d7047f typing: disable import error warnings that are already handled
Matt Harbison <matt_harbison@yahoo.com>
parents: 43944
diff changeset
    30
    from ..cext import parsers as cparsers  # pytype: disable=import-error
43944
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
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
    32
    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
    33
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48875
diff changeset
    34
try:
51254
f94c10334bcb rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51253
diff changeset
    35
    from ..rustext.revlog import (  # pytype: disable=import-error
f94c10334bcb rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51253
diff changeset
    36
        Index as RustIndex,
f94c10334bcb rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51253
diff changeset
    37
    )
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48875
diff changeset
    38
except ImportError:
51254
f94c10334bcb rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51253
diff changeset
    39
    RustIndex = None
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48875
diff changeset
    40
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    41
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    42
@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
    43
    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
    44
    '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
    45
)
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
class RevlogBasedTestBase(unittest.TestCase):
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48875
diff changeset
    47
    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: 48875
diff changeset
    48
        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: 48875
diff changeset
    49
            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: 48875
diff changeset
    50
        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: 48875
diff changeset
    51
51244
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
    52
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
    53
@unittest.skipIf(
51254
f94c10334bcb rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51253
diff changeset
    54
    RustIndex is None,
51244
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
    55
    'The Rust index is not available. It is needed for this test.',
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
    56
)
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
    57
class RustRevlogBasedTestBase(unittest.TestCase):
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48875
diff changeset
    58
    def parserustindex(self, data=None):
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 48875
diff changeset
    59
        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: 48875
diff changeset
    60
            data = data_non_inlined
51244
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
    61
        # not inheriting RevlogBasedTestCase to avoid having a
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
    62
        # `parseindex` method that would be shadowed by future subclasses
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
    63
        # this duplication will soon be removed
51254
f94c10334bcb rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51253
diff changeset
    64
        return RustIndex(data, REVLOGV1)