##// END OF EJS Templates
typing: add stub functions for `cext/charencoding`...
typing: add stub functions for `cext/charencoding` I'm not sure if it's better to have a separate file, and currently pytype doesn't really know how to handle these, so it's no help in figuring that out. Technically, these methods are part of the `mercurial.cext.parsers` module, so put them into the existing stub until there's a reason to split it out.

File last commit:

r52138:0b81440e default
r52834:e58f02e2 default
Show More
test-rust-discovery.py
120 lines | 4.2 KiB | text/x-python | PythonLexer
/ tests / test-rust-discovery.py
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 import unittest
Raphaël Gomès
module-policy: update rust extension import to use the new module policy...
r42895 from mercurial import policy
Georges Racinet
rust-index: using `hg::index::Index` in discovery...
r52138 from mercurial.testing import revlog as revlogtesting
Raphaël Gomès
module-policy: update rust extension import to use the new module policy...
r42895
PartialDiscovery = policy.importrust('discovery', member='PartialDiscovery')
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356
try:
from mercurial.cext import parsers as cparsers
except ImportError:
cparsers = None
# picked from test-parse-index2, copied rather than imported
# so that it stays stable even if test-parse-index2 changes or disappears.
data_non_inlined = (
b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01D\x19'
b'\x00\x07e\x12\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff'
b'\xff\xff\xff\xff\xd1\xf4\xbb\xb0\xbe\xfc\x13\xbd\x8c\xd3\x9d'
b'\x0f\xcd\xd9;\x8c\x07\x8cJ/\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x01D\x19\x00\x00\x00\x00\x00\xdf\x00'
b'\x00\x01q\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\xff'
b'\xff\xff\xff\xc1\x12\xb9\x04\x96\xa4Z1t\x91\xdfsJ\x90\xf0\x9bh'
b'\x07l&\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x01D\xf8\x00\x00\x00\x00\x01\x1b\x00\x00\x01\xb8\x00\x00'
b'\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\xff\xff\xff\xff\x02\n'
b'\x0e\xc6&\xa1\x92\xae6\x0b\x02i\xfe-\xe5\xbao\x05\xd1\xe7\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01F'
b'\x13\x00\x00\x00\x00\x01\xec\x00\x00\x03\x06\x00\x00\x00\x01'
b'\x00\x00\x00\x03\x00\x00\x00\x02\xff\xff\xff\xff\x12\xcb\xeby1'
b'\xb6\r\x98B\xcb\x07\xbd`\x8f\x92\xd9\xc4\x84\xbdK\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class fakechangelog:
Augie Fackler
tests: split joint repo/changelog fake into one for each type...
r43004 def __init__(self, idx):
self.index = idx
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class fakerepo:
Georges Racinet
rust-discovery: read the index from a repo passed at init...
r42964 def __init__(self, idx):
"""Just make so that self.changelog.index is the given idx."""
Augie Fackler
tests: split joint repo/changelog fake into one for each type...
r43004 self.changelog = fakechangelog(idx)
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356
Augie Fackler
formatting: blacken the codebase...
r43346
@unittest.skipIf(
PartialDiscovery is None or cparsers is None,
"rustext or the C Extension parsers module "
"discovery relies on is not available",
)
Georges Racinet
rust-index: using `hg::index::Index` in discovery...
r52138 class rustdiscoverytest(revlogtesting.RustRevlogBasedTestBase):
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 """Test the correctness of binding to Rust code.
This test is merely for the binding to Rust itself: extraction of
Python variable, giving back the results etc.
It is not meant to test the algorithmic correctness of the provided
methods. Hence the very simple embedded index data is good enough.
Algorithmic correctness is asserted by the Rust unit tests.
"""
def parseindex(self):
Georges Racinet
rust-index: using `hg::index::Index` in discovery...
r52138 return self.parserustindex(data=data_non_inlined)
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356
Georges Racinet
rust-discovery: read the index from a repo passed at init...
r42964 def repo(self):
return fakerepo(self.parseindex())
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 def testindex(self):
idx = self.parseindex()
# checking our assumptions about the index binary data:
Augie Fackler
formatting: blacken the codebase...
r43346 self.assertEqual(
{i: (r[5], r[6]) for i, r in enumerate(idx)},
{0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)},
)
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356
def testaddcommonsmissings(self):
Georges Racinet
rust-discovery: read the index from a repo passed at init...
r42964 disco = PartialDiscovery(self.repo(), [3], True)
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 self.assertFalse(disco.hasinfo())
self.assertFalse(disco.iscomplete())
disco.addcommons([1])
self.assertTrue(disco.hasinfo())
self.assertFalse(disco.iscomplete())
disco.addmissings([2])
self.assertTrue(disco.hasinfo())
self.assertTrue(disco.iscomplete())
self.assertEqual(disco.commonheads(), {1})
Georges Racinet
rust-discovery: implementing and exposing stats()...
r42357 def testaddmissingsstats(self):
Georges Racinet
rust-discovery: read the index from a repo passed at init...
r42964 disco = PartialDiscovery(self.repo(), [3], True)
Georges Racinet
rust-discovery: implementing and exposing stats()...
r42357 self.assertIsNone(disco.stats()['undecided'], None)
disco.addmissings([2])
self.assertEqual(disco.stats()['undecided'], 2)
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 def testaddinfocommonfirst(self):
Georges Racinet
rust-discovery: read the index from a repo passed at init...
r42964 disco = PartialDiscovery(self.repo(), [3], True)
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 disco.addinfo([(1, True), (2, False)])
self.assertTrue(disco.hasinfo())
self.assertTrue(disco.iscomplete())
self.assertEqual(disco.commonheads(), {1})
def testaddinfomissingfirst(self):
Georges Racinet
rust-discovery: read the index from a repo passed at init...
r42964 disco = PartialDiscovery(self.repo(), [3], True)
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 disco.addinfo([(2, False), (1, True)])
self.assertTrue(disco.hasinfo())
self.assertTrue(disco.iscomplete())
self.assertEqual(disco.commonheads(), {1})
Georges Racinet
rust-discovery: optionally don't randomize at all, for tests...
r42968 def testinitnorandom(self):
PartialDiscovery(self.repo(), [3], True, randomize=False)
Augie Fackler
formatting: blacken the codebase...
r43346
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 if __name__ == '__main__':
import silenttestrunner
Augie Fackler
formatting: blacken the codebase...
r43346
Georges Racinet
rust-discovery: cpython bindings for the core logic...
r42356 silenttestrunner.main(__name__)