Browse Source

minor fixes and cleanups

The MMGen Project 1 year ago
parent
commit
19dc7eac26
7 changed files with 17 additions and 13 deletions
  1. 3 1
      mmgen/term.py
  2. 1 1
      mmgen/ui.py
  3. 3 3
      scripts/exec_wrapper.py
  4. 3 3
      test/include/pexpect.py
  5. 3 3
      test/test.py
  6. 1 1
      test/test_py_d/ts_base.py
  7. 3 1
      test/test_py_d/ts_input.py

+ 3 - 1
mmgen/term.py

@@ -107,7 +107,9 @@ class MMGenTermLinux(MMGenTerm):
 			ret = os.get_terminal_size()
 		except:
 			try:
-				ret = (os.environ['COLUMNS'],os.environ['LINES'])
+				ret = (
+					int(os.environ['COLUMNS']),
+					int(os.environ['LINES']) )
 			except:
 				ret = (80,25)
 		return _term_dimensions(*ret)

+ 1 - 1
mmgen/ui.py

@@ -117,7 +117,7 @@ def do_pager(text):
 	end_msg = '\n(end of text)\n\n'
 	# --- Non-MSYS Windows code deleted ---
 	# raw, chop, horiz scroll 8 chars, disable buggy line chopping in MSYS
-	os.environ['LESS'] = (('--shift 8 -RS'),('--shift 16 -RS'))[gc.platform=='win']
+	os.environ['LESS'] = '--shift 16 -RS' if gc.platform == 'win' else '--shift 8 -RS'
 
 	if 'PAGER' in os.environ and os.environ['PAGER'] != pagers[0]:
 		pagers = [os.environ['PAGER']] + pagers

+ 3 - 3
scripts/exec_wrapper.py

@@ -12,7 +12,7 @@ def exec_wrapper_get_colors():
 			(lambda s,n=n:f'\033[{n};1m{s}\033[0m' )
 		for n in (31,32,33,34,35) ])
 
-def exec_wrapper_init(): # don't change: name is used to test if script is running under exec_wrapper
+def exec_wrapper_init():
 
 	import os
 	if os.path.dirname(exec_wrapper_sys.argv[1]) == 'test': # scripts in ./test do overlay setup themselves
@@ -21,8 +21,6 @@ def exec_wrapper_init(): # don't change: name is used to test if script is runni
 		from test.overlay import overlay_setup
 		exec_wrapper_sys.path[0] = overlay_setup(repo_root=os.getcwd()) # assume we're in the repo root
 
-	os.environ['MMGEN_EXEC_WRAPPER'] = '1'
-	os.environ['PYTHONPATH'] = '.'
 	if 'TMUX' in os.environ:
 		del os.environ['TMUX']
 
@@ -32,6 +30,8 @@ def exec_wrapper_init(): # don't change: name is used to test if script is runni
 		except:
 			pass
 
+	os.environ['MMGEN_EXEC_WRAPPER'] = '1'
+
 def exec_wrapper_write_traceback(e,exit_val):
 
 	exc_line = (

+ 3 - 3
test/include/pexpect.py

@@ -42,7 +42,7 @@ class MMGenPexpect:
 			self,
 			args,
 			no_output     = False,
-			env           = None,
+			spawn_env     = None,
 			pexpect_spawn = False,
 			send_delay    = None,
 			timeout       = None,
@@ -61,9 +61,9 @@ class MMGenPexpect:
 		else:
 			timeout = int(timeout or cfg.pexpect_timeout or 0) or (60,5)[bool(cfg.debug_pexpect)]
 			if pexpect_spawn:
-				self.p = pexpect.spawn(args[0],args[1:],encoding='utf8',timeout=timeout,env=env)
+				self.p = pexpect.spawn(args[0],args[1:],encoding='utf8',timeout=timeout,env=spawn_env)
 			else:
-				self.p = PopenSpawn(args,encoding='utf8',timeout=timeout,env=env)
+				self.p = PopenSpawn(args,encoding='utf8',timeout=timeout,env=spawn_env)
 
 			if cfg.exact_output:
 				self.p.logfile = sys.stdout

+ 3 - 3
test/test.py

@@ -647,7 +647,7 @@ class TestSuiteRunner(object):
 
 		env = { 'EXEC_WRAPPER_SPAWN':'1' }
 		env.update(os.environ)
-		if 'exec_wrapper_init' in globals():
+		if os.getenv('MMGEN_EXEC_WRAPPER'):
 			# test.py itself is running under exec_wrapper, so disable traceback file writing for spawned script
 			env.update({ 'EXEC_WRAPPER_TRACEBACK':'' }) # Python 3.9: OR the dicts
 
@@ -655,7 +655,7 @@ class TestSuiteRunner(object):
 		return MMGenPexpect(
 			args          = args,
 			no_output     = no_output,
-			env           = env,
+			spawn_env     = env,
 			pexpect_spawn = pexpect_spawn,
 			timeout       = timeout,
 			send_delay    = send_delay,
@@ -1021,7 +1021,7 @@ except TestSuiteException as e:
 except TestSuiteFatalException as e:
 	die(4,e.args[0])
 except Exception:
-	if 'exec_wrapper_init' in globals(): # test.py itself is running under exec_wrapper
+	if os.getenv('MMGEN_EXEC_WRAPPER'): # 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'))

+ 1 - 1
test/test_py_d/ts_base.py

@@ -37,7 +37,7 @@ class TestSuiteBase:
 	win_skip = False
 
 	def __init__(self,trunner,cfgs,spawn):
-		if hasattr(self,'tr'): # init will be called multiple times for classes with multiple inheritance
+		if hasattr(self,'name'): # init will be called multiple times for classes with multiple inheritance
 			return
 		self.name = type(self).__name__
 		self.proto = cfg._proto

+ 3 - 1
test/test_py_d/ts_input.py

@@ -95,7 +95,7 @@ class TestSuiteInput(TestSuiteBase):
 	def get_seed_from_stdin(self):
 		self.spawn('',msg_only=True)
 		from subprocess import run,PIPE
-		cmd = ['python3','cmds/mmgen-walletconv','--in-fmt=words','--out-fmt=bip39','--outdir=test/trash']
+		cmd = ['python3','cmds/mmgen-walletconv','--in-fmt=words','--out-fmt=words','--outdir=test/trash']
 		mn = sample_mn['mmgen']['mn']
 		os.environ['MMGEN_TEST_SUITE'] = ''
 
@@ -109,6 +109,8 @@ class TestSuiteInput(TestSuiteBase):
 		set_vt100()
 		os.environ['MMGEN_TEST_SUITE'] = '1'
 		imsg(cp.stderr.decode().strip())
+		res = get_data_from_file(cfg,'test/trash/A773B05C[128].mmwords',silent=True).strip()
+		assert res == mn, f'{res} != {mn}'
 		return 'ok' if b'written to file' in cp.stderr else 'error'
 
 	def get_passphrase_ui(self):