tests/test-rust-ancestor.py
author Kyle Lippincott <spectral@google.com>
Wed, 01 Apr 2020 14:14:55 -0700
branchstable
changeset 44611 8fca7e8449a8
parent 43944 8a8305f557d0
child 46113 59fa3890d40a
permissions -rw-r--r--
histedit: add missing b prefix to a string If i18n is disabled (such as via HGPLAIN=1), `_()` doesn't convert from str to bytes, so this raises a TypeError on py3. Differential Revision: https://phab.mercurial-scm.org/D8354
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
     1
from __future__ import absolute_import
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
     2
import sys
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
     3
import unittest
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
     4
41350
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
     5
from mercurial import (
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
     6
    error,
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
     7
    node,
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
     8
)
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
     9
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    10
from mercurial.testing import revlog as revlogtesting
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    11
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    12
try:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    13
    from mercurial import rustext
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    14
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    15
    rustext.__name__  # trigger immediate actual import
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    16
except ImportError:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    17
    rustext = None
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    18
else:
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    19
    # this would fail already without appropriate ancestor.__package__
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    20
    from mercurial.rustext.ancestor import (
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    21
        AncestorsIterator,
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
    22
        LazyAncestors,
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
    23
        MissingAncestors,
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    24
    )
41694
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
    25
    from mercurial.rustext import dagop
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    26
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    27
try:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    28
    from mercurial.cext import parsers as cparsers
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    29
except ImportError:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    30
    cparsers = None
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    31
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    32
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    33
@unittest.skipIf(
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    34
    rustext is None,
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    35
    'The Rust version of the "ancestor" module is not available. It is needed'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    36
    ' for this test.',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    37
)
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    38
@unittest.skipIf(
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    39
    rustext is None,
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    40
    'The Rust or C version of the "parsers" module, which the "ancestor" module'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    41
    ' relies on, is not available.',
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    42
)
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    43
class rustancestorstest(revlogtesting.RevlogBasedTestBase):
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    44
    """Test the correctness of binding to Rust code.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    45
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    46
    This test is merely for the binding to Rust itself: extraction of
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    47
    Python variable, giving back the results etc.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    48
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    49
    It is not meant to test the algorithmic correctness of the operations
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    50
    on ancestors it provides. Hence the very simple embedded index data is
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    51
    good enough.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    52
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    53
    Algorithmic correctness is asserted by the Rust unit tests.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    54
    """
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    55
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    56
    def testiteratorrevlist(self):
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    57
        idx = self.parseindex()
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    58
        # checking test assumption about the index binary data:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    59
        self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    60
            {i: (r[5], r[6]) for i, r in enumerate(idx)},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    61
            {0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    62
        )
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    63
        ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    64
        self.assertEqual([r for r in ait], [3, 2, 1, 0])
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    65
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    66
        ait = AncestorsIterator(idx, [3], 0, False)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    67
        self.assertEqual([r for r in ait], [2, 1, 0])
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
    68
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    69
    def testlazyancestors(self):
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    70
        idx = self.parseindex()
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    71
        start_count = sys.getrefcount(idx)  # should be 2 (see Python doc)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    72
        self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    73
            {i: (r[5], r[6]) for i, r in enumerate(idx)},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    74
            {0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
    75
        )
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    76
        lazy = LazyAncestors(idx, [3], 0, True)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    77
        # we have two more references to the index:
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    78
        # - in its inner iterator for __contains__ and __bool__
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    79
        # - in the LazyAncestors instance itself (to spawn new iterators)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    80
        self.assertEqual(sys.getrefcount(idx), start_count + 2)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    81
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    82
        self.assertTrue(2 in lazy)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    83
        self.assertTrue(bool(lazy))
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    84
        self.assertEqual(list(lazy), [3, 2, 1, 0])
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    85
        # a second time to validate that we spawn new iterators
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    86
        self.assertEqual(list(lazy), [3, 2, 1, 0])
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    87
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    88
        # now let's watch the refcounts closer
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    89
        ait = iter(lazy)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    90
        self.assertEqual(sys.getrefcount(idx), start_count + 3)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    91
        del ait
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    92
        self.assertEqual(sys.getrefcount(idx), start_count + 2)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    93
        del lazy
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    94
        self.assertEqual(sys.getrefcount(idx), start_count)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    95
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    96
        # let's check bool for an empty one
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    97
        self.assertFalse(LazyAncestors(idx, [0], 0, False))
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
    98
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
    99
    def testmissingancestors(self):
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   100
        idx = self.parseindex()
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   101
        missanc = MissingAncestors(idx, [1])
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   102
        self.assertTrue(missanc.hasbases())
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   103
        self.assertEqual(missanc.missingancestors([3]), [2, 3])
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   104
        missanc.addbases({2})
41243
5257e6299d4c rust-cpython: set conversion for MissingAncestors.bases()
Georges Racinet <georges.racinet@octobus.net>
parents: 41188
diff changeset
   105
        self.assertEqual(missanc.bases(), {1, 2})
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   106
        self.assertEqual(missanc.missingancestors([3]), [3])
41246
619ee4039bd4 rust: MissingAncestors.basesheads()
Georges Racinet <georges.racinet@octobus.net>
parents: 41243
diff changeset
   107
        self.assertEqual(missanc.basesheads(), {2})
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   108
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   109
    def testmissingancestorsremove(self):
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   110
        idx = self.parseindex()
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   111
        missanc = MissingAncestors(idx, [1])
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   112
        revs = {0, 1, 2, 3}
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   113
        missanc.removeancestorsfrom(revs)
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   114
        self.assertEqual(revs, {2, 3})
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
   115
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   116
    def testrefcount(self):
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   117
        idx = self.parseindex()
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   118
        start_count = sys.getrefcount(idx)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   119
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   120
        # refcount increases upon iterator init...
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   121
        ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   122
        self.assertEqual(sys.getrefcount(idx), start_count + 1)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   123
        self.assertEqual(next(ait), 3)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   124
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   125
        # and decreases once the iterator is removed
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   126
        del ait
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   127
        self.assertEqual(sys.getrefcount(idx), start_count)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   128
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   129
        # and removing ref to the index after iterator init is no issue
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   130
        ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   131
        del idx
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
   132
        self.assertEqual(list(ait), [3, 2, 1, 0])
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
   133
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
   134
    def testgrapherror(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
   135
        data = (
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
   136
            revlogtesting.data_non_inlined[: 64 + 27]
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
   137
            + b'\xf2'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
   138
            + revlogtesting.data_non_inlined[64 + 28 :]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
   139
        )
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   140
        idx = cparsers.parse_index2(data, False)[0]
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   141
        with self.assertRaises(rustext.GraphError) as arc:
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   142
            AncestorsIterator(idx, [1], -1, False)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   143
        exc = arc.exception
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   144
        self.assertIsInstance(exc, ValueError)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   145
        # rust-cpython issues appropriate str instances for Python 2 and 3
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
   146
        self.assertEqual(exc.args, ('ParentOutOfRange', 1))
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
   147
41350
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
   148
    def testwdirunsupported(self):
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
   149
        # trying to access ancestors of the working directory raises
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
   150
        # WdirUnsupported directly
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
   151
        idx = self.parseindex()
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
   152
        with self.assertRaises(error.WdirUnsupported):
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
   153
            list(AncestorsIterator(idx, [node.wdirrev], -1, False))
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
   154
41694
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
   155
    def testheadrevs(self):
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
   156
        idx = self.parseindex()
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
   157
        self.assertEqual(dagop.headrevs(idx, [1, 2, 3]), {3})
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
   158
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
   159
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
   160
if __name__ == '__main__':
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
   161
    import silenttestrunner
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
   162
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
   163
    silenttestrunner.main(__name__)