Add parse tests
This commit is contained in:
parent
4869507b09
commit
a14b2d49b7
|
@ -275,16 +275,23 @@ def install_test(d, variant, tName, binaryForm, annotatedTextForm):
|
||||||
if variant in ['normal', 'nondeterministic']:
|
if variant in ['normal', 'nondeterministic']:
|
||||||
add_method(d, tName, test_encode_ann)
|
add_method(d, tName, test_encode_ann)
|
||||||
|
|
||||||
def install_exn_test(d, tName, bs, check_proc):
|
def install_exn_test(d, tName, testLambda, check_proc):
|
||||||
def test_exn(self):
|
def test_exn(self):
|
||||||
try:
|
try:
|
||||||
self.D(bs)
|
testLambda(self)
|
||||||
except:
|
except:
|
||||||
check_proc(self, sys.exc_info()[1])
|
check_proc(self, sys.exc_info()[1])
|
||||||
return
|
return
|
||||||
self.fail('did not fail as expected')
|
self.fail('did not fail as expected')
|
||||||
add_method(d, tName, test_exn)
|
add_method(d, tName, test_exn)
|
||||||
|
|
||||||
|
def expected_err(self, e):
|
||||||
|
self.assertIsInstance(e, DecodeError)
|
||||||
|
self.assertNotIsInstance(e, ShortPacket)
|
||||||
|
|
||||||
|
def expected_short(self, e):
|
||||||
|
self.assertIsInstance(e, ShortPacket)
|
||||||
|
|
||||||
class CommonTestSuite(PreservesTestCase):
|
class CommonTestSuite(PreservesTestCase):
|
||||||
TestCases = Record.makeConstructor('TestCases', 'cases')
|
TestCases = Record.makeConstructor('TestCases', 'cases')
|
||||||
|
|
||||||
|
@ -300,20 +307,20 @@ class CommonTestSuite(PreservesTestCase):
|
||||||
elif t.key == Symbol('DecodeTest'):
|
elif t.key == Symbol('DecodeTest'):
|
||||||
install_test(locals(), 'decode', tName, t[0].strip(), t[1])
|
install_test(locals(), 'decode', tName, t[0].strip(), t[1])
|
||||||
elif t.key == Symbol('DecodeError'):
|
elif t.key == Symbol('DecodeError'):
|
||||||
def expected_err(self, e):
|
install_exn_test(locals(), tName, lambda self, t=t: self.D(t[0].strip()), expected_err)
|
||||||
self.assertIsInstance(e, DecodeError)
|
|
||||||
self.assertNotIsInstance(e, ShortPacket)
|
|
||||||
install_exn_test(locals(), tName, t[0].strip(), expected_err)
|
|
||||||
elif t.key in [Symbol('DecodeShort'), Symbol('DecodeEOF')]:
|
elif t.key in [Symbol('DecodeShort'), Symbol('DecodeEOF')]:
|
||||||
def expected_short(self, e):
|
install_exn_test(locals(), tName, lambda self, t=t: self.D(t[0].strip()), expected_short)
|
||||||
self.assertIsInstance(e, ShortPacket)
|
elif t.key == Symbol('ParseError'):
|
||||||
install_exn_test(locals(), tName, t[0].strip(), expected_short)
|
install_exn_test(locals(), tName, lambda self, t=t: self.R(t[0].strip()), expected_err)
|
||||||
elif t.key in [Symbol('ParseError'), Symbol('ParseShort'), Symbol('ParseEOF')]:
|
elif t.key in [Symbol('ParseShort'), Symbol('ParseEOF')]:
|
||||||
# Skipped for now, until we have an implementation of text syntax
|
install_exn_test(locals(), tName, lambda self, t=t: self.R(t[0].strip()), expected_short)
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise Exception('Unsupported test kind', t.key)
|
raise Exception('Unsupported test kind', t.key)
|
||||||
|
|
||||||
|
def R(self, text):
|
||||||
|
return parse(text)
|
||||||
|
|
||||||
def DS(self, bs):
|
def DS(self, bs):
|
||||||
return decode(bs, decode_embedded=lambda x: x)
|
return decode(bs, decode_embedded=lambda x: x)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue