tests/test-parseindex2.py
changeset 38991 22216c4607bb
parent 38990 087a755310c3
child 38992 94cff858b4e5
equal deleted inserted replaced
38990:087a755310c3 38991:22216c4607bb
   174         testversionfail(4, makehex(major, minor + 1, micro))
   174         testversionfail(4, makehex(major, minor + 1, micro))
   175         testversionfail(5, "'foo'")
   175         testversionfail(5, "'foo'")
   176 
   176 
   177     def testbadargs(self):
   177     def testbadargs(self):
   178         # Check that parse_index2() raises TypeError on bad arguments.
   178         # Check that parse_index2() raises TypeError on bad arguments.
   179         try:
   179         with self.assertRaises(TypeError):
   180             parse_index2(0, True)
   180             parse_index2(0, True)
   181         except TypeError:
       
   182             pass
       
   183         else:
       
   184             print("Expected to get TypeError.")
       
   185 
   181 
   186     def testparseindexfile(self):
   182     def testparseindexfile(self):
   187         # Check parsers.parse_index2() on an index file against the
   183         # Check parsers.parse_index2() on an index file against the
   188         # original Python implementation of parseindex, both with and
   184         # original Python implementation of parseindex, both with and
   189         # without inlined data.
   185         # without inlined data.
   192         c_res_1 = parse_index2(data_inlined, True)
   188         c_res_1 = parse_index2(data_inlined, True)
   193 
   189 
   194         py_res_2 = py_parseindex(data_non_inlined, False)
   190         py_res_2 = py_parseindex(data_non_inlined, False)
   195         c_res_2 = parse_index2(data_non_inlined, False)
   191         c_res_2 = parse_index2(data_non_inlined, False)
   196 
   192 
   197         if py_res_1 != c_res_1:
   193         self.assertEqual(py_res_1, c_res_1) # inline data
   198             print("Parse index result (with inlined data) differs!")
   194         self.assertEqual(py_res_2, c_res_2) # no inline data
   199 
       
   200         if py_res_2 != c_res_2:
       
   201             print("Parse index result (no inlined data) differs!")
       
   202 
   195 
   203         ix = parsers.parse_index2(data_inlined, True)[0]
   196         ix = parsers.parse_index2(data_inlined, True)[0]
   204         for i, r in enumerate(ix):
   197         for i, r in enumerate(ix):
   205             if r[7] == nullid:
   198             if r[7] == nullid:
   206                 i = -1
   199                 i = -1
   207             try:
   200             try:
   208                 if ix[r[7]] != i:
   201                 self.assertEqual(
   209                     print('Reverse lookup inconsistent for %r'
   202                     ix[r[7]], i,
   210                         % r[7].encode('hex'))
   203                     'Reverse lookup inconsistent for %r' % r[7].encode('hex'))
   211             except TypeError:
   204             except TypeError:
   212                 # pure version doesn't support this
   205                 # pure version doesn't support this
   213                 break
   206                 break
   214 
   207 
   215 if __name__ == '__main__':
   208 if __name__ == '__main__':