test.include.pexpect.read(): add strip_color param

This commit is contained in:
The MMGen Project 2023-04-30 10:01:24 +00:00
commit 2f1271f570
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 8 additions and 11 deletions

View file

@ -170,14 +170,13 @@ class MMGenPexpect:
return self.p.kill(signal)
def match_expect_list(self,expect_list,greedy=False):
res = strip_ansi_escapes(self.read()).replace('\r','')
allrep = '.*' if greedy else '.*?'
expect = (
r'(\b|\s)' +
fr'\s{allrep}\s'.join(s.replace(r'.',r'\.').replace(' ',r'\s+') for s in expect_list) +
r'(\b|\s)' )
import re
m = re.search(expect,res,re.DOTALL)
m = re.search( expect, self.read(strip_color=True), re.DOTALL )
assert m, f'No match found for regular expression {expect!r}'
return m
@ -230,8 +229,8 @@ class MMGenPexpect:
msg(f'{ls}SEND {es}{yt}')
return ret
def read(self,n=-1):
return self.p.read(n)
def read(self,n=-1,strip_color=False):
return strip_ansi_escapes(self.p.read(n)).replace('\r','') if strip_color else self.p.read(n)
def close(self):
if self.pexpect_spawn:

View file

@ -813,7 +813,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
def bal(self,n):
t = self.spawn('mmgen-tool', self.eth_args + ['twview','wide=1'])
text = strip_ansi_escapes(t.read())
text = t.read(strip_color=True)
for b in bals[n]:
addr,amt,adj = b if len(b) == 3 else b + (False,)
if adj and self.proto.coin == 'ETC':
@ -826,7 +826,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
def token_bal(self,n=None):
t = self.spawn('mmgen-tool', self.eth_args + ['--token=mm1','twview','wide=1'])
text = strip_ansi_escapes(t.read())
text = t.read(strip_color=True)
for b in token_bals[n]:
addr,_amt1,_amt2,adj = b if len(b) == 4 else b + (False,)
if adj and self.proto.coin == 'ETC':

View file

@ -51,7 +51,7 @@ class TestSuiteMisc(TestSuiteBase):
def xmrwallet_txview(self,op='txview'):
files = get_file_with_ext('test/ref/monero','tx',no_dot=True,delete=False,return_list=True)
t = self.spawn( f'mmgen-xmrwallet', [op] + files )
res = strip_ansi_escapes(t.read()).replace('\r','')
res = t.read(strip_color=True)
if op == 'txview':
for s in (
'Amount: 0.74 XMR',

View file

@ -758,8 +758,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
def user_txhist(self,user,args,expect):
t = self.spawn('mmgen-tool',['--'+user,'txhist'] + args)
res = strip_ansi_escapes(t.read()).replace('\r','')
m = re.search(expect,res,re.DOTALL)
m = re.search( expect, t.read(strip_color=True), re.DOTALL )
assert m, f'Expected: {expect}'
return t

View file

@ -367,8 +367,7 @@ class TestSuiteXMRWallet(TestSuiteBase):
(['--no-start-wallet-daemon'] if cfg in ('continue','stop') else []) +
(['--no-stop-wallet-daemon'] if cfg in ('start','continue') else []) +
['new', (kafile or data.kafile), spec] )
res = strip_ansi_escapes(t.read()).replace('\r','')
m = re.search(expect,res,re.DOTALL)
m = re.search( expect, t.read(strip_color=True), re.DOTALL )
assert m, f'no match found for {expect!r}'
return t