Browse Source

init_proto(): add `return_cls` param; cmdtest.py: minor cleanups

The MMGen Project 1 year ago
parent
commit
fb9c5ac22c
5 changed files with 17 additions and 11 deletions
  1. 2 1
      mmgen/cfg.py
  2. 5 3
      mmgen/daemon.py
  3. 5 1
      mmgen/protocol.py
  4. 4 4
      test/cmdtest.py
  5. 1 2
      test/cmdtest_py_d/cfg.py

+ 2 - 1
mmgen/cfg.py

@@ -572,7 +572,8 @@ class Config(Lockable):
 						(ns[2:],ns[1]=='testnet') if len(ns) > 2 and ns[1] in ('mainnet','testnet') else
 						(ns[1:],False)
 					)
-					cls = type(init_proto( self, ns[0], tn, need_amt=True )) # no instance yet, so override _class_ attr
+					# no instance yet, so override _class_ attr:
+					cls = init_proto(self, ns[0], tn, need_amt=True, return_cls=True)
 					attr = '_'.join(nse)
 				else:
 					cls = self

+ 5 - 3
mmgen/daemon.py

@@ -319,11 +319,13 @@ class CoinDaemon(Daemon):
 
 	@classmethod
 	def get_daemon(cls,cfg,coin,daemon_id,proto=None):
-		if not proto:
+		if proto:
+			proto_cls = type(proto)
+		else:
 			from .protocol import init_proto
-			proto = init_proto( cfg, coin )
+			proto_cls = init_proto(cfg, coin, return_cls=True)
 		return getattr(
-			importlib.import_module(f'mmgen.proto.{proto.base_proto_coin.lower()}.daemon'),
+			importlib.import_module(f'mmgen.proto.{proto_cls.base_proto_coin.lower()}.daemon'),
 			daemon_id+'_daemon' )
 
 	@classmethod

+ 5 - 1
mmgen/protocol.py

@@ -238,7 +238,8 @@ def init_proto(
 		network    = None,
 		network_id = None,
 		tokensym   = None,
-		need_amt   = False ):
+		need_amt   = False,
+		return_cls = False):
 
 	assert type(testnet) is bool, 'init_proto_chk1'
 	assert type(regtest) is bool, 'init_proto_chk2'
@@ -271,6 +272,9 @@ def init_proto(
 			getattr(importlib.import_module(f'mmgen.proto.{coin}.params'),network)
 		)
 
+	if return_cls:
+		return getattr(CoinProtocol,proto_name)
+
 	return getattr(CoinProtocol,proto_name)(
 		cfg       = cfg,
 		coin      = coin,

+ 4 - 4
test/cmdtest.py

@@ -94,7 +94,7 @@ else:
 		from test.include.test_init import repo_root
 
 from mmgen.cfg import Config,gc
-from mmgen.color import red,yellow,green,blue,cyan,nocolor,init_color
+from mmgen.color import red,yellow,green,blue,cyan,gray,nocolor,init_color
 from mmgen.util import Msg,bmsg,die,suf,make_timestr,async_run
 
 from test.include.common import (
@@ -699,7 +699,7 @@ class CmdTestRunner:
 		ct_cls = CmdGroupMgr().load_mod(gname)
 
 		if sys.platform == 'win32' and ct_cls.win_skip:
-			omsg(f'Skipping test {gname!r} for Windows platform')
+			omsg(gray(f'INFO → skipping test {gname!r} (platform=win32)'))
 			return False
 
 		for k in ('segwit','segwit_random','bech32'):
@@ -719,7 +719,7 @@ class CmdTestRunner:
 		m = ''.join(gen_msg())
 
 		if segwit_opt and not ct_cls.segwit_opts_ok:
-			iqmsg('INFO → skipping ' + m)
+			iqmsg(gray(f'INFO → skipping {m}'))
 			return False
 
 		# 'networks = ()' means all networks allowed
@@ -731,7 +731,7 @@ class CmdTestRunner:
 				if a == coin and b == nw:
 					break
 			else:
-				iqmsg('INFO → skipping ' + m)
+				iqmsg(gray(f'INFO → skipping {m} (network={nw})'))
 				return False
 
 		if do_clean:

+ 1 - 2
test/cmdtest_py_d/cfg.py

@@ -12,8 +12,6 @@
 test.cmdtest_py_d.cfg: configuration data for cmdtest.py
 """
 
-import os
-
 from .common import pwfile,hincog_fn,incog_id_fn,randbool
 from ..include.common import cfg
 
@@ -222,6 +220,7 @@ cfgs = { # addr_idx_lists (except 31,32,33,34) must contain exactly 8 addresses
 }
 
 def fixup_cfgs():
+	import os
 	for src,target in (
 			('6','11'),
 			('7','12'),