test/unit_tests.py: support coroutine tests; cleanups
This commit is contained in:
parent
d7ebc45915
commit
a3595062db
2 changed files with 16 additions and 16 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue