test.py: allow tests to override --pexpect-spawn, update tests
This commit is contained in:
parent
41474d9bf7
commit
9c1b58717c
7 changed files with 52 additions and 42 deletions
|
|
@ -1 +1 @@
|
|||
13.3.dev12
|
||||
13.3.dev13
|
||||
|
|
|
|||
|
|
@ -41,8 +41,9 @@ NL = '\n'
|
|||
|
||||
class MMGenPexpect:
|
||||
|
||||
def __init__(self,args,no_output=False,env=None):
|
||||
def __init__(self,args,no_output=False,env=None,pexpect_spawn=False):
|
||||
|
||||
self.pexpect_spawn = pexpect_spawn
|
||||
self.req_exit_val = 0
|
||||
self.skip_ok = False
|
||||
self.sent_value = None
|
||||
|
|
@ -53,7 +54,7 @@ class MMGenPexpect:
|
|||
run([args[0]] + args[1:],check=True,stdout=DEVNULL if no_output else None)
|
||||
else:
|
||||
timeout = int(opt.pexpect_timeout or 0) or (60,5)[bool(opt.debug_pexpect)]
|
||||
if opt.pexpect_spawn:
|
||||
if pexpect_spawn:
|
||||
self.p = pexpect.spawn(args[0],args[1:],encoding='utf8',timeout=timeout,env=env)
|
||||
else:
|
||||
self.p = PopenSpawn(args,encoding='utf8',timeout=timeout,env=env)
|
||||
|
|
@ -79,7 +80,7 @@ class MMGenPexpect:
|
|||
self.expect('Comment: ',add_comment+'\n')
|
||||
|
||||
def ok(self):
|
||||
if not opt.pexpect_spawn:
|
||||
if not self.pexpect_spawn:
|
||||
self.p.sendeof()
|
||||
self.p.read()
|
||||
ret = self.p.wait()
|
||||
|
|
@ -234,5 +235,5 @@ class MMGenPexpect:
|
|||
return self.p.read(n)
|
||||
|
||||
def close(self):
|
||||
if opt.pexpect_spawn:
|
||||
if self.pexpect_spawn:
|
||||
self.p.close()
|
||||
|
|
|
|||
11
test/test.py
11
test/test.py
|
|
@ -327,9 +327,6 @@ def set_environ_for_spawned_scripts():
|
|||
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
|
||||
|
||||
|
|
@ -555,7 +552,8 @@ class TestSuiteRunner(object):
|
|||
msg_only = False,
|
||||
no_msg = False,
|
||||
cmd_dir = 'cmds',
|
||||
no_exec_wrapper = False ):
|
||||
no_exec_wrapper = False,
|
||||
pexpect_spawn = None ):
|
||||
|
||||
desc = self.ts.test_name if opt.names else self.gm.dpy_data[self.ts.test_name][1]
|
||||
if extra_desc:
|
||||
|
|
@ -605,6 +603,9 @@ class TestSuiteRunner(object):
|
|||
self.ts.test_name,
|
||||
cmd_disp))
|
||||
|
||||
pexpect_spawn = pexpect_spawn if pexpect_spawn is not None else bool(opt.pexpect_spawn)
|
||||
|
||||
os.environ['MMGEN_TEST_SUITE_POPEN_SPAWN'] = '' if pexpect_spawn else '1'
|
||||
os.environ['MMGEN_FORCE_COLOR'] = '1' if self.ts.color else ''
|
||||
|
||||
env = { 'EXEC_WRAPPER_SPAWN':'1' }
|
||||
|
|
@ -614,7 +615,7 @@ class TestSuiteRunner(object):
|
|||
env.update({ 'EXEC_WRAPPER_TRACEBACK':'' }) # Python 3.9: OR the dicts
|
||||
|
||||
from test.include.pexpect import MMGenPexpect
|
||||
return MMGenPexpect( args, no_output=no_output, env=env )
|
||||
return MMGenPexpect( args, no_output=no_output, env=env, pexpect_spawn=pexpect_spawn )
|
||||
|
||||
def end_msg(self):
|
||||
t = int(time.time() - self.start_time)
|
||||
|
|
|
|||
|
|
@ -41,12 +41,13 @@ class TestSuiteCfg(TestSuiteBase):
|
|||
def __del__(self):
|
||||
os.environ['MMGEN_TEST_SUITE_CFGTEST'] = ''
|
||||
|
||||
def spawn_test(self,args=[],extra_desc=''):
|
||||
def spawn_test(self,args=[],extra_desc='',pexpect_spawn=None):
|
||||
return self.spawn(
|
||||
'test/misc/cfg.py',
|
||||
[f'--data-dir={self.path("data_dir")}'] + args,
|
||||
cmd_dir = '.',
|
||||
extra_desc = extra_desc )
|
||||
extra_desc = extra_desc,
|
||||
pexpect_spawn = pexpect_spawn )
|
||||
|
||||
def path(self,id_str):
|
||||
return {
|
||||
|
|
@ -98,7 +99,7 @@ class TestSuiteCfg(TestSuiteBase):
|
|||
e = CfgFileSampleUsr.altered_by_user_fs.format(self.path('sample'))
|
||||
return self.bad_sample(s,e)
|
||||
|
||||
def old_sample_common(self,old_set=False,args=[]):
|
||||
def old_sample_common(self,old_set=False,args=[],pexpect_spawn=None):
|
||||
s = read_from_file(self.path('sys'))
|
||||
d = s.replace('monero_','zcash_').splitlines()
|
||||
a1 = ['','# Uncomment to make foo true:','# foo true']
|
||||
|
|
@ -107,7 +108,7 @@ class TestSuiteCfg(TestSuiteBase):
|
|||
chk = CfgFileSample.cls_make_metadata(d)
|
||||
write_to_file(self.path('sample'),'\n'.join(d+chk) + '\n')
|
||||
|
||||
t = self.spawn_test(args=args)
|
||||
t = self.spawn_test(args=args,pexpect_spawn=pexpect_spawn)
|
||||
|
||||
t.expect('options have changed')
|
||||
for s in ('have been added','monero_','have been removed','zcash_','foo','bar'):
|
||||
|
|
@ -124,7 +125,7 @@ class TestSuiteCfg(TestSuiteBase):
|
|||
for s in ('CHANGES','Removed','# zcash_','# foo','# bar','Added','# monero_'):
|
||||
t.expect(s)
|
||||
|
||||
if opt.pexpect_spawn: # view and exit pager
|
||||
if t.pexpect_spawn: # view and exit pager
|
||||
if opt.exact_output:
|
||||
time.sleep(1)
|
||||
t.send('q')
|
||||
|
|
@ -152,7 +153,7 @@ class TestSuiteCfg(TestSuiteBase):
|
|||
def old_sample_bad_var(self):
|
||||
d = ['foo true','bar false']
|
||||
write_to_file(self.path('usr'),'\n'.join(d) + '\n')
|
||||
return self.old_sample_common(old_set=True)
|
||||
return self.old_sample_common(old_set=True,pexpect_spawn=True)
|
||||
|
||||
def coin_specific_vars(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -367,8 +367,6 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
|
|||
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',need_amt=True)
|
||||
|
||||
|
|
@ -1259,17 +1257,17 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
|
|||
def token_twview3(self):
|
||||
return self.twview(args=['--token=mm1'],tool_args=['wide=1','sort=age'])
|
||||
|
||||
def edit_label(self,out_num,args=[],action='l',label_text=None,changed=False):
|
||||
t = self.spawn('mmgen-txcreate', self.eth_args + args + ['-B','-i'])
|
||||
def edit_label(self,out_num,args=[],action='l',label_text=None,changed=False,pexpect_spawn=None):
|
||||
t = self.spawn('mmgen-txcreate', self.eth_args + args + ['-B','-i'],pexpect_spawn=pexpect_spawn)
|
||||
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 == self.erase_input else ((),())
|
||||
p4,r4 = (('(y/N): ',),('y',)) if label_text == Ctrl_U else ((),())
|
||||
for p,r in zip((p1,p1,p2,p3)+p4,('M',action,out_num+'\n',r3)+r4):
|
||||
t.expect(p,r)
|
||||
m = (
|
||||
'Label to account #{} edited' if changed else
|
||||
'Account #{} removed' if action == 'D' else
|
||||
'Label added to account #{}' if label_text and label_text != self.erase_input else
|
||||
'Label added to account #{}' if label_text and label_text != Ctrl_U else
|
||||
'Label removed from account #{}' )
|
||||
t.expect(m.format(out_num))
|
||||
for p,r in zip((p1,p1),('M','q')):
|
||||
|
|
@ -1280,12 +1278,11 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
|
|||
def edit_label1(self):
|
||||
return self.edit_label(out_num=del_addrs[0],label_text=tw_label_zh[:3])
|
||||
def edit_label2(self):
|
||||
idx = 3 if opt.pexpect_spawn else 0
|
||||
return self.edit_label(out_num=del_addrs[0],label_text=tw_label_zh[idx:],changed=True)
|
||||
return self.edit_label(out_num=del_addrs[0],label_text=tw_label_zh[3:],changed=True,pexpect_spawn=True)
|
||||
def edit_label3(self):
|
||||
return self.edit_label(out_num=del_addrs[1],label_text=tw_label_lat_cyr_gr)
|
||||
def edit_label4(self):
|
||||
return self.edit_label(out_num=del_addrs[0],label_text=self.erase_input)
|
||||
return self.edit_label(out_num=del_addrs[0],label_text=Ctrl_U,pexpect_spawn=True)
|
||||
|
||||
def token_edit_label1(self):
|
||||
return self.edit_label(out_num='1',label_text='Token label #1',args=['--token=mm1'])
|
||||
|
|
|
|||
|
|
@ -158,7 +158,8 @@ class TestSuiteOutput(TestSuiteBase):
|
|||
('output_ru', (1,"Russian text", [])),
|
||||
('output_zh', (1,"Chinese text", [])),
|
||||
('output_jp', (1,"Japanese text", [])),
|
||||
('oneshot_warning', (1,"Oneshot warnings", []))
|
||||
('oneshot_warning', (1,"Oneshot warnings", [])),
|
||||
('oneshot_warning_term', (1,"Oneshot warnings (pexpect_spawn)", []))
|
||||
)
|
||||
color = True
|
||||
|
||||
|
|
@ -170,9 +171,9 @@ class TestSuiteOutput(TestSuiteBase):
|
|||
def output_zh(self): return self.screen_output('zh')
|
||||
def output_jp(self): return self.screen_output('jp')
|
||||
|
||||
def oneshot_warning(self):
|
||||
nl = '\r\n' if g.platform == 'win' or opt.pexpect_spawn else '\n'
|
||||
t = self.spawn('test/misc/oneshot_warning.py',cmd_dir='.')
|
||||
def oneshot_warning(self,pexpect_spawn=None):
|
||||
t = self.spawn('test/misc/oneshot_warning.py',cmd_dir='.',pexpect_spawn=pexpect_spawn)
|
||||
nl = '\r\n' if g.platform == 'win' or t.pexpect_spawn else '\n'
|
||||
for s in (
|
||||
f'pw{nl}wg1',
|
||||
'foo is experimental',
|
||||
|
|
@ -195,6 +196,9 @@ class TestSuiteOutput(TestSuiteBase):
|
|||
t.expect(s)
|
||||
return t
|
||||
|
||||
def oneshot_warning_term(self):
|
||||
return self.oneshot_warning(pexpect_spawn=True)
|
||||
|
||||
class TestSuiteRefTX(TestSuiteMain,TestSuiteBase):
|
||||
'create a reference transaction file (administrative command)'
|
||||
segwit_opts_ok = False
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
ts_regtest.py: Regtest tests for the test.py test suite
|
||||
"""
|
||||
|
||||
import os,json
|
||||
import os,json,time
|
||||
from decimal import Decimal
|
||||
from mmgen.globalvars import g
|
||||
from mmgen.opts import opt
|
||||
|
|
@ -343,6 +343,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
|
|||
('alice_twview_date', 'twview (age_fmt=date)'),
|
||||
('alice_twview_date_time', 'twview (age_fmt=date_time)'),
|
||||
('alice_txcreate_info', 'txcreate -i'),
|
||||
('alice_txcreate_info_term', 'txcreate -i (pexpect_spawn)'),
|
||||
),
|
||||
}
|
||||
|
||||
|
|
@ -1242,27 +1243,32 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
|
|||
args = ['age_fmt=date_time'],
|
||||
expect = (rtAmts[0],pat_date_time) )
|
||||
|
||||
def alice_txcreate_info(self,args=[]):
|
||||
t = self.spawn('mmgen-txcreate',['--alice','-Bi'])
|
||||
def alice_txcreate_info(self,pexpect_spawn=None):
|
||||
t = self.spawn('mmgen-txcreate',['--alice','-Bi'],pexpect_spawn=pexpect_spawn)
|
||||
pats = (
|
||||
( '\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'),
|
||||
( '\d+', 'w'),
|
||||
( '\d+', 'D'),
|
||||
( '\d+', 'D'),
|
||||
( '\d+', 'D'),
|
||||
( pat_date, 'q'),
|
||||
)
|
||||
for d,s in pats:
|
||||
t.expect(
|
||||
r'\D{}\D.*\b{}\b'.format( rtAmts[0], d ),
|
||||
s,
|
||||
regex=True )
|
||||
if t.pexpect_spawn and s == 'w':
|
||||
t.expect(r'Total.*',regex=True)
|
||||
if opt.exact_output:
|
||||
time.sleep(1)
|
||||
t.send('q')
|
||||
time.sleep(0.2)
|
||||
t.send('e')
|
||||
return t
|
||||
|
||||
def alice_txcreate_info_term(self):
|
||||
return self.alice_txcreate_info(pexpect_spawn=True)
|
||||
|
||||
def bob_msgcreate(self):
|
||||
sid1 = self._user_sid('bob')
|
||||
sid2 = self._get_user_subsid('bob','29L')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue