tests/test-rust-revlog.py
author Joerg Sonnenberger <joerg@bec.de>
Mon, 06 Jul 2020 03:43:32 +0200
changeset 45118 d0ef8c1dddd4
parent 44015 443dc1655923
child 45957 89a2afe31e82
permissions -rw-r--r--
manifest: tigher manifest parsing and flag use In the manifest line, flags are put directly after the hash, so the parser has been guessing the presence of flags based on the length of the hash. Replace this assumption by an enumeration of the valid flags and removing them from the hash first as they are distinct input values. Consistently handle the expected 256bit length of the SHA1-replacement in the pure Python parser. Check that setting flags will use one of the blessed values. Extend write logic in the C version to handle 256bit hashes as well. Verify that hashes always have exactly the expected length. Since 1070df141718 we should no longer depend on the old extra-byte hack. Differential Revision: https://phab.mercurial-scm.org/D8679
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
     1
from __future__ import absolute_import
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
44014
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
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: 43966
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: 43966
diff changeset
    15
43966
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
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    18
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    19
@unittest.skipIf(
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    20
    rustext is None, "rustext module revlog relies on is not available",
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    21
)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    22
class RustRevlogIndexTest(revlogtesting.RevlogBasedTestBase):
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    23
    def test_heads(self):
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    24
        idx = self.parseindex()
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    25
        rustidx = revlog.MixedIndex(idx)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    26
        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
    27
44015
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
    28
    def test_get_cindex(self):
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
    29
        # 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: 44014
diff changeset
    30
        idx = self.parseindex()
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
    31
        rustidx = revlog.MixedIndex(idx)
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
    32
        cidx = rustidx.get_cindex()
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
    33
        self.assertTrue(idx is cidx)
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
    34
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    35
    def test_len(self):
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    36
        idx = self.parseindex()
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    37
        rustidx = revlog.MixedIndex(idx)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    38
        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
    39
44014
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    40
    def test_ancestors(self):
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    41
        idx = self.parseindex()
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    42
        rustidx = revlog.MixedIndex(idx)
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    43
        lazy = LazyAncestors(rustidx, [3], 0, True)
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    44
        # 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: 43966
diff changeset
    45
        # - 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: 43966
diff changeset
    46
        # - 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: 43966
diff changeset
    47
        self.assertTrue(2 in lazy)
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    48
        self.assertTrue(bool(lazy))
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    49
        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: 43966
diff changeset
    50
        # 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: 43966
diff changeset
    51
        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: 43966
diff changeset
    52
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    53
        # let's check bool for an empty one
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    54
        self.assertFalse(LazyAncestors(idx, [0], 0, False))
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43966
diff changeset
    55
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    56
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    57
if __name__ == '__main__':
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    58
    import silenttestrunner
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
    silenttestrunner.main(__name__)