From 9a8f6216f7e60a33dae3763e2ab77b04745970ae Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 11 Oct 2023 12:58:52 +0000 Subject: [PATCH] pylint (test suite) - f-strings --- examples/coin-daemon-info.py | 2 +- scripts/exec_wrapper.py | 2 +- test/misc/input_func.py | 2 +- test/misc/utf8_output.py | 2 +- test/test.py | 2 +- test/test_py_d/ts_input.py | 8 ++++---- test/test_py_d/ts_regtest.py | 6 +++--- test/tooltest.py | 5 ++--- test/tooltest2.py | 2 +- test/unit_tests.py | 2 +- test/unit_tests_d/ut_addrlist.py | 2 +- test/unit_tests_d/ut_testdep.py | 2 +- 12 files changed, 18 insertions(+), 19 deletions(-) diff --git a/examples/coin-daemon-info.py b/examples/coin-daemon-info.py index c3207954..aa9b5153 100755 --- a/examples/coin-daemon-info.py +++ b/examples/coin-daemon-info.py @@ -74,7 +74,7 @@ async def main(coins): 'Up', rpc.port, rpc.chain, - '{:<8} [{}]'.format(rpc.blockcount, make_timestr(rpc.cur_date)), + f'{rpc.blockcount:<8} [{make_timestr(rpc.cur_date)}]', rpc.daemon.coind_name, rpc.daemon_version_str, rpc.daemon.datadir diff --git a/scripts/exec_wrapper.py b/scripts/exec_wrapper.py index a3755000..f0e0bd7e 100755 --- a/scripts/exec_wrapper.py +++ b/scripts/exec_wrapper.py @@ -43,7 +43,7 @@ def exec_wrapper_write_traceback(e,exit_val): exc_line = ( repr(e) if type(e).__name__ in ('MMGenError','MMGenSystemExit') else - '{}: {}'.format( type(e).__name__, e )) + f'{type(e).__name__}: {e}') c = exec_wrapper_get_colors() diff --git a/test/misc/input_func.py b/test/misc/input_func.py index cc0b0393..2a78e2a2 100755 --- a/test/misc/input_func.py +++ b/test/misc/input_func.py @@ -42,4 +42,4 @@ elif cmd in ('get_char','line_input'): args = ', '.join(f'{k}={v!r}' for k,v in func_args.items()) )) ret = locals()[cmd](**func_args) - msg(' ==> {!r}'.format(ret)) + msg(f' ==> {ret!r}') diff --git a/test/misc/utf8_output.py b/test/misc/utf8_output.py index aa09c6a5..80cd108c 100755 --- a/test/misc/utf8_output.py +++ b/test/misc/utf8_output.py @@ -11,6 +11,6 @@ import sys from mmgen.util import msg,die if len(sys.argv) != 2 or not sys.argv[1] in text: - die(2,'argument must be one of {}'.format(list(text.keys()))) + die(2,f'argument must be one of {list(text.keys())}') msg(text[sys.argv[1]]) diff --git a/test/test.py b/test/test.py index 7f7ac829..9b6c4e28 100755 --- a/test/test.py +++ b/test/test.py @@ -301,7 +301,7 @@ def list_cmds(): yield '\n'+green('AVAILABLE UTILITIES:') for cmd in sorted(utils): - yield ' {:{w}} - {}'.format( cmd, utils[cmd], w=w ) + yield f' {cmd:{w}} - {utils[cmd]}' from mmgen.ui import do_pager do_pager('\n'.join(gen_output())) diff --git a/test/test_py_d/ts_input.py b/test/test_py_d/ts_input.py index dc023098..b79f96a5 100755 --- a/test/test_py_d/ts_input.py +++ b/test/test_py_d/ts_input.py @@ -247,9 +247,9 @@ class TestSuiteInput(TestSuiteBase): cmd_dir='.', pexpect_spawn=term ) imsg('Parameters:') - imsg(' pexpect_spawn: {}'.format(term)) - imsg(' sending: {!r}'.format(text)) - imsg(' expecting: {!r}'.format(expect)) + imsg(f' pexpect_spawn: {term}') + imsg(f' sending: {text!r}') + imsg(f' expecting: {expect!r}') imsg('\nFunction args:') for k,v in func_args.items(): imsg(' {:14} {!r}'.format(k+':',v)) @@ -336,7 +336,7 @@ class TestSuiteInput(TestSuiteBase): if term and gc.platform == 'win': return ('skip_warn','pexpect_spawn not supported on Windows platform') t = self.spawn( 'test/misc/input_func.py', opts + ['passphrase'], cmd_dir='.', pexpect_spawn=term ) - imsg('Terminal: {}'.format(term)) + imsg(f'Terminal: {term}') pw = 'abc-α' t.expect(prompt,pw+'\n') ret = t.expect_getend('Entered: ') diff --git a/test/test_py_d/ts_regtest.py b/test/test_py_d/ts_regtest.py index ff59ea74..ea0a3677 100755 --- a/test/test_py_d/ts_regtest.py +++ b/test/test_py_d/ts_regtest.py @@ -633,7 +633,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): skip_passphrase = skip_passphrase ) def fund_bob_deterministic(self): - return self.fund_wallet_deterministic( 'bob', f'{self._user_sid("bob")}:C:1', '1-11' ) + return self.fund_wallet_deterministic( f'{self._user_sid("bob")}:C:1', '1-11' ) def fund_alice_deterministic(self): sid = self._user_sid('alice') @@ -1240,10 +1240,10 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): t.expect(p,s,regex=True) if npruned: - t.expect('Pruned {} addresses'.format(npruned)) + t.expect(f'Pruned {npruned} addresses') taddr = 35 if self.proto.cap('segwit') else 25 - t.expect('Exporting {} addresses'.format(taddr-npruned)) + t.expect(f'Exporting {taddr-npruned} addresses') fn = t.written_to_file('JSON data') return t diff --git a/test/tooltest.py b/test/tooltest.py index 1cd09e45..691cc96b 100755 --- a/test/tooltest.py +++ b/test/tooltest.py @@ -218,8 +218,7 @@ def is_coin_addr_loc(s): msg_w = 35 def test_msg(m): - m2 = f'Testing {m}' - msg_r(green(m2+'\n') if cfg.verbose else '{:{w}}'.format( m2, w=msg_w+8 )) + msg_r(green(f'Testing {m}\n') if cfg.verbose else '{:{w}}'.format(f'Testing {m}', w=msg_w+8)) compressed = cfg.type or ('','compressed')['C' in proto.mmtypes] segwit = ('','segwit')['S' in proto.mmtypes] @@ -280,7 +279,7 @@ class MMGenToolTestUtils: if cmp_equal(ret,idata): ok() else: - die(4, "Error: values don't match:\nIn: {!r}\nOut: {!r}".format(idata,ret)) + die(4, f"Error: values don't match:\nIn: {idata!r}\nOut: {ret!r}") return ret def run_cmd_nochk(self,name,f1,kwargs='',add_opts=[]): diff --git a/test/tooltest2.py b/test/tooltest2.py index 3f00bd0a..a0de6935 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -969,7 +969,7 @@ if cfg.list_tests: Msg('Available tests:') for modname,cmdlist in main_tool.mods.items(): cls = getattr(importlib.import_module(f'mmgen.tool.{modname}'),'tool_cmd') - Msg(' {:6} - {}'.format( modname, docstring_head(cls) )) + Msg(f' {modname:6} - {docstring_head(cls)}') sys.exit(0) if cfg.list_tested_cmds: diff --git a/test/unit_tests.py b/test/unit_tests.py index e9b76ce8..2fee6661 100755 --- a/test/unit_tests.py +++ b/test/unit_tests.py @@ -127,7 +127,7 @@ class UnitTestHelpers: except Exception as e: exc = type(e).__name__ emsg = e.args[0] - cfg._util.vmsg(' {:{w}} [{}]'.format( exc, emsg, w=exc_w )) + cfg._util.vmsg(f' {exc:{exc_w}} [{emsg}]') assert exc == exc_chk, m_exc.format(exc,exc_chk) assert re.search(emsg_chk,emsg), m_err.format(emsg,emsg_chk) else: diff --git a/test/unit_tests_d/ut_addrlist.py b/test/unit_tests_d/ut_addrlist.py index 4ac4b42f..d977bdbb 100755 --- a/test/unit_tests_d/ut_addrlist.py +++ b/test/unit_tests_d/ut_addrlist.py @@ -84,7 +84,7 @@ class unit_tests: ): l = AddrIdxList(i) if cfg.verbose: - msg('list: {}\nin: {}\nout: {}\n'.format(list(l),i,o)) + msg(f'list: {list(l)}\nin: {i}\nout: {o}\n') assert l.id_str == o, f'{l.id_str} != {o}' return True diff --git a/test/unit_tests_d/ut_testdep.py b/test/unit_tests_d/ut_testdep.py index 23c3aa2a..bb3ab7ff 100755 --- a/test/unit_tests_d/ut_testdep.py +++ b/test/unit_tests_d/ut_testdep.py @@ -54,7 +54,7 @@ class unit_tests: if gc.platform == 'linux' and os.uname().machine != 'x86_64': distro = [l for l in open('/etc/os-release').read().split('\n') if l.startswith('ID=')][0][3:] if distro != 'archarm': - ut.skip_msg('distro {!r} on architecture {!r}'.format( distro, os.uname().machine )) + ut.skip_msg(f'distro {distro!r} on architecture {os.uname().machine!r}') return True from test.include.common import get_ethkey get_ethkey()