From a3595062db01437a43b83cd54398b9e5b1fd9d31 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 5 Feb 2022 13:32:54 +0000 Subject: [PATCH] test/unit_tests.py: support coroutine tests; cleanups --- test/unit_tests.py | 7 +++++-- test/unit_tests_d/ut_tx.py | 25 +++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/unit_tests.py b/test/unit_tests.py index 721ace81..154c67d8 100755 --- a/test/unit_tests.py +++ b/test/unit_tests.py @@ -36,9 +36,9 @@ opts_data = { -A, --no-daemon-autostart Don't start and stop daemons automatically -D, --no-daemon-stop Don't stop auto-started daemons after running tests -f, --fast Speed up execution by reducing rounds on some tests --n, --node-tools Select node-tools unit tests -l, --list List available tests -n, --names Print command names instead of descriptions +-N, --node-tools Select node-tools unit tests -q, --quiet Produce quieter output -x, --exclude=T Exclude tests 'T' (comma-separated) -v, --verbose Produce more verbose output @@ -106,7 +106,10 @@ def run_test(test,subtest=None): def run_subtest(subtest): msg(f'Running unit subtest {test}.{subtest}') t = getattr(mod,'unit_tests')() - if not getattr(t,subtest)(test,UnitTestHelpers): + ret = getattr(t,subtest)(test,UnitTestHelpers) + if type(ret).__name__ == 'coroutine': + ret = run_session(ret) + if not ret: rdie(1,f'Unit subtest {subtest!r} failed') pass diff --git a/test/unit_tests_d/ut_tx.py b/test/unit_tests_d/ut_tx.py index ecc38ff0..780fc8a9 100755 --- a/test/unit_tests_d/ut_tx.py +++ b/test/unit_tests_d/ut_tx.py @@ -13,17 +13,13 @@ from mmgen.protocol import init_proto class unit_tests: - def tx(self,name,ut): - qmsg(' Testing transaction objects') + async def tx(self,name,ut): + qmsg(' Testing NewTX initializer') d = CoinDaemon('btc',test_suite=True) d.start() - async def do(): - proto = init_proto('btc',need_amt=True) - tx = await NewTX(proto=proto) - tx.rpc = await rpc_init(proto=proto) - - run_session(do()) + proto = init_proto('btc',need_amt=True) + tx = await NewTX(proto=proto) d.stop() qmsg(' OK') @@ -35,19 +31,22 @@ class unit_tests: fns = ( # TODO: add altcoin TX files '0B8D5A[15.31789,14,tl=1320969600].rawtx', '0C7115[15.86255,14,tl=1320969600].testnet.rawtx', - '460D4D-BCH[10.19764,tl=1320969600].rawtx', '25EFA3[2.34].testnet.rawtx', + '460D4D-BCH[10.19764,tl=1320969600].rawtx', ) for fn in fns: - vmsg(f' parsing: {fn}') + qmsg(f' parsing: {os.path.basename(fn)}') fpath = os.path.join('test','ref',fn) tx = UnsignedTX(filename=fpath,quiet_open=True) - f = MMGenTxFile(tx) + vmsg(tx.info.format()) + + f = MMGenTxFile(tx) fn_gen = f.make_filename() + if g.debug_utf8: fn_gen = fn_gen.replace('-α','') - assert fn_gen == fn, f'{fn_gen} != {fn}' + assert fn_gen == os.path.basename(fn), f'{fn_gen} != {fn}' text = f.format() # New in version 3.3: Support for the unicode legacy literal (u'value') was @@ -57,10 +56,8 @@ class unit_tests: # remove Python2 'u' string prefixes from ref files chk = re.subn( r"\bu(['\"])", r'\1', fp.read() )[0] diff = get_ndiff(chk,text) - #print('\n'.join(diff)) nLines = len([i for i in diff if i.startswith('-')]) assert nLines in (0,1), f'{nLines} lines differ: only checksum line may differ' - #break # FIXME - test BCH, testnet qmsg(' OK') return True