From 19dc7eac26072f603b4e76eb0500bd51336c1a8b Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 23 May 2023 12:12:32 +0000 Subject: [PATCH] minor fixes and cleanups --- mmgen/term.py | 4 +++- mmgen/ui.py | 2 +- scripts/exec_wrapper.py | 6 +++--- test/include/pexpect.py | 6 +++--- test/test.py | 6 +++--- test/test_py_d/ts_base.py | 2 +- test/test_py_d/ts_input.py | 4 +++- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/mmgen/term.py b/mmgen/term.py index 7761997e..57fac4d8 100755 --- a/mmgen/term.py +++ b/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) diff --git a/mmgen/ui.py b/mmgen/ui.py index c2cf4038..bfccf78e 100755 --- a/mmgen/ui.py +++ b/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 diff --git a/scripts/exec_wrapper.py b/scripts/exec_wrapper.py index 66f96161..fad15215 100755 --- a/scripts/exec_wrapper.py +++ b/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 = ( diff --git a/test/include/pexpect.py b/test/include/pexpect.py index 8fbb0baf..f95efff8 100755 --- a/test/include/pexpect.py +++ b/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 diff --git a/test/test.py b/test/test.py index 09bab7e7..63e9fc42 100755 --- a/test/test.py +++ b/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')) diff --git a/test/test_py_d/ts_base.py b/test/test_py_d/ts_base.py index d3e5bfbc..6f6b9fee 100755 --- a/test/test_py_d/ts_base.py +++ b/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 diff --git a/test/test_py_d/ts_input.py b/test/test_py_d/ts_input.py index 35ca2bb8..43ad1643 100755 --- a/test/test_py_d/ts_input.py +++ b/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):