Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
tests: support async unit tests, assertListEqual added
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Aug 15, 2018
1 parent 55c1448 commit bfee46d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/unittest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from trezor.utils import ensure
from utest import assert_async


class SkipTest(Exception):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bfee46d

Please sign in to comment.