Skip to content

Commit ff8041a

Browse files
committed
streamlined assertions in protocol tests
1 parent b41bb69 commit ff8041a

1 file changed

Lines changed: 9 additions & 36 deletions

File tree

‎test/gen/genprottest.py‎

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -234,42 +234,24 @@ def build_request(endian):
234234
fpy.write('''
235235
def testPackRequest%(n)d(self):
236236
bin = apply(request.%(req)s._request.to_binary, (), self.req_args_%(n)d)
237-
try:
238-
assert bin == self.req_bin_%(n)d
239-
except AssertionError:
240-
raise AssertionError(tohex(bin))
237+
self.assert_(bin == self.req_bin_%(n)d, tohex(bin))
241238
242239
def testUnpackRequest%(n)d(self):
243240
args, remain = request.%(req)s._request.parse_binary(self.req_bin_%(n)d, dummy_display, 1)
244-
try:
245-
assert len(remain) == 0
246-
except AssertionError:
247-
raise AssertionError(tohex(remain))
248-
try:
249-
assert args == self.req_args_%(n)d
250-
except AssertionError:
251-
raise AssertionError(args)
241+
self.assert_(len(remain) == 0, tohex(remain))
242+
self.assert_(args == self.req_args_%(n)d, args)
252243
''' % { 'req': req.__name__, 'n': i })
253244

254245
for i in range(0, replies + 1):
255246
fpy.write('''
256247
def testPackReply%(n)d(self):
257248
bin = apply(request.%(req)s._reply.to_binary, (), self.reply_args_%(n)d)
258-
try:
259-
assert bin == self.reply_bin_%(n)d
260-
except AssertionError:
261-
raise AssertionError(tohex(bin))
249+
self.assert_(bin == self.reply_bin_%(n)d, tohex(bin))
262250
263251
def testUnpackReply%(n)d(self):
264252
args, remain = request.%(req)s._reply.parse_binary(self.reply_bin_%(n)d, dummy_display, 1)
265-
try:
266-
assert len(remain) == 0
267-
except AssertionError:
268-
raise AssertionError(tohex(remain))
269-
try:
270-
assert args == self.reply_args_%(n)d
271-
except AssertionError:
272-
raise AssertionError(args)
253+
self.assert_(len(remain) == 0, tohex(remain))
254+
self.assert_(args == self.reply_args_%(n)d, args)
273255
''' % { 'req': req.__name__, 'n': i })
274256

275257
fpy.write('''
@@ -414,21 +396,12 @@ def build_event(endian):
414396
fpy.write('''
415397
def testPack%(n)d(self):
416398
bin = apply(event.%(evt)s._fields.to_binary, (), self.evt_args_%(n)d)
417-
try:
418-
assert bin == self.evt_bin_%(n)d
419-
except AssertionError:
420-
raise AssertionError(tohex(bin))
399+
self.assert_(bin == self.evt_bin_%(n)d, tohex(bin))
421400
422401
def testUnpack%(n)d(self):
423402
args, remain = event.%(evt)s._fields.parse_binary(self.evt_bin_%(n)d, dummy_display, 1)
424-
try:
425-
assert len(remain) == 0
426-
except AssertionError:
427-
raise AssertionError(tohex(remain))
428-
try:
429-
assert args == self.evt_args_%(n)d
430-
except AssertionError:
431-
raise AssertionError(args)
403+
self.assert_(len(remain) == 0, tohex(remain))
404+
self.assert_(args == self.evt_args_%(n)d, args)
432405
''' % { 'evt': evt.__name__, 'n': i })
433406

434407
fpy.write('''

0 commit comments

Comments
 (0)