diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index 3e733d16..ddd228b5 100755 --- a/mmgen/globalvars.py +++ b/mmgen/globalvars.py @@ -120,7 +120,10 @@ class GlobalContext(Lockable): terminal_width = 0 mnemonic_entry_modes = {} - color = sys.stdout.isatty() + color = bool( + ( sys.stdout.isatty() and not os.getenv('MMGEN_TEST_SUITE_PEXPECT') ) or + os.getenv('MMGEN_FORCE_COLOR') + ) for k in ('linux','win','msys'): if sys.platform[:len(k)] == k: diff --git a/mmgen/util.py b/mmgen/util.py index be4ce2c0..3615777a 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -151,7 +151,11 @@ def set_for_type(val,refval,desc,invert_bool=False,src=None): if type(refval) == bool: v = str(val).lower() - ret = True if v in ('true','yes','1') else False if v in ('false','no','none','0') else None + ret = ( + True if v in ('true','yes','1','on') else + False if v in ('false','no','none','0','off','') else + None + ) if ret is not None: return not ret if invert_bool else ret else: diff --git a/test/include/common.py b/test/include/common.py index d3923068..0ce6abe3 100755 --- a/test/include/common.py +++ b/test/include/common.py @@ -27,6 +27,10 @@ import os from mmgen.common import * from mmgen.devtools import * +def strip_ansi_escapes(s): + import re + return re.sub('\x1b\[[;0-9]+?m','',s) + ascii_uc = ''.join(map(chr,list(range(65,91)))) # 26 chars ascii_lc = ''.join(map(chr,list(range(97,123)))) # 26 chars lat_accent = ''.join(map(chr,list(range(192,383)))) # 191 chars, L,S diff --git a/test/objtest.py b/test/objtest.py index 785c98ac..a36bfd20 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -178,7 +178,7 @@ def do_loop(): msg(clr(f'{nl}Testing {test}')) for k in ('bad','good'): - if not opt.silent: + if not opt.super_silent: msg(purple(capfirst(k)+' input:')) for arg in test_data[test][k]: run_test( diff --git a/test/objtest_py_d/ot_btc_mainnet.py b/test/objtest_py_d/ot_btc_mainnet.py index 828efb33..6e39fd65 100755 --- a/test/objtest_py_d/ot_btc_mainnet.py +++ b/test/objtest_py_d/ot_btc_mainnet.py @@ -169,6 +169,7 @@ tests = { 'arg1': 'proto', 'exc_name': 'BadTwLabel', 'bad': ( + {'text':'', 'proto':proto}, {'text':'x x', 'proto':proto}, {'text':'x я', 'proto':proto}, {'text':'я:я', 'proto':proto}, diff --git a/test/test.py b/test/test.py index 6b021880..5bcb64aa 100755 --- a/test/test.py +++ b/test/test.py @@ -460,8 +460,13 @@ def set_environ_for_spawned_scripts(): for name in g.env_opts: if name[:11] == 'MMGEN_DEBUG': os.environ[name] = '1' - if not opt.pexpect_spawn: os.environ['MMGEN_TEST_SUITE_POPEN_SPAWN'] = '1' - if not opt.system: os.environ['PYTHONPATH'] = repo_root + + if not opt.pexpect_spawn: + os.environ['MMGEN_TEST_SUITE_POPEN_SPAWN'] = '1' + + if not opt.system: + os.environ['PYTHONPATH'] = repo_root + if not opt.buf_keypress: os.environ['MMGEN_DISABLE_HOLD_PROTECT'] = '1' @@ -469,11 +474,10 @@ def set_environ_for_spawned_scripts(): if os.getenv('MMGEN_TRACEBACK') and not opt.traceback: os.environ['MMGEN_TRACEBACK'] = '' - # Disable color in spawned scripts so pexpect can parse their output - os.environ['MMGEN_DISABLE_COLOR'] = '1' os.environ['MMGEN_NO_LICENSE'] = '1' os.environ['MMGEN_MIN_URANDCHARS'] = '3' os.environ['MMGEN_BOGUS_SEND'] = '1' + os.environ['MMGEN_TEST_SUITE_PEXPECT'] = '1' def set_restore_term_at_exit(): import termios,atexit @@ -694,6 +698,8 @@ class TestSuiteRunner(object): self.ts.test_name, cmd_disp)) + os.environ['MMGEN_FORCE_COLOR'] = ('1' if self.ts.color else '') + from test.include.pexpect import MMGenPexpect return MMGenPexpect(args,no_output=no_output) diff --git a/test/test_py_d/ts_base.py b/test/test_py_d/ts_base.py index a7396ede..9fe9490b 100755 --- a/test/test_py_d/ts_base.py +++ b/test/test_py_d/ts_base.py @@ -33,6 +33,7 @@ class TestSuiteBase(object): extra_spawn_args = [] networks = () segwit_opts_ok = False + color = False def __init__(self,trunner,cfgs,spawn): from mmgen.protocol import init_proto_from_opts diff --git a/test/test_py_d/ts_input.py b/test/test_py_d/ts_input.py index 24a40e89..339f3e4b 100755 --- a/test/test_py_d/ts_input.py +++ b/test/test_py_d/ts_input.py @@ -19,6 +19,7 @@ class TestSuiteInput(TestSuiteBase): 'user input' networks = ('btc',) tmpdir_nums = [] + color = True cmd_group = ( ('get_passphrase_ui', (1,"hash preset, password and label (wallet.py)", [])), ('get_passphrase_cmdline', (1,"hash preset, password and label (wallet.py - from cmdline)", [])), @@ -185,7 +186,7 @@ class TestSuiteInput(TestSuiteBase): mne = mn_entry(fmt,entry_mode) t.expect('Entry mode: ',str(mne.entry_modes.index(entry_mode)+1)) t.expect('Using (.+) entry mode',regex=True) - mode = t.p.match.group(1).lower() + mode = strip_ansi_escapes(t.p.match.group(1)).lower() assert mode == mne.em.name.lower(), '{} != {}'.format(mode,mne.em.name.lower()) stealth_mnemonic_entry(t,mne,mn,entry_mode=entry_mode,pad_entry=pad_entry) t.expect(sample_mn[fmt]['hex']) @@ -202,7 +203,7 @@ class TestSuiteInput(TestSuiteBase): for idx,val in ((5,'x'),(18,'0'),(30,'7'),(44,'9')): mn.insert(idx,val) t = self.spawn('mmgen-walletconv',['-r10','-S','-i',fmt,'-o',out_fmt or fmt]) - t.expect('{} type: {}'.format(capfirst(wcls.wclass),wcls.mn_type)) + t.expect('{} type:.*{}'.format(capfirst(wcls.wclass),wcls.mn_type),regex=True) t.expect(wcls.choose_seedlen_prompt,'1') t.expect('(Y/n): ','y') if wcls.wclass == 'mnemonic': @@ -212,7 +213,7 @@ class TestSuiteInput(TestSuiteBase): mne = mn_entry(fmt,entry_mode) t.expect('Entry mode: ',str(mne.entry_modes.index(entry_mode)+1)) t.expect('Using (.+) entry mode',regex=True) - mode = t.p.match.group(1).lower() + mode = strip_ansi_escapes(t.p.match.group(1)).lower() assert mode == mne.em.name.lower(), '{} != {}'.format(mode,mne.em.name.lower()) stealth_mnemonic_entry(t,mne,mn,entry_mode=entry_mode) elif wcls.wclass == 'dieroll': @@ -224,7 +225,8 @@ class TestSuiteInput(TestSuiteBase): t.expect(wcls.user_entropy_prompt,'n') if not usr_rand: sid_chk = 'FE3C6545' - sid = t.expect_getend('Valid {} for Seed ID '.format(wcls.desc))[:8] + sid = t.expect_getend('Valid {} for Seed ID '.format(wcls.desc)) + sid = strip_ansi_escapes(sid.split(',')[0]) assert sid == sid_chk,'Seed ID mismatch! {} != {}'.format(sid,sid_chk) t.expect('to confirm: ','YES\n') t.read() diff --git a/test/test_py_d/ts_main.py b/test/test_py_d/ts_main.py index adb1a2e2..35e2845f 100755 --- a/test/test_py_d/ts_main.py +++ b/test/test_py_d/ts_main.py @@ -42,6 +42,7 @@ def make_brainwallet_file(fn): write_data_to_file(fn,d,'brainwallet password',quiet=True,ignore_opt_outdir=True) def verify_checksum_or_exit(checksum,chk): + chk = strip_ansi_escapes(chk) if checksum != chk: raise TestSuiteFatalException('Checksum error: {}'.format(chk)) vmsg(green('Checksums match: ') + cyan(chk)) @@ -66,6 +67,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared): networks = ('btc','btc_tn','ltc','ltc_tn','bch','bch_tn') passthru_opts = ('daemon_data_dir','rpc_port','coin','testnet') segwit_opts_ok = True + color = True cmd_group = ( ('walletgen_dfl_wallet', (15,'wallet generation (default wallet)',[[[],15]])), ('subwalletgen_dfl_wallet', (15,'subwallet generation (default wallet)',[[[pwfile],15]])), @@ -221,7 +223,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared): t.license() wcls = MMGenWallet t.passphrase(wcls.desc,self.cfgs['1']['wpasswd']) - t.expect('Generating subseed 10S') + t.expect('Generating subseed.*10S',regex=True) t.passphrase_new('new '+wcls.desc,'foo') t.usr_rand(self.usr_rand_chars) fn = t.written_to_file(capfirst(wcls.desc)) @@ -236,7 +238,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared): t = self.spawn('mmgen-subwalletgen', args) t.license() t.passphrase(icls.desc,self.cfgs['1']['wpasswd']) - t.expect('Generating subseed 3L') + t.expect('Generating subseed.*3L',regex=True) fn = t.written_to_file(capfirst(ocls.desc)) ext = get_extension(fn) assert ext == ocls.ext,'incorrect file extension: {}'.format(ext)