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) |