From bfee46db304080847059218609ce82534f90675b Mon Sep 17 00:00:00 2001 From: Dusan Klinec Date: Thu, 16 Aug 2018 01:36:59 +0200 Subject: [PATCH] tests: support async unit tests, assertListEqual added --- tests/unittest.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/unittest.py b/tests/unittest.py index dad094971..0c52a08da 100644 --- a/tests/unittest.py +++ b/tests/unittest.py @@ -1,4 +1,5 @@ from trezor.utils import ensure +from utest import assert_async class SkipTest(Exception): @@ -125,6 +126,15 @@ def assertRaises(self, exc, func=None, *args, **kwargs): return raise + def assertListEqual(self, x, y, msg=''): + if len(x) != len(y): + if not msg: + msg = "List lengths not equal" + ensure(False, msg) + + for i in range(len(x)): + self.assertEqual(x[i], y[i], msg) + def skip(msg): def _decor(fun): @@ -178,12 +188,16 @@ def run_class(c, test_result): print('class', c.__qualname__) for name in dir(o): if name.startswith("test"): + is_async = name.startswith("test_async") print(' ', name, end=' ...') m = getattr(o, name) try: set_up() test_result.testsRun += 1 - m() + if is_async: + assert_async(m(), [(None, StopIteration()), ]) + else: + m() tear_down() print(" ok") except SkipTest as e: