##// 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 from __future__ import absolute_import
1 from __future__ import absolute_import
2 import unittest
2 import unittest
3
3
4 from mercurial import policy
4 from mercurial import policy
5
5
6 PartialDiscovery = policy.importrust('discovery', member='PartialDiscovery')
6 PartialDiscovery = policy.importrust('discovery', member='PartialDiscovery')
7
7
8 try:
8 try:
9 from mercurial.cext import parsers as cparsers
9 from mercurial.cext import parsers as cparsers
10 except ImportError:
10 except ImportError:
11 cparsers = None
11 cparsers = None
12
12
13 # picked from test-parse-index2, copied rather than imported
13 # picked from test-parse-index2, copied rather than imported
14 # so that it stays stable even if test-parse-index2 changes or disappears.
14 # so that it stays stable even if test-parse-index2 changes or disappears.
15 data_non_inlined = (
15 data_non_inlined = (
16 b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01D\x19'
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'
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'
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'
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'
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'
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'
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'
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'
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'
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'
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'
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'
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'
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'
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'
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 class fakerepo(object):
38 class fakerepo(object):
35 def __init__(self, idx):
39 def __init__(self, idx):
36 """Just make so that self.changelog.index is the given idx."""
40 """Just make so that self.changelog.index is the given idx."""
37 self.index = idx
41 self.changelog = fakechangelog(idx)
38 self.changelog = self
39
42
40 @unittest.skipIf(PartialDiscovery is None or cparsers is None,
43 @unittest.skipIf(PartialDiscovery is None or cparsers is None,
41 "rustext or the C Extension parsers module "
44 "rustext or the C Extension parsers module "
42 "discovery relies on is not available")
45 "discovery relies on is not available")
43 class rustdiscoverytest(unittest.TestCase):
46 class rustdiscoverytest(unittest.TestCase):
44 """Test the correctness of binding to Rust code.
47 """Test the correctness of binding to Rust code.
45
48
46 This test is merely for the binding to Rust itself: extraction of
49 This test is merely for the binding to Rust itself: extraction of
47 Python variable, giving back the results etc.
50 Python variable, giving back the results etc.
48
51
49 It is not meant to test the algorithmic correctness of the provided
52 It is not meant to test the algorithmic correctness of the provided
50 methods. Hence the very simple embedded index data is good enough.
53 methods. Hence the very simple embedded index data is good enough.
51
54
52 Algorithmic correctness is asserted by the Rust unit tests.
55 Algorithmic correctness is asserted by the Rust unit tests.
53 """
56 """
54
57
55 def parseindex(self):
58 def parseindex(self):
56 return cparsers.parse_index2(data_non_inlined, False)[0]
59 return cparsers.parse_index2(data_non_inlined, False)[0]
57
60
58 def repo(self):
61 def repo(self):
59 return fakerepo(self.parseindex())
62 return fakerepo(self.parseindex())
60
63
61 def testindex(self):
64 def testindex(self):
62 idx = self.parseindex()
65 idx = self.parseindex()
63 # checking our assumptions about the index binary data:
66 # checking our assumptions about the index binary data:
64 self.assertEqual({i: (r[5], r[6]) for i, r in enumerate(idx)},
67 self.assertEqual({i: (r[5], r[6]) for i, r in enumerate(idx)},
65 {0: (-1, -1),
68 {0: (-1, -1),
66 1: (0, -1),
69 1: (0, -1),
67 2: (1, -1),
70 2: (1, -1),
68 3: (2, -1)})
71 3: (2, -1)})
69
72
70 def testaddcommonsmissings(self):
73 def testaddcommonsmissings(self):
71 disco = PartialDiscovery(self.repo(), [3], True)
74 disco = PartialDiscovery(self.repo(), [3], True)
72 self.assertFalse(disco.hasinfo())
75 self.assertFalse(disco.hasinfo())
73 self.assertFalse(disco.iscomplete())
76 self.assertFalse(disco.iscomplete())
74
77
75 disco.addcommons([1])
78 disco.addcommons([1])
76 self.assertTrue(disco.hasinfo())
79 self.assertTrue(disco.hasinfo())
77 self.assertFalse(disco.iscomplete())
80 self.assertFalse(disco.iscomplete())
78
81
79 disco.addmissings([2])
82 disco.addmissings([2])
80 self.assertTrue(disco.hasinfo())
83 self.assertTrue(disco.hasinfo())
81 self.assertTrue(disco.iscomplete())
84 self.assertTrue(disco.iscomplete())
82
85
83 self.assertEqual(disco.commonheads(), {1})
86 self.assertEqual(disco.commonheads(), {1})
84
87
85 def testaddmissingsstats(self):
88 def testaddmissingsstats(self):
86 disco = PartialDiscovery(self.repo(), [3], True)
89 disco = PartialDiscovery(self.repo(), [3], True)
87 self.assertIsNone(disco.stats()['undecided'], None)
90 self.assertIsNone(disco.stats()['undecided'], None)
88
91
89 disco.addmissings([2])
92 disco.addmissings([2])
90 self.assertEqual(disco.stats()['undecided'], 2)
93 self.assertEqual(disco.stats()['undecided'], 2)
91
94
92 def testaddinfocommonfirst(self):
95 def testaddinfocommonfirst(self):
93 disco = PartialDiscovery(self.repo(), [3], True)
96 disco = PartialDiscovery(self.repo(), [3], True)
94 disco.addinfo([(1, True), (2, False)])
97 disco.addinfo([(1, True), (2, False)])
95 self.assertTrue(disco.hasinfo())
98 self.assertTrue(disco.hasinfo())
96 self.assertTrue(disco.iscomplete())
99 self.assertTrue(disco.iscomplete())
97 self.assertEqual(disco.commonheads(), {1})
100 self.assertEqual(disco.commonheads(), {1})
98
101
99 def testaddinfomissingfirst(self):
102 def testaddinfomissingfirst(self):
100 disco = PartialDiscovery(self.repo(), [3], True)
103 disco = PartialDiscovery(self.repo(), [3], True)
101 disco.addinfo([(2, False), (1, True)])
104 disco.addinfo([(2, False), (1, True)])
102 self.assertTrue(disco.hasinfo())
105 self.assertTrue(disco.hasinfo())
103 self.assertTrue(disco.iscomplete())
106 self.assertTrue(disco.iscomplete())
104 self.assertEqual(disco.commonheads(), {1})
107 self.assertEqual(disco.commonheads(), {1})
105
108
106 def testinitnorandom(self):
109 def testinitnorandom(self):
107 PartialDiscovery(self.repo(), [3], True, randomize=False)
110 PartialDiscovery(self.repo(), [3], True, randomize=False)
108
111
109 if __name__ == '__main__':
112 if __name__ == '__main__':
110 import silenttestrunner
113 import silenttestrunner
111 silenttestrunner.main(__name__)
114 silenttestrunner.main(__name__)
General Comments 0
You need to be logged in to leave comments. Login now