1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-23 23:18:16 +00:00

tests(core): addTypeEqualityFunc added to unit test TestCase class

This commit is contained in:
Martin Novak 2022-07-19 10:52:05 +02:00
parent d216afb114
commit fe2433ac91

View File

@ -26,16 +26,24 @@ class AssertRaisesContext:
class TestCase:
def __init__(self) -> None:
self.__equality_functions = {}
def fail(self, msg=''):
ensure(False, msg)
def addTypeEqualityFunc(self, typeobj, function):
ensure(callable(function))
self.__equality_functions[typeobj.__name__] = function
def assertEqual(self, x, y, msg=''):
if not msg:
msg = f"{repr(x)} vs (expected) {repr(y)}"
if x.__class__ == y.__class__ and x.__class__.__name__ == "Msg":
self.assertMessageEqual(x, y)
elif x.__class__.__name__ in self.__equality_functions:
self.__equality_functions[x.__class__.__name__](x, y, msg)
else:
ensure(x == y, msg)