##// END OF EJS Templates
tests: fix test-parseindex2.py when run with --pure
Bryan O'Sullivan -
r16620:e22d6b1d stable
parent child Browse files
Show More
@@ -1,122 +1,126 b''
1 1 from mercurial import parsers
2 2 from mercurial.node import nullid, nullrev
3 3 import struct
4 4
5 5 # This unit test compares the return value of the original Python
6 6 # implementation of parseindex and the new C implementation for
7 7 # an index file with and without inlined data
8 8
9 9 # original python implementation
10 10 def gettype(q):
11 11 return int(q & 0xFFFF)
12 12
13 13 def offset_type(offset, type):
14 14 return long(long(offset) << 16 | type)
15 15
16 16 indexformatng = ">Qiiiiii20s12x"
17 17
18 18 def py_parseindex(data, inline) :
19 19 s = 64
20 20 cache = None
21 21 index = []
22 22 nodemap = {nullid: nullrev}
23 23 n = off = 0
24 24
25 25 l = len(data) - s
26 26 append = index.append
27 27 if inline:
28 28 cache = (0, data)
29 29 while off <= l:
30 30 e = struct.unpack(indexformatng, data[off:off + s])
31 31 nodemap[e[7]] = n
32 32 append(e)
33 33 n += 1
34 34 if e[1] < 0:
35 35 break
36 36 off += e[1] + s
37 37 else:
38 38 while off <= l:
39 39 e = struct.unpack(indexformatng, data[off:off + s])
40 40 nodemap[e[7]] = n
41 41 append(e)
42 42 n += 1
43 43 off += s
44 44
45 45 e = list(index[0])
46 46 type = gettype(e[0])
47 47 e[0] = offset_type(0, type)
48 48 index[0] = tuple(e)
49 49
50 50 # add the magic null revision at -1
51 51 index.append((0, 0, 0, -1, -1, -1, -1, nullid))
52 52
53 53 return index, cache
54 54
55 55 data_inlined = '\x00\x01\x00\x01\x00\x00\x00\x00\x00\x00\x01\x8c' \
56 56 '\x00\x00\x04\x07\x00\x00\x00\x00\x00\x00\x15\x15\xff\xff\xff' \
57 57 '\xff\xff\xff\xff\xff\xebG\x97\xb7\x1fB\x04\xcf\x13V\x81\tw\x1b' \
58 58 'w\xdduR\xda\xc6\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
59 59 'x\x9c\x9d\x93?O\xc30\x10\xc5\xf7|\x8a\xdb\x9a\xa8m\x06\xd8*\x95' \
60 60 '\x81B\xa1\xa2\xa2R\xcb\x86Pd\x9a\x0b5$vd_\x04\xfd\xf6\x9c\xff@' \
61 61 '\x11!\x0b\xd9\xec\xf7\xbbw\xe7gG6\xad6\x04\xdaN\xc0\x92\xa0$)' \
62 62 '\xb1\x82\xa2\xd1%\x16\xa4\x8b7\xa9\xca\xd4-\xb2Y\x02\xfc\xc9' \
63 63 '\xcaS\xf9\xaeX\xed\xb6\xd77Q\x02\x83\xd4\x19\xf5--Y\xea\xe1W' \
64 64 '\xab\xed\x10\xceR\x0f_\xdf\xdf\r\xe1,\xf5\xf0\xcb\xf5 \xceR\x0f' \
65 65 '_\xdc\x0e\x0e\xc3R\x0f_\xae\x96\x9b!\x9e\xa5\x1e\xbf\xdb,\x06' \
66 66 '\xc7q\x9a/\x88\x82\xc3B\xea\xb5\xb4TJ\x93\xb6\x82\x0e\xe16\xe6' \
67 67 'KQ\xdb\xaf\xecG\xa3\xd1 \x01\xd3\x0b_^\xe8\xaa\xa0\xae\xad\xd1' \
68 68 '&\xbef\x1bz\x08\xb0|\xc9Xz\x06\xf6Z\x91\x90J\xaa\x17\x90\xaa' \
69 69 '\xd2\xa6\x11$5C\xcf\xba#\xa0\x03\x02*2\x92-\xfc\xb1\x94\xdf\xe2' \
70 70 '\xae\xb8\'m\x8ey0^\x85\xd3\x82\xb4\xf0`:\x9c\x00\x8a\xfd\x01' \
71 71 '\xb0\xc6\x86\x8b\xdd\xae\x80\xf3\xa9\x9fd\x16\n\x00R%\x1a\x06' \
72 72 '\xe9\xd8b\x98\x1d\xf4\xf3+\x9bf\x01\xd8p\x1b\xf3.\xed\x9f^g\xc3' \
73 73 '^\xd9W81T\xdb\xd5\x04sx|\xf2\xeb\xd6`%?x\xed"\x831\xbf\xf3\xdc' \
74 74 'b\xeb%gaY\xe1\xad\x9f\xb9f\'1w\xa9\xa5a\x83s\x82J\xb98\xbc4\x8b' \
75 75 '\x83\x00\x9f$z\xb8#\xa5\xb1\xdf\x98\xd9\xec\x1b\x89O\xe3Ts\x9a4' \
76 76 '\x17m\x8b\xfc\x8f\xa5\x95\x9a\xfc\xfa\xed,\xe5|\xa1\xfe\x15\xb9' \
77 77 '\xbc\xb2\x93\x1f\xf2\x95\xff\xdf,\x1a\xc5\xe7\x17*\x93Oz:>\x0e'
78 78
79 79 data_non_inlined = '\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01D\x19' \
80 80 '\x00\x07e\x12\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff' \
81 81 '\xff\xff\xff\xff\xd1\xf4\xbb\xb0\xbe\xfc\x13\xbd\x8c\xd3\x9d' \
82 82 '\x0f\xcd\xd9;\x8c\x07\x8cJ/\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
83 83 '\x00\x00\x00\x00\x00\x00\x01D\x19\x00\x00\x00\x00\x00\xdf\x00' \
84 84 '\x00\x01q\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\xff' \
85 85 '\xff\xff\xff\xc1\x12\xb9\x04\x96\xa4Z1t\x91\xdfsJ\x90\xf0\x9bh' \
86 86 '\x07l&\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
87 87 '\x00\x01D\xf8\x00\x00\x00\x00\x01\x1b\x00\x00\x01\xb8\x00\x00' \
88 88 '\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\xff\xff\xff\xff\x02\n' \
89 89 '\x0e\xc6&\xa1\x92\xae6\x0b\x02i\xfe-\xe5\xbao\x05\xd1\xe7\x00' \
90 90 '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01F' \
91 91 '\x13\x00\x00\x00\x00\x01\xec\x00\x00\x03\x06\x00\x00\x00\x01' \
92 92 '\x00\x00\x00\x03\x00\x00\x00\x02\xff\xff\xff\xff\x12\xcb\xeby1' \
93 93 '\xb6\r\x98B\xcb\x07\xbd`\x8f\x92\xd9\xc4\x84\xbdK\x00\x00\x00' \
94 94 '\x00\x00\x00\x00\x00\x00\x00\x00\x00'
95 95
96 96 def parse_index2(data, inline):
97 97 index, chunkcache = parsers.parse_index2(data, inline)
98 98 return list(index), chunkcache
99 99
100 100 def runtest() :
101 101 py_res_1 = py_parseindex(data_inlined, True)
102 102 c_res_1 = parse_index2(data_inlined, True)
103 103
104 104 py_res_2 = py_parseindex(data_non_inlined, False)
105 105 c_res_2 = parse_index2(data_non_inlined, False)
106 106
107 107 if py_res_1 != c_res_1:
108 108 print "Parse index result (with inlined data) differs!"
109 109
110 110 if py_res_2 != c_res_2:
111 111 print "Parse index result (no inlined data) differs!"
112 112
113 113 ix = parsers.parse_index2(data_inlined, True)[0]
114 114 for i, r in enumerate(ix):
115 115 if r[7] == nullid:
116 116 i = -1
117 if ix[r[7]] != i:
118 print 'Reverse lookup inconsistent for %r' % r[7].encode('hex')
117 try:
118 if ix[r[7]] != i:
119 print 'Reverse lookup inconsistent for %r' % r[7].encode('hex')
120 except TypeError:
121 # pure version doesn't support this
122 break
119 123
120 124 print "done"
121 125
122 126 runtest()
General Comments 0
You need to be logged in to leave comments. Login now