Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHG087a755310c3: tests: fix up indent width in test-parseindex2.py
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
pulkit |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
if errtext not in stdout: | if errtext not in stdout: | ||||
printhexfail(testnumber, hexversion, stdout, | printhexfail(testnumber, hexversion, stdout, | ||||
expected="stdout to contain %r" % errtext) | expected="stdout to contain %r" % errtext) | ||||
def makehex(major, minor, micro): | def makehex(major, minor, micro): | ||||
return int("%x%02x%02x00" % (major, minor, micro), 16) | return int("%x%02x%02x00" % (major, minor, micro), 16) | ||||
class parseindex2tests(unittest.TestCase): | class parseindex2tests(unittest.TestCase): | ||||
def testversiondetection(self): | def testversiondetection(self): | ||||
"""Check the version-detection logic when importing parsers.""" | """Check the version-detection logic when importing parsers.""" | ||||
# Only test the version-detection logic if it is present. | # Only test the version-detection logic if it is present. | ||||
try: | try: | ||||
parsers.versionerrortext | parsers.versionerrortext | ||||
except AttributeError: | except AttributeError: | ||||
return | return | ||||
info = sys.version_info | info = sys.version_info | ||||
major, minor, micro = info[0], info[1], info[2] | major, minor, micro = info[0], info[1], info[2] | ||||
# Test same major-minor versions. | # Test same major-minor versions. | ||||
testversionokay(1, makehex(major, minor, micro)) | testversionokay(1, makehex(major, minor, micro)) | ||||
testversionokay(2, makehex(major, minor, micro + 1)) | testversionokay(2, makehex(major, minor, micro + 1)) | ||||
# Test different major-minor versions. | # Test different major-minor versions. | ||||
testversionfail(3, makehex(major + 1, minor, micro)) | testversionfail(3, makehex(major + 1, minor, micro)) | ||||
testversionfail(4, makehex(major, minor + 1, micro)) | testversionfail(4, makehex(major, minor + 1, micro)) | ||||
testversionfail(5, "'foo'") | testversionfail(5, "'foo'") | ||||
def testbadargs(self): | def testbadargs(self): | ||||
# Check that parse_index2() raises TypeError on bad arguments. | # Check that parse_index2() raises TypeError on bad arguments. | ||||
try: | try: | ||||
parse_index2(0, True) | parse_index2(0, True) | ||||
except TypeError: | except TypeError: | ||||
pass | pass | ||||
else: | else: | ||||
print("Expected to get TypeError.") | print("Expected to get TypeError.") | ||||
def testparseindexfile(self): | def testparseindexfile(self): | ||||
# Check parsers.parse_index2() on an index file against the original | # Check parsers.parse_index2() on an index file against the original | ||||
# Python implementation of parseindex, both with and without inlined data. | # Python implementation of parseindex, both with and without inlined data. | ||||
py_res_1 = py_parseindex(data_inlined, True) | py_res_1 = py_parseindex(data_inlined, True) | ||||
c_res_1 = parse_index2(data_inlined, True) | c_res_1 = parse_index2(data_inlined, True) | ||||
py_res_2 = py_parseindex(data_non_inlined, False) | py_res_2 = py_parseindex(data_non_inlined, False) | ||||
c_res_2 = parse_index2(data_non_inlined, False) | c_res_2 = parse_index2(data_non_inlined, False) | ||||
if py_res_1 != c_res_1: | if py_res_1 != c_res_1: | ||||
print("Parse index result (with inlined data) differs!") | print("Parse index result (with inlined data) differs!") | ||||
if py_res_2 != c_res_2: | if py_res_2 != c_res_2: | ||||
print("Parse index result (no inlined data) differs!") | print("Parse index result (no inlined data) differs!") | ||||
ix = parsers.parse_index2(data_inlined, True)[0] | ix = parsers.parse_index2(data_inlined, True)[0] | ||||
for i, r in enumerate(ix): | for i, r in enumerate(ix): | ||||
if r[7] == nullid: | if r[7] == nullid: | ||||
i = -1 | i = -1 | ||||
try: | try: | ||||
if ix[r[7]] != i: | if ix[r[7]] != i: | ||||
print('Reverse lookup inconsistent for %r' | print('Reverse lookup inconsistent for %r' | ||||
% r[7].encode('hex')) | % r[7].encode('hex')) | ||||
except TypeError: | except TypeError: | ||||
# pure version doesn't support this | # pure version doesn't support this | ||||
break | break | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
import silenttestrunner | import silenttestrunner | ||||
silenttestrunner.main(__name__) | silenttestrunner.main(__name__) | ||||
print("done") | print("done") |