comparison tests/test-parseindex2.py @ 38989:01966d45b45e

tests: start moving test-parseindex2.py to a unittest Using 2-space indents in this revision to make the code motion easier to review. I'll fix it in the next commit. Differential Revision: https://phab.mercurial-scm.org/D4176
author Augie Fackler <augie@google.com>
date Thu, 09 Aug 2018 12:58:25 -0400
parents a3dacabd476b
children 087a755310c3
comparison
equal deleted inserted replaced
38988:1aab0007a7c0 38989:01966d45b45e
6 from __future__ import absolute_import, print_function 6 from __future__ import absolute_import, print_function
7 7
8 import struct 8 import struct
9 import subprocess 9 import subprocess
10 import sys 10 import sys
11 import unittest
11 12
12 from mercurial.node import ( 13 from mercurial.node import (
13 nullid, 14 nullid,
14 nullrev, 15 nullrev,
15 ) 16 )
153 expected="stdout to contain %r" % errtext) 154 expected="stdout to contain %r" % errtext)
154 155
155 def makehex(major, minor, micro): 156 def makehex(major, minor, micro):
156 return int("%x%02x%02x00" % (major, minor, micro), 16) 157 return int("%x%02x%02x00" % (major, minor, micro), 16)
157 158
158 def runversiontests(): 159 class parseindex2tests(unittest.TestCase):
160 def testversiondetection(self):
159 """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.
163 try:
164 parsers.versionerrortext
165 except AttributeError:
166 return
160 info = sys.version_info 167 info = sys.version_info
161 major, minor, micro = info[0], info[1], info[2] 168 major, minor, micro = info[0], info[1], info[2]
162 # Test same major-minor versions. 169 # Test same major-minor versions.
163 testversionokay(1, makehex(major, minor, micro)) 170 testversionokay(1, makehex(major, minor, micro))
164 testversionokay(2, makehex(major, minor, micro + 1)) 171 testversionokay(2, makehex(major, minor, micro + 1))
165 # Test different major-minor versions. 172 # Test different major-minor versions.
166 testversionfail(3, makehex(major + 1, minor, micro)) 173 testversionfail(3, makehex(major + 1, minor, micro))
167 testversionfail(4, makehex(major, minor + 1, micro)) 174 testversionfail(4, makehex(major, minor + 1, micro))
168 testversionfail(5, "'foo'") 175 testversionfail(5, "'foo'")
169 176
170 def runtest() : 177 def testbadargs(self):
171 # Only test the version-detection logic if it is present.
172 try:
173 parsers.versionerrortext
174 except AttributeError:
175 pass
176 else:
177 runversiontests()
178
179 # Check that parse_index2() raises TypeError on bad arguments. 178 # Check that parse_index2() raises TypeError on bad arguments.
180 try: 179 try:
181 parse_index2(0, True) 180 parse_index2(0, True)
182 except TypeError: 181 except TypeError:
183 pass 182 pass
184 else: 183 else:
185 print("Expected to get TypeError.") 184 print("Expected to get TypeError.")
186 185
186 def testparseindexfile(self):
187 # Check parsers.parse_index2() on an index file against the original 187 # Check parsers.parse_index2() on an index file against the original
188 # Python implementation of parseindex, both with and without inlined data. 188 # Python implementation of parseindex, both with and without inlined data.
189 189
190 py_res_1 = py_parseindex(data_inlined, True) 190 py_res_1 = py_parseindex(data_inlined, True)
191 c_res_1 = parse_index2(data_inlined, True) 191 c_res_1 = parse_index2(data_inlined, True)
209 % r[7].encode('hex')) 209 % r[7].encode('hex'))
210 except TypeError: 210 except TypeError:
211 # pure version doesn't support this 211 # pure version doesn't support this
212 break 212 break
213 213
214 if __name__ == '__main__':
215 import silenttestrunner
216 silenttestrunner.main(__name__)
214 print("done") 217 print("done")
215
216 runtest()