minor fixes and changes

This commit is contained in:
The MMGen Project 2022-10-20 18:14:14 +00:00
commit c3dbd720c6
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
9 changed files with 31 additions and 25 deletions

View file

@ -49,9 +49,6 @@ if os.getenv('MMGEN_DEBUG') or os.getenv('MMGEN_TEST_SUITE') or os.getenv('MMGEN
class MMGenObject(object):
def print_stack_trace(self,*args,**kwargs):
print_stack_trace(*args,**kwargs)
# Pretty-print any object subclassed from MMGenObject, recursing into sub-objects - WIP
def pmsg(self,*args):
print(args[0] if len(args) == 1 else args if args else self.pfmt())

View file

@ -243,8 +243,6 @@ def write_data_to_file( outfile,data,desc='data',
d = ''
finally:
if d != cmp_data:
if g.test_suite:
print_diff(cmp_data,d)
die(3,f'{desc} in file {outfile!r} has been altered by some other program! Aborting file write')
# To maintain portability, always open files in binary mode

View file

@ -170,25 +170,21 @@ class ListItemAttr(ImmutableAttr):
class MMGenListItem(MMGenObject):
valid_attrs = set()
valid_attrs_extra = set()
invalid_attrs = {
'print_stack_trace',
'pfmt',
'pmsg',
'pdie',
'pexit',
'valid_attrs',
'valid_attrs_extra',
'invalid_attrs',
'immutable_attr_init_check',
'conv_funcs',
'_asdict',
}
def __init__(self,*args,**kwargs):
# generate valid_attrs, or use the class valid_attrs if set
self.__dict__['valid_attrs'] = self.valid_attrs or (
( {e for e in dir(self) if e[:2] != '__'} | self.valid_attrs_extra )
{e for e in dir(self) if e[0] != '_'}
- MMGenListItem.invalid_attrs
- self.invalid_attrs
)

View file

@ -67,9 +67,6 @@ class TrackingWallet(MMGenObject,metaclass=AsyncInit):
self.importing = True
mode = 'w'
if g.debug:
print_stack_trace(f'TW INIT {mode!r} {self!r}')
# TODO: create on demand - only certain ops require RPC
self.rpc = await rpc_init( proto, ignore_wallet=rpc_ignore_wallet )
self.proto = proto
@ -140,9 +137,6 @@ class TrackingWallet(MMGenObject,metaclass=AsyncInit):
Since no exceptions are raised, errors will not be caught by the test suite.
"""
if g.debug:
print_stack_trace(f'TW DEL {self!r}')
if getattr(self,'mode',None) == 'w': # mode attr might not exist in this state
self.write()
elif g.debug:
@ -227,9 +221,6 @@ class TrackingWallet(MMGenObject,metaclass=AsyncInit):
wdata = json.dumps(self.data)
if self.orig_data != wdata:
if g.debug:
print_stack_trace(f'TW DATA CHANGED {self!r}')
print_diff(self.orig_data,wdata,from_json=True)
self.write_changed(wdata,quiet=quiet)
elif g.debug:
msg('Data is unchanged\n')

View file

@ -107,7 +107,7 @@ def exec_wrapper_tracemalloc_log():
s = sum(stat.size for stat in stats) / 1024,
w = col1w ))
exec_wrapper_init() # sets sys.path[0]
exec_wrapper_init() # sets sys.path[0], runs overlay_setup()
exec_wrapper_tstart = time.time()
exec_wrapper_tracemalloc_setup()

View file

@ -23,7 +23,6 @@ common.py: Shared routines and data for the MMGen test suites
import os
from subprocess import run,PIPE
from mmgen.common import *
from mmgen.devtools import *
from mmgen.fileutil import write_data_to_file,get_data_from_file
def strip_ansi_escapes(s):
@ -163,8 +162,7 @@ def init_coverage():
def silence():
if not (opt.verbose or opt.exact_output):
devnull_fn = ('/dev/null','null.out')[g.platform == 'win']
g.stdout = g.stderr = open(devnull_fn,'w')
g.stdout = g.stderr = open(os.devnull,'w')
def end_silence():
if not (opt.verbose or opt.exact_output):

View file

@ -110,12 +110,15 @@ def run_test(test,subtest=None):
subtest_disp = subtest.replace('_','-')
msg(f'Running unit subtest {test}.{subtest_disp}')
t = getattr(mod,'unit_tests')()
if hasattr(t,'_pre_subtest'):
getattr(t,'_pre_subtest')(test,subtest,UnitTestHelpers)
ret = getattr(t,subtest.replace('-','_'))(test,UnitTestHelpers)
if hasattr(t,'_post_subtest'):
getattr(t,'_post_subtest')(test,subtest,UnitTestHelpers)
if type(ret).__name__ == 'coroutine':
ret = async_run(ret)
if not ret:
die(4,f'Unit subtest {subtest_disp!r} failed')
pass
if test not in tests_seen:
gmsg(f'Running unit test {test}')
@ -129,7 +132,7 @@ def run_test(test,subtest=None):
altcoin_deps = getattr(t,'altcoin_deps',())
win_skip = getattr(t,'win_skip',())
arm_skip = getattr(t,'arm_skip',())
subtests = [k for k,v in t.__dict__.items() if type(v).__name__ == 'function']
subtests = [k for k,v in t.__dict__.items() if type(v).__name__ == 'function' and k[0] != '_']
for subtest in subtests:
subtest_disp = subtest.replace('_','-')
if opt.no_altcoin_deps and subtest in altcoin_deps:

View file

@ -0,0 +1,22 @@
#!/usr/bin/env python3
"""
test.unit_tests_d.__init__: shared data for unit tests for the MMGen suite
"""
import sys,os
from mmgen.globalvars import g
from mmgen.opts import opt
class unit_tests_base:
def _silence(self):
if not opt.verbose:
self.stdout = sys.stdout
self.stderr = sys.stderr
sys.stdout = sys.stderr = g.stdout = g.stderr = open(os.devnull,'w')
def _end_silence(self):
if not opt.verbose:
sys.stdout = g.stdout = self.stdout
sys.stderr = g.stderr = self.stderr

View file

@ -56,6 +56,7 @@ class unit_test(object):
assert len(ss2_list) == 10, len(ss2_list)
assert seed.pfmt() == seed2.pfmt()
assert seed.subseeds.pfmt() == seed2.subseeds.pfmt()
s = seed.subseeds.format(1,nSubseeds)
s_lines = s.strip().split('\n')