Browse Source

scripts/traceback_run.py -> scripts/exec_wrapper.py

The MMGen Project 3 years ago
parent
commit
54d123fdc0
5 changed files with 27 additions and 27 deletions
  1. 14 14
      scripts/exec_wrapper.py
  2. 8 8
      test/test.py
  3. 1 1
      test/test_py_d/ts_ethdev.py
  4. 1 1
      test/test_py_d/ts_regtest.py
  5. 3 3
      test/tooltest2.py

+ 14 - 14
scripts/traceback_run.py → scripts/exec_wrapper.py

@@ -2,18 +2,18 @@
 
 # Import as few modules and define as few names as possible at global level before exec'ing the
 # file, as all names will be seen by the exec'ed code.  To prevent name collisions, all names
-# defined here should begin with 'traceback_run_'
+# defined here should begin with 'exec_wrapper_'
 
 import sys,os,time
 
-def traceback_run_get_colors():
+def exec_wrapper_get_colors():
 	from collections import namedtuple
 	return namedtuple('colors',['red','green','yellow','blue'])(*[
 			(lambda s:s) if os.getenv('MMGEN_DISABLE_COLOR') else
 			(lambda s,n=n:f'\033[{n};1m{s}\033[0m' )
 		for n in (31,32,33,34) ])
 
-def traceback_run_init():
+def exec_wrapper_init():
 
 	sys.path[0] = 'test' if os.path.dirname(sys.argv[1]) == 'test' else '.'
 
@@ -28,38 +28,38 @@ def traceback_run_init():
 
 	return of
 
-def traceback_run_process_exception():
+def exec_wrapper_write_traceback():
 	import traceback,re
 	lines = traceback.format_exception(*sys.exc_info()) # returns a list
 
 	pat = re.compile('File "<string>"')
-	repl = f'File "{traceback_run_execed_file}"'
+	repl = f'File "{exec_wrapper_execed_file}"'
 	lines = [pat.sub(repl,line,count=1) for line in lines]
 
 	exc = lines.pop()
 	if exc.startswith('SystemExit:'):
 		lines.pop()
 
-	c = traceback_run_get_colors()
+	c = exec_wrapper_get_colors()
 	sys.stdout.write('{}{}'.format(c.yellow(''.join(lines)),c.red(exc)))
 
-	open(traceback_run_outfile,'w').write(''.join(lines+[exc]))
+	open(exec_wrapper_traceback_file,'w').write(''.join(lines+[exc]))
 
-traceback_run_outfile = traceback_run_init() # sets sys.path[0]
-traceback_run_tstart = time.time()
+exec_wrapper_traceback_file = exec_wrapper_init() # sets sys.path[0]
+exec_wrapper_tstart = time.time()
 
 try:
 	sys.argv.pop(0)
-	traceback_run_execed_file = sys.argv[0]
+	exec_wrapper_execed_file = sys.argv[0]
 	exec(open(sys.argv[0]).read())
 except SystemExit as e:
 	if e.code != 0:
-		traceback_run_process_exception()
+		exec_wrapper_write_traceback()
 	sys.exit(e.code)
 except Exception as e:
-	traceback_run_process_exception()
+	exec_wrapper_write_traceback()
 	retval = e.mmcode if hasattr(e,'mmcode') else e.code if hasattr(e,'code') else 1
 	sys.exit(retval)
 
-c = traceback_run_get_colors()
-sys.stderr.write(c.blue('Runtime: {:0.5f} secs\n'.format(time.time() - traceback_run_tstart)))
+c = exec_wrapper_get_colors()
+sys.stderr.write(c.blue('Runtime: {:0.5f} secs\n'.format(time.time() - exec_wrapper_tstart)))

+ 8 - 8
test/test.py

@@ -120,10 +120,10 @@ opts_data = {
                      than those in the repo root
 -S, --skip-deps      Skip dependency checking for command
 -u, --usr-random     Get random data interactively from user
--t, --traceback      Run the command inside the '{tbc}' script
 -T, --pexpect-timeout=T Set the timeout for pexpect
 -v, --verbose        Produce more verbose output
 -W, --no-dw-delete   Don't remove default wallet from data dir after dw tests are done
+-x, --exec-wrapper   Run the command inside the '{ew}' script
 -X, --exit-after=C   Exit after command 'C'
 -y, --segwit         Generate and use Segwit addresses
 -Y, --segwit-random  Generate and use a random mix of Segwit and Legacy addrs
@@ -135,7 +135,7 @@ If no command is given, the whole test suite is run.
 	},
 	'code': {
 		'options': lambda s: s.format(
-			tbc='scripts/traceback_run.py',
+			ew='scripts/exec_wrapper.py',
 			lf=log_file),
 	}
 }
@@ -482,8 +482,8 @@ def set_environ_for_spawned_scripts():
 	if not opt.buf_keypress:
 		os.environ['MMGEN_DISABLE_HOLD_PROTECT'] = '1'
 
-	# If test.py itself is running under traceback, the spawned script shouldn't be, so disable this:
-	if os.getenv('MMGEN_TRACEBACK') and not opt.traceback:
+	# If test.py itself is running under exec_wrapper, the spawned script shouldn't be, so disable this:
+	if os.getenv('MMGEN_TRACEBACK') and not opt.exec_wrapper:
 		os.environ['MMGEN_TRACEBACK'] = ''
 
 	os.environ['MMGEN_NO_LICENSE'] = '1'
@@ -661,7 +661,7 @@ class TestSuiteRunner(object):
 			msg_only     = False,
 			no_msg       = False,
 			cmd_dir      = 'cmds',
-			no_traceback = False ):
+			no_exec_wrapper = False ):
 
 		desc = self.ts.test_name if opt.names else self.gm.dpy_data[self.ts.test_name][1]
 		if extra_desc: desc += ' ' + extra_desc
@@ -678,8 +678,8 @@ class TestSuiteRunner(object):
 
 		args = [cmd] + passthru_opts + self.ts.extra_spawn_args + args
 
-		if opt.traceback and not no_traceback:
-			args = ['scripts/traceback_run.py'] + args
+		if opt.exec_wrapper and not no_exec_wrapper:
+			args = ['scripts/exec_wrapper.py'] + args
 
 		if g.platform == 'win':
 			args = ['python3'] + args
@@ -1038,7 +1038,7 @@ except TestSuiteException as e:
 except TestSuiteFatalException as e:
 	rdie(1,e.args[0])
 except Exception:
-	if opt.traceback:
+	if opt.exec_wrapper:
 		msg(blue('Spawned script exited with error'))
 	else:
 		import traceback

+ 1 - 1
test/test_py_d/ts_ethdev.py

@@ -743,7 +743,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
 		try: os.mkdir(odir)
 		except: pass
 		cmd = [
-			'scripts/traceback_run.py',
+			'scripts/exec_wrapper.py',
 			'scripts/create-token.py',
 			'--coin=' + self.proto.coin,
 			'--outdir=' + odir

+ 1 - 1
test/test_py_d/ts_regtest.py

@@ -320,7 +320,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
 
 		icls = MMGenWallet
 		fn = get_file_with_ext(self._user_dir(user),icls.ext)
-		t = self.spawn('mmgen-tool',['get_subseed',subseed_idx,'wallet='+fn],no_msg=True,no_traceback=True)
+		t = self.spawn('mmgen-tool',['get_subseed',subseed_idx,'wallet='+fn],no_msg=True,no_exec_wrapper=True)
 		t.passphrase(icls.desc,rt_pw)
 		sid = t.read().strip()[:8]
 		self.usr_subsids[user][subseed_idx] = sid

+ 3 - 3
test/tooltest2.py

@@ -75,7 +75,7 @@ opts_data = {
                      those in the repo root
 -t, --type=          Specify coin type
 -f, --fork           Run commands via tool executable instead of importing tool module
--t, --traceback      Run tool inside traceback script
+-x, --exec-wrapper   Run tool inside exec_wrapper script
 -v, --verbose        Produce more verbose output
 """,
 	'notes': """
@@ -1029,8 +1029,8 @@ if opt.fork:
 		'='+getattr(opt,k) if getattr(opt,k) != True else ''
 		) for k in passthru_args if getattr(opt,k)])
 
-	if opt.traceback:
-		tool_cmd = (os.path.join('scripts','traceback_run.py'),) + tool_cmd
+	if opt.exec_wrapper:
+		tool_cmd = (os.path.join('scripts','exec_wrapper.py'),) + tool_cmd
 
 	if opt.coverage:
 		d,f = init_coverage()