Browse Source

minor fixes and cleanups

The MMGen Project 3 years ago
parent
commit
3a2cb6f551
6 changed files with 32 additions and 26 deletions
  1. 4 2
      test/gentest.py
  2. 5 4
      test/include/pexpect.py
  3. 1 2
      test/misc/tool_api_test.py
  4. 16 16
      test/test.py
  5. 1 1
      test/test_py_d/ts_main.py
  6. 5 1
      test/tooltest2.py

+ 4 - 2
test/gentest.py

@@ -331,8 +331,10 @@ def speed_test(kg,ag,rounds):
 		sec = PrivKey(proto,seed+pack('I',i),compressed=addr_type.compressed,pubkey_type=addr_type.pubkey_type)
 		addr = ag.to_addr(kg.to_pubhex(sec))
 		vmsg(f'\nkey:  {sec.wif}\naddr: {addr}\n')
-	qmsg_r(f'\rRound {i+1}/{rounds} ')
-	qmsg(f'\n{rounds} addresses generated in {time.time()-start:.2f} seconds')
+	qmsg(
+		f'\rRound {i+1}/{rounds} ' +
+		f'\n{rounds} addresses generated in {time.time()-start:.2f} seconds'
+	)
 
 def dump_test(kg,ag,fh):
 

+ 5 - 4
test/include/pexpect.py

@@ -41,7 +41,7 @@ NL = '\n'
 
 class MMGenPexpect(object):
 
-	def __init__(self,args,no_output=False):
+	def __init__(self,args,no_output=False,env=None):
 
 		if opt.direct_exec:
 			msg('')
@@ -50,13 +50,14 @@ class MMGenPexpect(object):
 		else:
 			timeout = int(opt.pexpect_timeout or 0) or (60,5)[bool(opt.debug_pexpect)]
 			if opt.pexpect_spawn:
-				self.p = pexpect.spawn(args[0],args[1:],encoding='utf8',timeout=timeout)
+				self.p = pexpect.spawn(args[0],args[1:],encoding='utf8',timeout=timeout,env=env)
 				self.p.delaybeforesend = 0
 			else:
-				self.p = PopenSpawn(args,encoding='utf8',timeout=timeout)
+				self.p = PopenSpawn(args,encoding='utf8',timeout=timeout,env=env)
 #				self.p.delaybeforesend = 0 # TODO: try this here too
 
-			if opt.exact_output: self.p.logfile = sys.stdout
+			if opt.exact_output:
+				self.p.logfile = sys.stdout
 
 		self.req_exit_val = 0
 		self.skip_ok = False

+ 1 - 2
test/misc/tool_api_test.py

@@ -8,8 +8,7 @@ tool_api_test.py: test the MMGen suite tool API
 """
 
 import sys,os
-os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(sys.argv[0])))))
-sys.path[0] = os.curdir
+from mmgen.common import *
 from mmgen.obj import PrivKey,CoinAddr
 
 keys = [

+ 16 - 16
test/test.py

@@ -71,6 +71,7 @@ def create_shm_dir(data_dir,trash_dir):
 	return shm_dir
 
 import sys,os,time
+
 from include.tests_header import repo_root
 
 try: os.unlink(os.path.join(repo_root,'my.err'))
@@ -88,7 +89,7 @@ opts_data = {
 	'text': {
 		'desc': 'Test suite for the MMGen suite',
 		'usage':'[options] [command(s) or metacommand(s)]',
-		'options': """
+		'options': f"""
 -h, --help           Print this help message
 --, --longhelp       Print help message for long options (common options)
 -A, --no-daemon-autostart Don't start and stop daemons automatically
@@ -108,7 +109,7 @@ opts_data = {
 -g, --list-current-cmd-groups List command groups for current configuration
 -n, --names          Display command names instead of descriptions
 -N, --no-timings     Suppress display of timing information
--o, --log            Log commands to file {lf}
+-o, --log            Log commands to file {log_file!r}
 -O, --pexpect-spawn  Use pexpect.spawn instead of popen_spawn (much slower,
                      kut does real terminal emulation)
 -p, --pause          Pause between tests, resuming on keypress
@@ -133,11 +134,6 @@ opts_data = {
 If no command is given, the whole test suite is run.
 """
 	},
-	'code': {
-		'options': lambda s: s.format(
-			ew='scripts/exec_wrapper.py',
-			lf=log_file),
-	}
 }
 
 data_dir = get_data_dir() # include/common.py
@@ -773,6 +769,10 @@ class TestSuiteRunner(object):
 		if not quiet:
 			bmsg('Executing ' + m)
 
+		if not self.daemons_started and network_id not in ('eth','etc','xmr'):
+			start_test_daemons(network_id,remove_datadir=True)
+			self.daemons_started = True
+
 		os.environ['MMGEN_BOGUS_WALLET_DATA'] = '' # zero this here, so test group doesn't have to
 		self.ts = self.gm.gm_init_group(self,gname,self.spawn_wrapper)
 
@@ -788,19 +788,20 @@ class TestSuiteRunner(object):
 
 	def run_tests(self,usr_args):
 		self.start_time = time.time()
+		self.daemons_started = False
 		gname_save = None
 		if usr_args:
 			for arg in usr_args:
+				if arg in utils:
+					params = usr_args[usr_args.index(arg)+1:]
+					globals()[arg](*params)
+					sys.exit(0)
 				if arg in self.gm.cmd_groups:
 					if not self.init_group(arg):
 						continue
 					for cmd in self.gm.cmd_list:
 						self.check_needs_rerun(cmd,build=True)
 						do_between()
-				elif arg in utils:
-					params = usr_args[usr_args.index(arg)+1:]
-					globals()[arg](*params)
-					sys.exit(0)
 				else:
 					if ':' in arg:
 						gname,arg = arg.split(':')
@@ -944,6 +945,7 @@ class TestSuiteRunner(object):
 
 	def process_retval(self,cmd,ret):
 		if type(ret).__name__ == 'MMGenPexpect':
+			ret.read()
 			ret.ok()
 			self.cmd_total += 1
 		elif ret == 'ok':
@@ -1019,8 +1021,6 @@ if opt.pause:
 	set_restore_term_at_exit()
 
 set_environ_for_spawned_scripts()
-if network_id not in ('eth','etc','xmr'):
-	start_test_daemons(network_id,remove_datadir=True)
 
 try:
 	tr = TestSuiteRunner(data_dir,trash_dir)
@@ -1038,12 +1038,12 @@ except TestSuiteException as e:
 except TestSuiteFatalException as e:
 	rdie(1,e.args[0])
 except Exception:
-	if opt.exec_wrapper:
-		msg(blue('Spawned script exited with error'))
-	else:
+	if 'exec_wrapper_init' in globals(): # test.py itself is running under exec_wrapper
 		import traceback
 		print(''.join(traceback.format_exception(*sys.exc_info())))
 		msg(blue('Test script exited with error'))
+	else:
+		msg(blue('Spawned script exited with error'))
 	raise
 except:
 	raise

+ 1 - 1
test/test_py_d/ts_main.py

@@ -481,7 +481,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared):
 			outputs_list.append(len(tx_data)*(addrs_per_wallet+1) + 1)
 
 		self.txcreate_ui_common(t,
-			menu        = (['M'],['M','D','m','g'])[self.test_name=='txcreate'],
+			menu        = (['M'],['M','D','D','D','D','m','g'])[self.test_name=='txcreate'],
 			inputs      = ' '.join(map(str,outputs_list)),
 			add_comment = ('',tx_label_lat_cyr_gr)[do_label],
 			view        = view,

+ 5 - 1
test/tooltest2.py

@@ -818,7 +818,11 @@ async def run_test(gid,cmd_name):
 	msg_r(green(m)+'\n' if opt.verbose else m)
 
 	def fork_cmd(cmd_name,args,out,opts):
-		cmd = list(tool_cmd) + (opts or []) + [cmd_name] + args
+		cmd = (
+			list(tool_cmd) +
+			(opts or []) +
+			[cmd_name] + args
+		)
 		vmsg('{} {}'.format(
 			green('Executing'),
 			cyan(' '.join(cmd)) ))