From c3dbd720c6643490d1383786d772e9e4e1d7d8a8 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 20 Oct 2022 18:14:14 +0000 Subject: [PATCH] minor fixes and changes --- mmgen/devtools.py | 3 --- mmgen/fileutil.py | 2 -- mmgen/obj.py | 6 +----- mmgen/tw/ctl.py | 9 --------- scripts/exec_wrapper.py | 2 +- test/include/common.py | 4 +--- test/unit_tests.py | 7 +++++-- test/unit_tests_d/__init__.py | 22 ++++++++++++++++++++++ test/unit_tests_d/ut_subseed.py | 1 + 9 files changed, 31 insertions(+), 25 deletions(-) diff --git a/mmgen/devtools.py b/mmgen/devtools.py index 25a35e08..ba1c1e86 100755 --- a/mmgen/devtools.py +++ b/mmgen/devtools.py @@ -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()) diff --git a/mmgen/fileutil.py b/mmgen/fileutil.py index dd4a4f94..f8704cf3 100755 --- a/mmgen/fileutil.py +++ b/mmgen/fileutil.py @@ -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 diff --git a/mmgen/obj.py b/mmgen/obj.py index 6dffaacc..bf5f72d7 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -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 ) diff --git a/mmgen/tw/ctl.py b/mmgen/tw/ctl.py index a5baf9ae..cdf4ff09 100755 --- a/mmgen/tw/ctl.py +++ b/mmgen/tw/ctl.py @@ -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') diff --git a/scripts/exec_wrapper.py b/scripts/exec_wrapper.py index 96378f7e..57f94b74 100755 --- a/scripts/exec_wrapper.py +++ b/scripts/exec_wrapper.py @@ -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() diff --git a/test/include/common.py b/test/include/common.py index 322d1da7..5ad99340 100755 --- a/test/include/common.py +++ b/test/include/common.py @@ -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): diff --git a/test/unit_tests.py b/test/unit_tests.py index cea3de3c..626a1eb4 100755 --- a/test/unit_tests.py +++ b/test/unit_tests.py @@ -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: diff --git a/test/unit_tests_d/__init__.py b/test/unit_tests_d/__init__.py index e69de29b..eee82427 100755 --- a/test/unit_tests_d/__init__.py +++ b/test/unit_tests_d/__init__.py @@ -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 diff --git a/test/unit_tests_d/ut_subseed.py b/test/unit_tests_d/ut_subseed.py index 3f787cfc..023e91d4 100755 --- a/test/unit_tests_d/ut_subseed.py +++ b/test/unit_tests_d/ut_subseed.py @@ -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')