Browse Source

pylint (test suite) - f-strings

The MMGen Project 1 year ago
parent
commit
9a8f6216f7

+ 1 - 1
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

+ 1 - 1
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()
 

+ 1 - 1
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}')

+ 1 - 1
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]])

+ 1 - 1
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()))

+ 4 - 4
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: ')

+ 3 - 3
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
 

+ 2 - 3
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=[]):

+ 1 - 1
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:

+ 1 - 1
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:

+ 1 - 1
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

+ 1 - 1
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()