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