From 6cd88569128680486f9648b6515677f622dc5fd3 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 28 Mar 2023 18:14:37 +0000 Subject: [PATCH] minor whitespace, cleanups --- mmgen/globalvars.py | 8 +++++--- mmgen/proto/btc/daemon.py | 2 +- mmgen/tool/common.py | 7 ++----- test/include/pexpect.py | 1 + test/test_py_d/ts_ref_3seed.py | 3 ++- test/test_py_d/ts_regtest.py | 1 + test/tooltest.py | 6 ++++-- test/unit_tests_d/ut_rpc.py | 9 ++++++--- 8 files changed, 22 insertions(+), 15 deletions(-) diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index d6de0944..fb9785dc 100755 --- a/mmgen/globalvars.py +++ b/mmgen/globalvars.py @@ -34,6 +34,8 @@ class GlobalConstants(Lockable): These values are non-configurable. They’re constant for a given machine, user, executable and MMGen release. """ + _autolock = True + proj_name = 'MMGen' proj_url = 'https://github.com/mmgen/mmgen' author = 'The MMGen Project' @@ -304,10 +306,10 @@ class GlobalConfig(Lockable): 'eth_testnet_chain_names' ) # Supported environmental vars - # The corresponding vars (lowercase, minus 'mmgen_') must be initialized in g - # 'DISABLE_' env vars disable the corresponding var in g + # The corresponding attributes (lowercase, without 'mmgen_') must exist in the class. + # The 'MMGEN_DISABLE_' prefix sets the corresponding attribute to False. env_opts = ( - 'MMGEN_DEBUG_ALL', # special: there is no g.debug_all var + 'MMGEN_DEBUG_ALL', # special: there is no `debug_all` attribute 'MMGEN_COLUMNS', 'MMGEN_TEST_SUITE', diff --git a/mmgen/proto/btc/daemon.py b/mmgen/proto/btc/daemon.py index 08ddad18..a35b50ec 100755 --- a/mmgen/proto/btc/daemon.py +++ b/mmgen/proto/btc/daemon.py @@ -28,11 +28,11 @@ class bitcoin_core_daemon(CoinDaemon): tracking_wallet_name = 'mmgen-tracking-wallet' rpc_ports = _nw(8332, 18332, 18443) cfg_file = 'bitcoin.conf' + nonstd_datadir = False datadirs = { 'linux': [gc.home_dir,'.bitcoin'], 'win': [os.getenv('APPDATA'),'Bitcoin'] } - nonstd_datadir = False def init_datadir(self): if self.network == 'regtest' and not self.test_suite: diff --git a/mmgen/tool/common.py b/mmgen/tool/common.py index 70da9f59..dbec9628 100755 --- a/mmgen/tool/common.py +++ b/mmgen/tool/common.py @@ -34,11 +34,8 @@ class tool_cmd_base(MMGenObject): def __init__(self,cmdname=None,proto=None,mmtype=None): if self.need_proto: - if proto: - self.proto = proto - else: - from ..protocol import init_proto_from_opts - self.proto = init_proto_from_opts(need_amt=self.need_amt) + from ..protocol import init_proto_from_opts + self.proto = proto or init_proto_from_opts(need_amt=self.need_amt) from ..globalvars import g if g.token: self.proto.tokensym = g.token.upper() diff --git a/test/include/pexpect.py b/test/include/pexpect.py index 627478c1..d2506958 100755 --- a/test/include/pexpect.py +++ b/test/include/pexpect.py @@ -178,6 +178,7 @@ class MMGenPexpect: r'(\b|\s)' + fr'\s{allrep}\s'.join(s.replace(r'.',r'\.').replace(' ',r'\s+') for s in expect_list) + r'(\b|\s)' ) + import re m = re.search(expect,res,re.DOTALL) assert m, f'No match found for regular expression {expect!r}' return m diff --git a/test/test_py_d/ts_ref_3seed.py b/test/test_py_d/ts_ref_3seed.py index b2a56ea9..af116f00 100755 --- a/test/test_py_d/ts_ref_3seed.py +++ b/test/test_py_d/ts_ref_3seed.py @@ -121,7 +121,8 @@ class TestSuiteRef3Seed(TestSuiteBase,TestSuiteShared): ] slarg = [f'-l{self.seed_len} '] hparg = ['-p1'] - if wtype == 'hic_wallet_old' and opt.profile: msg('') + if wtype == 'hic_wallet_old' and opt.profile: + msg('') t = self.spawn('mmgen-walletchk', slarg + hparg + of_arg + ic_arg, extra_desc=edesc) diff --git a/test/test_py_d/ts_regtest.py b/test/test_py_d/ts_regtest.py index b40cacc4..a4ff238a 100755 --- a/test/test_py_d/ts_regtest.py +++ b/test/test_py_d/ts_regtest.py @@ -1385,6 +1385,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): return self.alice_add_comment_badaddr( rt_pw, 'invalid address', 2 ) def alice_add_comment_badaddr2(self): + # mainnet zero address: addr = init_proto(self.proto.coin,network='mainnet').pubhash2addr(bytes(20),False) # mainnet zero address return self.alice_add_comment_badaddr( addr, 'invalid address', 2 ) diff --git a/test/tooltest.py b/test/tooltest.py index 0af46778..0c1f863c 100755 --- a/test/tooltest.py +++ b/test/tooltest.py @@ -266,10 +266,12 @@ class MMGenToolTestUtils(object): def run_cmd_out(self,name,carg=None,Return=False,kwargs='',fn_idx='',extra_msg='', literal=False,chkdata='',hush=False,add_opts=[]): - if carg: write_to_tmpfile(cfg,f'{name}{fn_idx}.in',carg+'\n') + if carg: + write_to_tmpfile(cfg,f'{name}{fn_idx}.in',carg+'\n') ret = self.run_cmd(name,([],[carg])[bool(carg)],kwargs=kwargs, extra_msg=extra_msg,add_opts=add_opts) - if carg: vmsg('In: ' + repr(carg)) + if carg: + vmsg('In: ' + repr(carg)) vmsg('Out: ' + (repr(ret),ret)[literal]) if ret or ret == '': write_to_tmpfile(cfg,f'{name}{fn_idx}.out',ret+'\n') diff --git a/test/unit_tests_d/ut_rpc.py b/test/unit_tests_d/ut_rpc.py index d75a9ecf..61d04daf 100755 --- a/test/unit_tests_d/ut_rpc.py +++ b/test/unit_tests_d/ut_rpc.py @@ -31,10 +31,12 @@ def cfg_file_auth_test(proto,d,bad_auth=False): if bad_auth: os.rename(d.auth_cookie_fn,d.auth_cookie_fn+'.bak') - try: async_run(rpc_init(proto)) + try: + async_run(rpc_init(proto)) except Exception as e: vmsg(yellow(str(e))) - else: die(3,'No error on missing credentials!') + else: + die(3,'No error on missing credentials!') os.rename(d.auth_cookie_fn+'.bak',d.auth_cookie_fn) else: rpc = async_run(rpc_init(proto)) @@ -174,7 +176,8 @@ class unit_tests: passwd = None, daemon = md, ) - print_daemon_info(rpc) + if opt.verbose: + print_daemon_info(rpc) rpc.call_raw('get_height') rpc.call('get_last_block_header')