From 2660a3591bdf4e38dcd2f0073e5e478aca7dd504 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 7 Oct 2021 13:12:10 +0000 Subject: [PATCH] test.py: fixes for --pexpect-spawn --- test/test.py | 3 +++ test/test_py_d/common.py | 2 ++ test/test_py_d/ts_cfg.py | 2 ++ test/test_py_d/ts_ethdev.py | 9 ++++++--- test/test_py_d/ts_misc.py | 2 +- test/test_py_d/ts_regtest.py | 15 ++++++++++----- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/test/test.py b/test/test.py index 32f1f8e5..a0e574f4 100755 --- a/test/test.py +++ b/test/test.py @@ -657,6 +657,9 @@ class TestSuiteRunner(object): self.coverdir,self.accfile = init_coverage() omsg(f'INFO → Writing coverage files to {self.coverdir!r}') + if opt.pexpect_spawn: + omsg(f'INFO → Using pexpect.spawn() for real terminal emulation') + def spawn_wrapper(self,cmd, args = [], extra_desc = '', diff --git a/test/test_py_d/common.py b/test/test_py_d/common.py index e3e0d702..42872f36 100755 --- a/test/test_py_d/common.py +++ b/test/test_py_d/common.py @@ -67,6 +67,8 @@ ref_enc_fn = 'sample-text.mmenc' tool_enc_passwd = "Scrypt it, don't hash it!" chksum_pat = r'\b[A-F0-9]{4} [A-F0-9]{4} [A-F0-9]{4} [A-F0-9]{4}\b' +Ctrl_U = '\x15' + def ok_msg(): if opt.profile: return sys.stderr.write(green('\nOK\n') if opt.exact_output or opt.verbose else ' OK\n') diff --git a/test/test_py_d/ts_cfg.py b/test/test_py_d/ts_cfg.py index 2f5917d7..f86b890e 100755 --- a/test/test_py_d/ts_cfg.py +++ b/test/test_py_d/ts_cfg.py @@ -99,6 +99,8 @@ class TestSuiteCfg(TestSuiteBase): return self.bad_sample(s,e) def old_sample_common(self,old_set=False,args=[]): + if opt.pexpect_spawn: # FIXME: get_char() is blocking + return 'skip' s = read_from_file(self.path('sys')) d = s.replace('monero_','zcash_').splitlines() a1 = ['','# Uncomment to make foo true:','# foo true'] diff --git a/test/test_py_d/ts_ethdev.py b/test/test_py_d/ts_ethdev.py index 3ff9d95f..3c5ad0cb 100755 --- a/test/test_py_d/ts_ethdev.py +++ b/test/test_py_d/ts_ethdev.py @@ -320,6 +320,9 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared): TestSuiteBase.__init__(self,trunner,cfgs,spawn) if trunner == None: return + + self.erase_input = Ctrl_U if opt.pexpect_spawn else '' + from mmgen.protocol import init_proto self.proto = init_proto(g.coin,network='regtest') from mmgen.daemon import CoinDaemon @@ -1121,11 +1124,11 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared): t = self.spawn('mmgen-txcreate', self.eth_args + args + ['-B','-i']) p1,p2 = ('efresh balance:\b','return to main menu): ') p3,r3 = (p2,label_text+'\n') if label_text is not None else ('(y/N): ','y') - p4,r4 = (('(y/N): ',),('y',)) if label_text == '' else ((),()) + p4,r4 = (('(y/N): ',),('y',)) if label_text == self.erase_input else ((),()) for p,r in zip((p1,p1,p2,p3)+p4,('M',action,out_num+'\n',r3)+r4): t.expect(p,r) m = ( 'Account #{} removed' if action == 'D' else - 'Label added to account #{}' if label_text else + 'Label added to account #{}' if label_text and label_text != self.erase_input else 'Label removed from account #{}' ) t.expect(m.format(out_num)) for p,r in zip((p1,p1),('M','q')): @@ -1139,7 +1142,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared): def edit_label2(self): return self.edit_label(out_num=del_addrs[1],label_text=tw_label_lat_cyr_gr) def edit_label3(self): - return self.edit_label(out_num=del_addrs[0],label_text='') + return self.edit_label(out_num=del_addrs[0],label_text=self.erase_input) def token_edit_label1(self): return self.edit_label(out_num='1',label_text='Token label #1',args=['--token=mm1']) diff --git a/test/test_py_d/ts_misc.py b/test/test_py_d/ts_misc.py index 48976538..6f520cba 100755 --- a/test/test_py_d/ts_misc.py +++ b/test/test_py_d/ts_misc.py @@ -122,7 +122,7 @@ class TestSuiteOutput(TestSuiteBase): def output_jp(self): return self.screen_output('jp') def oneshot_warning(self): - nl = '\r\n' if g.platform == 'win' else '\n' + nl = '\r\n' if g.platform == 'win' or opt.pexpect_spawn else '\n' t = self.spawn('test/misc/oneshot_warning.py',cmd_dir='.') for s in ( f'pw{nl}wg1', diff --git a/test/test_py_d/ts_regtest.py b/test/test_py_d/ts_regtest.py index e783b226..1404b3ce 100755 --- a/test/test_py_d/ts_regtest.py +++ b/test/test_py_d/ts_regtest.py @@ -1020,11 +1020,16 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): def alice_txcreate_info(self,args=[]): t = self.spawn('mmgen-txcreate',['--alice','-Bi']) pats = ( - ( '\d+', 'D'), - ( '\d+', 'D'), - ( '\d+', 'D'), - ( pat_date, 'w'), - ( '\d+\s+\d+\s+'+pat_date_time,'q'), + ( '\d+', 'D'), + ( '\d+', 'D'), + ( '\d+', 'D'), + ( pat_date, 'q'), + ) if opt.pexpect_spawn else ( + ( '\d+', 'D'), + ( '\d+', 'D'), + ( '\d+', 'D'), + ( pat_date, 'w'), + ( '\d+\s+\d+\s+'+pat_date_time,'q'), ) for d,s in pats: t.expect(