From 2f1271f57055d99bd335f5ea25b4d48a7109221f Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 30 Apr 2023 10:01:24 +0000 Subject: [PATCH] test.include.pexpect.read(): add `strip_color` param --- test/include/pexpect.py | 7 +++---- test/test_py_d/ts_ethdev.py | 4 ++-- test/test_py_d/ts_misc.py | 2 +- test/test_py_d/ts_regtest.py | 3 +-- test/test_py_d/ts_xmrwallet.py | 3 +-- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/test/include/pexpect.py b/test/include/pexpect.py index 110e8742..3a34b4e7 100755 --- a/test/include/pexpect.py +++ b/test/include/pexpect.py @@ -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: diff --git a/test/test_py_d/ts_ethdev.py b/test/test_py_d/ts_ethdev.py index 6ebb21c6..aff2cc93 100755 --- a/test/test_py_d/ts_ethdev.py +++ b/test/test_py_d/ts_ethdev.py @@ -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': diff --git a/test/test_py_d/ts_misc.py b/test/test_py_d/ts_misc.py index 21115b8e..09c37545 100755 --- a/test/test_py_d/ts_misc.py +++ b/test/test_py_d/ts_misc.py @@ -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', diff --git a/test/test_py_d/ts_regtest.py b/test/test_py_d/ts_regtest.py index 1e909f85..4c1eaead 100755 --- a/test/test_py_d/ts_regtest.py +++ b/test/test_py_d/ts_regtest.py @@ -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 diff --git a/test/test_py_d/ts_xmrwallet.py b/test/test_py_d/ts_xmrwallet.py index 9ea3753d..5549025e 100755 --- a/test/test_py_d/ts_xmrwallet.py +++ b/test/test_py_d/ts_xmrwallet.py @@ -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