mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 04:18:10 +00:00
fix(core/tests): fix equality testing for new message types
This commit is contained in:
parent
e5e3ad21b2
commit
1382246977
@ -129,39 +129,39 @@ class TestNemMosaic(unittest.TestCase):
|
||||
b.quantity = 1
|
||||
b.mosaic = 'mosaic'
|
||||
res = sort_mosaics([a, b])
|
||||
self.assertEqual(res, [b, a])
|
||||
self.assertListEqual(res, [b, a])
|
||||
|
||||
a.namespace = ''
|
||||
b.namespace = 'a.b.c'
|
||||
res = sort_mosaics([a, b])
|
||||
self.assertEqual(res, [a, b])
|
||||
self.assertListEqual(res, [a, b])
|
||||
|
||||
a.namespace = 'z.z.z'
|
||||
b.namespace = 'a.b.c'
|
||||
res = sort_mosaics([a, b])
|
||||
self.assertEqual(res, [b, a])
|
||||
self.assertListEqual(res, [b, a])
|
||||
|
||||
a.namespace = 'a'
|
||||
b.namespace = 'a'
|
||||
a.mosaic = 'mosaic'
|
||||
b.mosaic = 'mosaic'
|
||||
res = sort_mosaics([a, b])
|
||||
self.assertEqual(res, [a, b])
|
||||
self.assertListEqual(res, [a, b])
|
||||
|
||||
a.mosaic = 'www'
|
||||
b.mosaic = 'aaa'
|
||||
res = sort_mosaics([a, b])
|
||||
self.assertEqual(res, [b, a])
|
||||
self.assertListEqual(res, [b, a])
|
||||
|
||||
c = NEMMosaic()
|
||||
c.namespace = 'a'
|
||||
c.mosaic = 'zzz'
|
||||
res = sort_mosaics([a, b, c])
|
||||
self.assertEqual(res, [b, a, c])
|
||||
self.assertListEqual(res, [b, a, c])
|
||||
|
||||
c.mosaic = 'bbb'
|
||||
res = sort_mosaics([a, b, c])
|
||||
self.assertEqual(res, [b, c, a])
|
||||
self.assertListEqual(res, [b, c, a])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -33,7 +33,11 @@ class TestCase:
|
||||
def assertEqual(self, x, y, msg=''):
|
||||
if not msg:
|
||||
msg = "%r vs (expected) %r" % (x, y)
|
||||
ensure(x == y, msg)
|
||||
|
||||
if x.__class__ == y.__class__ and x.__class__.__name__ == "Msg":
|
||||
self.assertMessageEqual(x, y)
|
||||
else:
|
||||
ensure(x == y, msg)
|
||||
|
||||
def assertNotEqual(self, x, y, msg=''):
|
||||
if not msg:
|
||||
@ -152,6 +156,22 @@ class TestCase:
|
||||
self.assertIsInstance(a, b.__class__, msg)
|
||||
self.assertEqual(a.__dict__, b.__dict__, msg)
|
||||
|
||||
def assertMessageEqual(self, x, y):
|
||||
self.assertEqual(
|
||||
x.MESSAGE_NAME,
|
||||
y.MESSAGE_NAME,
|
||||
"Expected {}, found {}".format(x.MESSAGE_NAME, y.MESSAGE_NAME)
|
||||
)
|
||||
xdict = x.__dict__
|
||||
ydict = y.__dict__
|
||||
for key in xdict:
|
||||
self.assertTrue(key in ydict)
|
||||
self.assertEqual(
|
||||
xdict[key],
|
||||
ydict[key],
|
||||
"At {}.{} expected {}, found {}".format(x.MESSAGE_NAME, key, xdict[key], ydict[key])
|
||||
)
|
||||
|
||||
|
||||
def skip(msg):
|
||||
def _decor(fun):
|
||||
|
Loading…
Reference in New Issue
Block a user