Browse Source

unit_tests.py: cleanups, import cleanups

The MMGen Project 1 year ago
parent
commit
bbe19effb0

+ 9 - 5
test/unit_tests.py

@@ -30,7 +30,10 @@ if not os.getenv('MMGEN_DEVTOOLS'):
 	from mmgen.devinit import init_dev
 	init_dev()
 
-from mmgen.common import *
+from mmgen.cfg import Config,gc
+from mmgen.color import gray
+from mmgen.util import msg,gmsg,ymsg,Msg,die,async_run
+
 from test.include.common import set_globals,end_msg
 
 opts_data = {
@@ -60,6 +63,9 @@ sys.argv.insert(1,'--skip-cfg-file')
 
 cfg = Config(opts_data=opts_data)
 
+if cfg.no_altcoin_deps:
+	ymsg(f'{gc.prog_name}: skipping altcoin tests by user request')
+
 type(cfg)._reset_ok += ('use_internal_keccak_module','debug_addrlist')
 
 set_globals(cfg)
@@ -132,12 +138,10 @@ tests_seen = []
 def run_test(test,subtest=None):
 	mod = importlib.import_module(f'test.unit_tests_d.{file_pfx}{test}')
 
-	def run_subtest(subtest):
+	def run_subtest(t,subtest):
 		subtest_disp = subtest.replace('_','-')
 		msg(f'Running unit subtest {test}.{subtest_disp}')
 
-		t = getattr(mod,'unit_tests')()
-
 		if getattr(t,'silence_output',False):
 			t._silence()
 
@@ -188,7 +192,7 @@ def run_test(test,subtest=None):
 			elif platform.machine() == 'aarch64' and subtest in arm_skip:
 				cfg._util.qmsg(gray(f'Skipping subtest {subtest_disp!r} for ARM platform'))
 				continue
-			run_subtest(subtest)
+			run_subtest(t,subtest)
 		if hasattr(t,'_post'):
 			t._post()
 	else:

+ 3 - 1
test/unit_tests_d/ut_addrlist.py

@@ -4,7 +4,9 @@
 test.unit_tests_d.ut_addrlist: address list unit tests for the MMGen suite
 """
 
-from mmgen.common import *
+from mmgen.color import blue
+from mmgen.util import msg
+
 from mmgen.seed import Seed
 from mmgen.addr import MMGenAddrType
 from mmgen.addrlist import AddrIdxList,AddrList,KeyList,KeyAddrList,ViewKeyAddrList

+ 3 - 1
test/unit_tests_d/ut_addrparse.py

@@ -4,7 +4,9 @@
 test/unit_tests_d/ut_addrparse: address parsing tests for the MMGen suite
 """
 
-from mmgen.common import *
+from mmgen.color import yellow,cyan
+from mmgen.util import msg,msg_r,pp_fmt
+
 from ..include.common import cfg,vmsg
 
 vectors = {

+ 2 - 1
test/unit_tests_d/ut_baseconv.py

@@ -4,7 +4,8 @@
 test.unit_tests_d.ut_baseconv: Base conversion unit test for the MMGen suite
 """
 
-from mmgen.common import *
+from mmgen.util import msg,msg_r
+
 from ..include.common import cfg,qmsg,qmsg_r,vmsg,vmsg_r
 
 class unit_test(object):

+ 2 - 1
test/unit_tests_d/ut_bip39.py

@@ -4,7 +4,8 @@
 test/unit_tests_d/ut_bip39: BIP39 unit test for the MMGen suite
 """
 
-from mmgen.common import *
+from mmgen.util import msg,msg_r
+
 from ..include.common import cfg,qmsg,vmsg
 
 class unit_test(object):

+ 24 - 17
test/unit_tests_d/ut_daemon.py

@@ -4,10 +4,14 @@
 test.unit_tests_d.ut_daemon: unit test for the MMGen suite's Daemon class
 """
 
-from subprocess import run,DEVNULL
-from mmgen.common import *
-from mmgen.daemon import *
+from subprocess import run,DEVNULL,PIPE
+from collections import namedtuple
+
+from mmgen.color import orange
+from mmgen.util import fmt_list
+from mmgen.daemon import CoinDaemon
 from mmgen.protocol import init_proto
+
 from ..include.common import cfg,qmsg,qmsg_r,vmsg
 
 def test_flags():
@@ -53,19 +57,22 @@ def test_flags_err(ut,d):
 		('flag (4)', 'ClassFlagsError', 'already set',       bad7 ),
 	))
 
-def test_cmd(args_in,message):
-	qmsg_r(message)
-	args = ['python3', f'test/{args_in[0]}-coin-daemons.py'] + list(args_in[1:])
-	vmsg('\n' + orange(f"Running '{' '.join(args)}':"))
-	pipe = None if cfg.verbose else PIPE
-	cp = run( args, stdout=pipe, stderr=pipe, check=True )
-	qmsg('OK')
-	return True
-
 class unit_tests:
 
 	win_skip = ('start','status','stop')
 
+	def _pre(self):
+		self.daemon_ctrl_args = ['btc','btc_tn','btc_rt'] if cfg.no_altcoin_deps else ['all']
+
+	def _test_cmd(self,args_in,message):
+		qmsg_r(message)
+		args = ['python3', f'test/{args_in[0]}-coin-daemons.py'] + list(args_in[1:]) + self.daemon_ctrl_args
+		vmsg('\n' + orange(f"Running '{' '.join(args)}':"))
+		pipe = None if cfg.verbose else PIPE
+		cp = run( args, stdout=pipe, stderr=pipe, check=True )
+		qmsg('OK')
+		return True
+
 	def flags(self,name,ut):
 
 		qmsg_r('Testing flags and opts...')
@@ -81,16 +88,16 @@ class unit_tests:
 		return True
 
 	def exec(self,name,ut):
-		return test_cmd(['start','-Vm','all'], 'Testing availability of coin daemons...')
+		return self._test_cmd(['start','-Vm'], 'Testing availability of coin daemons...')
 
 	def cmds(self,name,ut):
-		return test_cmd(['start','-t','all'], 'Testing start commands for coin daemons...')
+		return self._test_cmd(['start','-t'], 'Testing start commands for coin daemons...')
 
 	def start(self,name,ut):
-		return test_cmd(['start','all'], 'Starting coin daemons...')
+		return self._test_cmd(['start'], 'Starting coin daemons...')
 
 	def status(self,name,ut):
-		return test_cmd(['start','all'], 'Checking status of coin daemons...')
+		return self._test_cmd(['start'], 'Checking status of coin daemons...')
 
 	def stop(self,name,ut):
-		return test_cmd(['stop','all'], 'Stopping coin daemons...')
+		return self._test_cmd(['stop'], 'Stopping coin daemons...')

+ 3 - 1
test/unit_tests_d/ut_dep.py

@@ -9,8 +9,10 @@ test.unit_tests_d.ut_dep: dependency unit tests for the MMGen suite
 
 from subprocess import run,PIPE
 
-from mmgen.common import *
+from mmgen.cfg import gc
+from mmgen.util import ymsg,gmsg
 from mmgen.exception import NoLEDSupport
+
 from ..include.common import cfg,vmsg,check_solc_ver
 
 class unit_tests:

+ 2 - 2
test/unit_tests_d/ut_flags.py

@@ -4,8 +4,8 @@
 test.unit_tests_d.ut_flags: unit test for the MMGen suite's ClassFlags class
 """
 
-from mmgen.common import *
-from mmgen.flags import *
+from mmgen.flags import ClassOpts,ClassFlags
+
 from ..include.common import qmsg,qmsg_r,vmsg
 
 class unit_test(object):

+ 2 - 1
test/unit_tests_d/ut_gen.py

@@ -4,12 +4,13 @@
 test.unit_tests_d.ut_gen: key/address generation unit tests for the MMGen suite
 """
 
-from mmgen.common import *
+from mmgen.color import blue
 from mmgen.protocol import init_proto
 from mmgen.key import PrivKey
 from mmgen.addr import MMGenAddrType
 from mmgen.addrgen import KeyGenerator,AddrGenerator
 from mmgen.keygen import get_backends
+
 from ..include.common import cfg,qmsg
 
 # TODO: add viewkey checks

+ 2 - 1
test/unit_tests_d/ut_indexed_dict.py

@@ -4,7 +4,8 @@
 test/unit_tests_d/ut_indexed_dict: IndexedDict class unit test for the MMGen suite
 """
 
-from mmgen.common import *
+from mmgen.util import msg,msg_r,die
+
 from ..include.common import vmsg
 
 class unit_test(object):

+ 0 - 1
test/unit_tests_d/ut_lockable.py

@@ -4,7 +4,6 @@
 test.unit_tests_d.ut_lockable: unit test for the MMGen suite's Lockable class
 """
 
-from mmgen.common import *
 from ..include.common import qmsg,qmsg_r,vmsg
 
 class unit_test(object):

+ 0 - 1
test/unit_tests_d/ut_obj.py

@@ -6,7 +6,6 @@ test.unit_tests_d.ut_obj: data object unit tests for the MMGen suite
 
 from decimal import Decimal
 
-from mmgen.common import *
 from ..include.common import qmsg,qmsg_r,vmsg
 
 class unit_tests:

+ 5 - 3
test/unit_tests_d/ut_rpc.py

@@ -4,15 +4,17 @@
 test.unit_tests_d.ut_rpc: RPC unit test for the MMGen suite
 """
 
-import time
-
-from mmgen.common import *
+import os,time
 
+from mmgen.cfg import gc
+from mmgen.color import yellow,cyan
+from mmgen.util import msg,gmsg,async_run,make_timestr,pp_fmt,die
 from mmgen.protocol import init_proto
 from mmgen.rpc import rpc_init
 from mmgen.daemon import CoinDaemon
 from mmgen.proto.xmr.rpc import MoneroRPCClient,MoneroWalletRPCClient
 from mmgen.proto.xmr.daemon import MoneroWalletDaemon
+
 from ..include.common import cfg,qmsg,vmsg
 
 def cfg_file_auth_test(proto,d,bad_auth=False):

+ 2 - 1
test/unit_tests_d/ut_seedsplit.py

@@ -4,7 +4,8 @@
 test/unit_tests_d/ut_seedsplit: seed splitting unit test for the MMGen suite
 """
 
-from mmgen.common import *
+from mmgen.util import msg,msg_r
+
 from ..include.common import cfg,vmsg,vmsg_r
 
 class unit_test(object):

+ 2 - 1
test/unit_tests_d/ut_subseed.py

@@ -4,7 +4,8 @@
 test/unit_tests_d/ut_subseed: subseed unit test for the MMGen suite
 """
 
-from mmgen.common import *
+from mmgen.util import msg,msg_r
+
 from ..include.common import cfg,vmsg_r
 
 class unit_test(object):

+ 4 - 1
test/unit_tests_d/ut_testdep.py

@@ -4,9 +4,12 @@
 test.unit_tests_d.ut_testdep: test dependency unit tests for the MMGen suite
 """
 
-from mmgen.common import *
+import os
 from subprocess import run,PIPE
 
+from mmgen.cfg import gc
+from mmgen.util import ymsg
+
 sec = 'deadbeef' * 8
 
 class unit_tests:

+ 2 - 2
test/unit_tests_d/ut_tx.py

@@ -4,13 +4,13 @@
 test.unit_tests_d.ut_tx: TX unit tests for the MMGen suite
 """
 
-import re
+import os,re
 
-from mmgen.common import *
 from mmgen.tx import NewTX,CompletedTX
 from mmgen.tx.file import MMGenTxFile
 from mmgen.daemon import CoinDaemon
 from mmgen.protocol import init_proto
+
 from ..include.common import cfg,qmsg,vmsg
 
 async def do_txfile_test(desc,fns):

+ 5 - 3
test/unit_tests_d/ut_tx_deserialize.py

@@ -6,14 +6,15 @@ test/unit_tests_d/ut_tx_deserialize: TX deserialization unit tests for the MMGen
 
 import os,json
 
-from mmgen.common import *
-from ..include.common import cfg,start_test_daemons,stop_test_daemons
+from mmgen.util import msg,Msg,Msg_r
 from mmgen.protocol import init_proto
 from mmgen.tx import CompletedTX
 from mmgen.proto.btc.tx.base import DeserializeTX
 from mmgen.rpc import rpc_init
 from mmgen.daemon import CoinDaemon
 
+from ..include.common import cfg,start_test_daemons,stop_test_daemons
+
 def print_info(name,extra_desc):
 	if cfg.names:
 		Msg_r('{} {} {}'.format(
@@ -106,7 +107,8 @@ class unit_tests:
 
 		core_repo_root = os.getenv('CORE_REPO_ROOT')
 		if not core_repo_root:
-			die(1,'The environmental variable CORE_REPO_ROOT must be set before running this test')
+			msg('The environmental variable CORE_REPO_ROOT must be set before running this test')
+			return False
 
 		start_test_daemons('btc')
 

+ 2 - 1
test/unit_tests_d/ut_xmrseed.py

@@ -4,7 +4,8 @@
 test/unit_tests_d/ut_xmrseed: Monero mnemonic unit test for the MMGen suite
 """
 
-from mmgen.common import *
+from mmgen.util import msg,msg_r
+
 from ..include.common import cfg,qmsg,vmsg
 
 class unit_test(object):