| 1 |
import unittest |
| 2 |
|
| 3 |
from mercurial import policy |
| 4 |
from mercurial.testing import revlog as revlogtesting |
| 5 |
|
| 6 |
PartialDiscovery = policy.importrust('discovery', member='PartialDiscovery') |
| 7 |
|
| 8 |
try: |
| 9 |
from mercurial.cext import parsers as cparsers |
| 10 |
except ImportError: |
| 11 |
cparsers = None |
| 12 |
|
| 13 |
# picked from test-parse-index2, copied rather than imported |
| 14 |
# so that it stays stable even if test-parse-index2 changes or disappears. |
| 15 |
data_non_inlined = ( |
| 16 |
b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01D\x19' |
| 17 |
b'\x00\x07e\x12\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff' |
| 18 |
b'\xff\xff\xff\xff\xd1\xf4\xbb\xb0\xbe\xfc\x13\xbd\x8c\xd3\x9d' |
| 19 |
b'\x0f\xcd\xd9;\x8c\x07\x8cJ/\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
| 20 |
b'\x00\x00\x00\x00\x00\x00\x01D\x19\x00\x00\x00\x00\x00\xdf\x00' |
| 21 |
b'\x00\x01q\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\xff' |
| 22 |
b'\xff\xff\xff\xc1\x12\xb9\x04\x96\xa4Z1t\x91\xdfsJ\x90\xf0\x9bh' |
| 23 |
b'\x07l&\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
| 24 |
b'\x00\x01D\xf8\x00\x00\x00\x00\x01\x1b\x00\x00\x01\xb8\x00\x00' |
| 25 |
b'\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\xff\xff\xff\xff\x02\n' |
| 26 |
b'\x0e\xc6&\xa1\x92\xae6\x0b\x02i\xfe-\xe5\xbao\x05\xd1\xe7\x00' |
| 27 |
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01F' |
| 28 |
b'\x13\x00\x00\x00\x00\x01\xec\x00\x00\x03\x06\x00\x00\x00\x01' |
| 29 |
b'\x00\x00\x00\x03\x00\x00\x00\x02\xff\xff\xff\xff\x12\xcb\xeby1' |
| 30 |
b'\xb6\r\x98B\xcb\x07\xbd`\x8f\x92\xd9\xc4\x84\xbdK\x00\x00\x00' |
| 31 |
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
| 32 |
) |
| 33 |
|
| 34 |
|
| 35 |
class fakechangelog: |
| 36 |
def __init__(self, idx): |
| 37 |
self.index = idx |
| 38 |
|
| 39 |
|
| 40 |
class fakerepo: |
| 41 |
def __init__(self, idx): |
| 42 |
"""Just make so that self.changelog.index is the given idx.""" |
| 43 |
self.changelog = fakechangelog(idx) |
| 44 |
|
| 45 |
|
| 46 |
@unittest.skipIf( |
| 47 |
PartialDiscovery is None or cparsers is None, |
| 48 |
"rustext or the C Extension parsers module " |
| 49 |
"discovery relies on is not available", |
| 50 |
) |
| 51 |
class rustdiscoverytest(revlogtesting.RustRevlogBasedTestBase): |
| 52 |
"""Test the correctness of binding to Rust code. |
| 53 |
|
| 54 |
This test is merely for the binding to Rust itself: extraction of |
| 55 |
Python variable, giving back the results etc. |
| 56 |
|
| 57 |
It is not meant to test the algorithmic correctness of the provided |
| 58 |
methods. Hence the very simple embedded index data is good enough. |
| 59 |
|
| 60 |
Algorithmic correctness is asserted by the Rust unit tests. |
| 61 |
""" |
| 62 |
|
| 63 |
def parseindex(self): |
| 64 |
return self.parserustindex(data=data_non_inlined) |
| 65 |
|
| 66 |
def repo(self): |
| 67 |
return fakerepo(self.parseindex()) |
| 68 |
|
| 69 |
def testindex(self): |
| 70 |
idx = self.parseindex() |
| 71 |
# checking our assumptions about the index binary data: |
| 72 |
self.assertEqual( |
| 73 |
{i: (r[5], r[6]) for i, r in enumerate(idx)}, |
| 74 |
{0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)}, |
| 75 |
) |
| 76 |
|
| 77 |
def testaddcommonsmissings(self): |
| 78 |
disco = PartialDiscovery(self.repo(), [3], True) |
| 79 |
self.assertFalse(disco.hasinfo()) |
| 80 |
self.assertFalse(disco.iscomplete()) |
| 81 |
|
| 82 |
disco.addcommons([1]) |
| 83 |
self.assertTrue(disco.hasinfo()) |
| 84 |
self.assertFalse(disco.iscomplete()) |
| 85 |
|
| 86 |
disco.addmissings([2]) |
| 87 |
self.assertTrue(disco.hasinfo()) |
| 88 |
self.assertTrue(disco.iscomplete()) |
| 89 |
|
| 90 |
self.assertEqual(disco.commonheads(), {1}) |
| 91 |
|
| 92 |
def testaddmissingsstats(self): |
| 93 |
disco = PartialDiscovery(self.repo(), [3], True) |
| 94 |
self.assertIsNone(disco.stats()['undecided'], None) |
| 95 |
|
| 96 |
disco.addmissings([2]) |
| 97 |
self.assertEqual(disco.stats()['undecided'], 2) |
| 98 |
|
| 99 |
def testaddinfocommonfirst(self): |
| 100 |
disco = PartialDiscovery(self.repo(), [3], True) |
| 101 |
disco.addinfo([(1, True), (2, False)]) |
| 102 |
self.assertTrue(disco.hasinfo()) |
| 103 |
self.assertTrue(disco.iscomplete()) |
| 104 |
self.assertEqual(disco.commonheads(), {1}) |
| 105 |
|
| 106 |
def testaddinfomissingfirst(self): |
| 107 |
disco = PartialDiscovery(self.repo(), [3], True) |
| 108 |
disco.addinfo([(2, False), (1, True)]) |
| 109 |
self.assertTrue(disco.hasinfo()) |
| 110 |
self.assertTrue(disco.iscomplete()) |
| 111 |
self.assertEqual(disco.commonheads(), {1}) |
| 112 |
|
| 113 |
def testinitnorandom(self): |
| 114 |
PartialDiscovery(self.repo(), [3], True, randomize=False) |
| 115 |
|
| 116 |
|
| 117 |
if __name__ == '__main__': |
| 118 |
import silenttestrunner |
| 119 |
|
| 120 |
silenttestrunner.main(__name__) |