155 |
155 |
156 def makehex(major, minor, micro): |
156 def makehex(major, minor, micro): |
157 return int("%x%02x%02x00" % (major, minor, micro), 16) |
157 return int("%x%02x%02x00" % (major, minor, micro), 16) |
158 |
158 |
159 class parseindex2tests(unittest.TestCase): |
159 class parseindex2tests(unittest.TestCase): |
160 def testversiondetection(self): |
160 def testversiondetection(self): |
161 """Check the version-detection logic when importing parsers.""" |
161 """Check the version-detection logic when importing parsers.""" |
162 # Only test the version-detection logic if it is present. |
162 # Only test the version-detection logic if it is present. |
163 try: |
|
164 parsers.versionerrortext |
|
165 except AttributeError: |
|
166 return |
|
167 info = sys.version_info |
|
168 major, minor, micro = info[0], info[1], info[2] |
|
169 # Test same major-minor versions. |
|
170 testversionokay(1, makehex(major, minor, micro)) |
|
171 testversionokay(2, makehex(major, minor, micro + 1)) |
|
172 # Test different major-minor versions. |
|
173 testversionfail(3, makehex(major + 1, minor, micro)) |
|
174 testversionfail(4, makehex(major, minor + 1, micro)) |
|
175 testversionfail(5, "'foo'") |
|
176 |
|
177 def testbadargs(self): |
|
178 # Check that parse_index2() raises TypeError on bad arguments. |
|
179 try: |
|
180 parse_index2(0, True) |
|
181 except TypeError: |
|
182 pass |
|
183 else: |
|
184 print("Expected to get TypeError.") |
|
185 |
|
186 def testparseindexfile(self): |
|
187 # Check parsers.parse_index2() on an index file against the original |
|
188 # Python implementation of parseindex, both with and without inlined data. |
|
189 |
|
190 py_res_1 = py_parseindex(data_inlined, True) |
|
191 c_res_1 = parse_index2(data_inlined, True) |
|
192 |
|
193 py_res_2 = py_parseindex(data_non_inlined, False) |
|
194 c_res_2 = parse_index2(data_non_inlined, False) |
|
195 |
|
196 if py_res_1 != c_res_1: |
|
197 print("Parse index result (with inlined data) differs!") |
|
198 |
|
199 if py_res_2 != c_res_2: |
|
200 print("Parse index result (no inlined data) differs!") |
|
201 |
|
202 ix = parsers.parse_index2(data_inlined, True)[0] |
|
203 for i, r in enumerate(ix): |
|
204 if r[7] == nullid: |
|
205 i = -1 |
|
206 try: |
163 try: |
207 if ix[r[7]] != i: |
164 parsers.versionerrortext |
208 print('Reverse lookup inconsistent for %r' |
165 except AttributeError: |
209 % r[7].encode('hex')) |
166 return |
|
167 info = sys.version_info |
|
168 major, minor, micro = info[0], info[1], info[2] |
|
169 # Test same major-minor versions. |
|
170 testversionokay(1, makehex(major, minor, micro)) |
|
171 testversionokay(2, makehex(major, minor, micro + 1)) |
|
172 # Test different major-minor versions. |
|
173 testversionfail(3, makehex(major + 1, minor, micro)) |
|
174 testversionfail(4, makehex(major, minor + 1, micro)) |
|
175 testversionfail(5, "'foo'") |
|
176 |
|
177 def testbadargs(self): |
|
178 # Check that parse_index2() raises TypeError on bad arguments. |
|
179 try: |
|
180 parse_index2(0, True) |
210 except TypeError: |
181 except TypeError: |
211 # pure version doesn't support this |
182 pass |
212 break |
183 else: |
|
184 print("Expected to get TypeError.") |
|
185 |
|
186 def testparseindexfile(self): |
|
187 # Check parsers.parse_index2() on an index file against the |
|
188 # original Python implementation of parseindex, both with and |
|
189 # without inlined data. |
|
190 |
|
191 py_res_1 = py_parseindex(data_inlined, True) |
|
192 c_res_1 = parse_index2(data_inlined, True) |
|
193 |
|
194 py_res_2 = py_parseindex(data_non_inlined, False) |
|
195 c_res_2 = parse_index2(data_non_inlined, False) |
|
196 |
|
197 if py_res_1 != c_res_1: |
|
198 print("Parse index result (with inlined data) differs!") |
|
199 |
|
200 if py_res_2 != c_res_2: |
|
201 print("Parse index result (no inlined data) differs!") |
|
202 |
|
203 ix = parsers.parse_index2(data_inlined, True)[0] |
|
204 for i, r in enumerate(ix): |
|
205 if r[7] == nullid: |
|
206 i = -1 |
|
207 try: |
|
208 if ix[r[7]] != i: |
|
209 print('Reverse lookup inconsistent for %r' |
|
210 % r[7].encode('hex')) |
|
211 except TypeError: |
|
212 # pure version doesn't support this |
|
213 break |
213 |
214 |
214 if __name__ == '__main__': |
215 if __name__ == '__main__': |
215 import silenttestrunner |
216 import silenttestrunner |
216 silenttestrunner.main(__name__) |
217 silenttestrunner.main(__name__) |
217 print("done") |
218 print("done") |