From b98d5312ecf34d89798f0afc1de2444e47763cf4 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 3 Oct 2023 14:27:55 +0000 Subject: [PATCH] objtest.py: cleanups, import cleanups --- test/objtest.py | 30 ++++++++++++++--------------- test/objtest_py_d/ot_btc_mainnet.py | 19 ++++++++++++------ test/objtest_py_d/ot_btc_testnet.py | 6 ++++-- test/objtest_py_d/ot_common.py | 5 ++--- test/objtest_py_d/ot_eth_mainnet.py | 4 ++-- test/objtest_py_d/ot_ltc_mainnet.py | 7 +++++-- test/objtest_py_d/ot_ltc_testnet.py | 6 ++++-- 7 files changed, 44 insertions(+), 33 deletions(-) diff --git a/test/objtest.py b/test/objtest.py index 219a863e..caa6db72 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -30,17 +30,10 @@ if not os.getenv('MMGEN_DEVTOOLS'): from mmgen.devinit import init_dev init_dev() -# Import these _after_ local path's been added to sys.path -from mmgen.common import * -from mmgen.obj import * -from mmgen.seedsplit import * -from mmgen.addr import * -from mmgen.addrlist import * -from mmgen.addrdata import * -from mmgen.tw.shared import * -from mmgen.amt import * -from mmgen.key import * -from mmgen.rpc import IPPort +from mmgen.cfg import Config +from mmgen.util import msg,msg_r,gmsg,capfirst +from mmgen.color import yellow,blue,green,orange,purple,gray,nocolor +from mmgen.obj import get_obj opts_data = { 'sets': [('super_silent', True, 'silent', True)], @@ -61,10 +54,13 @@ opts_data = { cfg = Config(opts_data=opts_data) +if cfg.verbose: + from mmgen.objmethods import MMGenObject + from test.include.common import set_globals set_globals(cfg) -def run_test(test,arg,input_data,arg1,exc_name): +def run_test(mod,test,arg,input_data,arg1,exc_name): arg_copy = arg kwargs = {} ret_chk = arg @@ -111,10 +107,10 @@ def run_test(test,arg,input_data,arg1,exc_name): if cfg.test_suite_deterministic and isinstance(arg_copy,dict): arg_disp = re.sub(r'object at 0x[0-9a-f]+','object at [SCRUBBED]',arg_disp) msg_r((green if input_data=='good' else orange)(f'{arg_disp+":":<22}')) - cls = globals()[test] + cls = getattr(mod,test) if cfg.getobj: - ret = get_obj(globals()[test],**kwargs) + ret = get_obj(getattr(mod,test),**kwargs) else: ret = cls(*args,**kwargs) @@ -154,7 +150,7 @@ def run_test(test,arg,input_data,arg1,exc_name): except Exception as e: if input_data == 'good': - raise ValueError('Error on good input data') + raise ValueError(f'Error on good input data: {e}') if not type(e).__name__ == exc_name: msg(f'Incorrect exception: expected {exc_name} but got {type(e).__name__}') raise @@ -176,7 +172,8 @@ def run_test(test,arg,input_data,arg1,exc_name): def do_loop(): import importlib modname = f'test.objtest_py_d.ot_{proto.coin.lower()}_{proto.network}' - test_data = importlib.import_module(modname).tests + mod = importlib.import_module(modname) + test_data = getattr(mod,'tests') gmsg(f'Running data object tests for {proto.coin} {proto.network}') clr = None @@ -198,6 +195,7 @@ def do_loop(): msg(purple(capfirst(k)+' input:')) for arg in test_data[test][k]: run_test( + mod, test, arg, input_data = k, diff --git a/test/objtest_py_d/ot_btc_mainnet.py b/test/objtest_py_d/ot_btc_mainnet.py index 6001bec4..a59f4f04 100755 --- a/test/objtest_py_d/ot_btc_mainnet.py +++ b/test/objtest_py_d/ot_btc_mainnet.py @@ -9,12 +9,19 @@ test.objtest_py_d.ot_btc_mainnet: BTC mainnet test vectors for MMGen data object from decimal import Decimal -from mmgen.obj import * -from mmgen.addrlist import AddrIdxList -from mmgen.seedsplit import * -from mmgen.key import * -from .ot_common import * -from ..include.common import cfg +from .ot_common import r16,r32 +from ..include.common import cfg,utf8_ctrl,utf8_text,utf8_combining,gr_uc_w_ctrl,text_jp,text_zh,ru_uc,gr_uc + +from mmgen.obj import Int,MMGenTxID,CoinTxID,MMGenWalletLabel,MMGenTxComment,MMGenPWIDString +from mmgen.addrlist import AddrIdx,AddrIdxList,AddrListID +from mmgen.seed import Seed,SeedID +from mmgen.seedsplit import SeedShareIdx,SeedShareCount,SubSeedList,MasterShareIdx,SeedSplitSpecifier +from mmgen.subseed import SubSeedList,SubSeedIdx,SubSeedIdxRange +from mmgen.key import PrivKey,WifKey,PubKey +from mmgen.amt import BTCAmt +from mmgen.addr import CoinAddr,MMGenID,MMGenAddrType,MMGenPasswordType +from mmgen.tw.shared import TwMMGenID,TwLabel,TwComment +from mmgen.rpc import IPPort from mmgen.protocol import init_proto proto = init_proto( cfg, 'btc', need_amt=True ) diff --git a/test/objtest_py_d/ot_btc_testnet.py b/test/objtest_py_d/ot_btc_testnet.py index a6114b49..a3daad8d 100755 --- a/test/objtest_py_d/ot_btc_testnet.py +++ b/test/objtest_py_d/ot_btc_testnet.py @@ -7,10 +7,12 @@ test.objtest_py_d.ot_btc_testnet: BTC testnet test vectors for MMGen data objects """ -from mmgen.obj import * -from .ot_common import * +from .ot_common import r16,r32 from ..include.common import cfg +from mmgen.key import PrivKey,WifKey +from mmgen.addr import CoinAddr + from mmgen.protocol import init_proto proto = init_proto( cfg, 'btc', network='testnet', need_amt=True ) diff --git a/test/objtest_py_d/ot_common.py b/test/objtest_py_d/ot_common.py index cfb3f73c..a8ff1dd0 100755 --- a/test/objtest_py_d/ot_common.py +++ b/test/objtest_py_d/ot_common.py @@ -7,7 +7,6 @@ test.objtest_py_d.ot_common: shared data for MMGen data objects tests """ -import os -from ..include.common import * +from ..include.common import getrand -r32,r24,r16,r17,r18 = getrand(32),getrand(24),getrand(16),getrand(17),getrand(18) +r16,r32 = getrand(16),getrand(32) diff --git a/test/objtest_py_d/ot_eth_mainnet.py b/test/objtest_py_d/ot_eth_mainnet.py index 19ae1c33..7b23c715 100755 --- a/test/objtest_py_d/ot_eth_mainnet.py +++ b/test/objtest_py_d/ot_eth_mainnet.py @@ -9,8 +9,8 @@ test.objtest_py_d.ot_eth_mainnet: ETH mainnet test vectors for MMGen data object from decimal import Decimal -from mmgen.obj import * -from .ot_common import * +from mmgen.obj import ETHNonce +from mmgen.amt import ETHAmt tests = { 'ETHAmt': { diff --git a/test/objtest_py_d/ot_ltc_mainnet.py b/test/objtest_py_d/ot_ltc_mainnet.py index ee82be9d..b9e06aae 100755 --- a/test/objtest_py_d/ot_ltc_mainnet.py +++ b/test/objtest_py_d/ot_ltc_mainnet.py @@ -9,10 +9,13 @@ test.objtest_py_d.ot_ltc_mainnet: LTC mainnet test vectors for MMGen data object from decimal import Decimal -from mmgen.obj import * -from .ot_common import * +from .ot_common import r16,r32 from ..include.common import cfg +from mmgen.amt import LTCAmt +from mmgen.addr import CoinAddr +from mmgen.key import WifKey,PrivKey + from mmgen.protocol import init_proto proto = init_proto( cfg, 'ltc', need_amt=True ) diff --git a/test/objtest_py_d/ot_ltc_testnet.py b/test/objtest_py_d/ot_ltc_testnet.py index 99979962..8dcc4d91 100755 --- a/test/objtest_py_d/ot_ltc_testnet.py +++ b/test/objtest_py_d/ot_ltc_testnet.py @@ -7,10 +7,12 @@ test.objtest_py_d.ot_ltc_testnet: LTC testnet test vectors for MMGen data objects """ -from mmgen.obj import * -from .ot_common import * +from .ot_common import r16,r32 from ..include.common import cfg +from mmgen.addr import CoinAddr +from mmgen.key import WifKey,PrivKey + from mmgen.protocol import init_proto proto = init_proto( cfg, 'ltc', network='testnet', need_amt=True )