From 07d2d6dcb9ee6e5c71817af9eeea89ce5e7343a4 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 11 Oct 2023 12:58:51 +0000 Subject: [PATCH] pylint (test suite) - type comparison with isinstance() --- test/include/pexpect.py | 2 +- test/objtest.py | 8 ++++---- test/test.py | 6 +++--- test/tooltest2.py | 8 ++++---- test/unit_tests_d/ut_scrypt.py | 2 +- test/unit_tests_d/ut_tx_deserialize.py | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/include/pexpect.py b/test/include/pexpect.py index 783bf7f5..3c3a47a8 100755 --- a/test/include/pexpect.py +++ b/test/include/pexpect.py @@ -218,7 +218,7 @@ class MMGenPexpect: if cfg.debug_pexpect: debug_pexpect_msg(self.p) - if cfg.verbose and type(s) != str: + if cfg.verbose and not isinstance(s,str): msg_r(f' ==> {ret} ') if ret == -1: diff --git a/test/objtest.py b/test/objtest.py index 93477290..ad3acbd0 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -65,9 +65,9 @@ def run_test(mod,test,arg,input_data,arg1,exc_name): kwargs = {} ret_chk = arg ret_idx = None - if input_data == 'good' and type(arg) == tuple: + if input_data == 'good' and isinstance(arg,tuple): arg,ret_chk = arg - if type(arg) == dict: # pass one arg + kwargs to constructor + if isinstance(arg,dict): # pass one arg + kwargs to constructor arg_copy = arg.copy() if 'arg' in arg: args = [arg['arg']] @@ -89,7 +89,7 @@ def run_test(mod,test,arg,input_data,arg1,exc_name): del arg['ret_idx'] del arg_copy['ret_idx'] kwargs.update(arg) - elif type(arg) == tuple: + elif isinstance(arg,tuple): args = arg else: args = [arg] @@ -103,7 +103,7 @@ def run_test(mod,test,arg,input_data,arg1,exc_name): try: if not cfg.super_silent: - arg_disp = repr(arg_copy[0] if type(arg_copy) == tuple else arg_copy) + arg_disp = repr(arg_copy[0] if isinstance(arg_copy,tuple) else arg_copy) if cfg.test_suite_deterministic and isinstance(arg_copy,dict): arg_disp = re.sub(r'object at 0x[0-9a-f]+','object at [SCRUBBED]',arg_disp) msg_r((green if input_data=='good' else orange)(f'{arg_disp+":":<22}')) diff --git a/test/test.py b/test/test.py index 883dda18..547d3b39 100755 --- a/test/test.py +++ b/test/test.py @@ -293,7 +293,7 @@ def list_cmds(): data = dpdata[cmd] yield ' {:{w}} - {}'.format( cmd, - (data if type(data) == str else data[1]), + (data if isinstance(data,str) else data[1]), w = cw ) w = max(map(len,utils)) @@ -454,7 +454,7 @@ class CmdGroupMgr: if hasattr(cls,'skip_cmds') and k in cls.skip_cmds: continue sdeps = get_shared_deps(k,i) - if type(b) == str: + if isinstance(b,str): cdata.append( (k, (i,f'{b} ({j}-bit)',[[[]+sdeps,i]])) ) else: cdata.append( (k, (i,f'{b[1]} ({j}-bit)',[[b[0]+sdeps,i]])) ) @@ -954,7 +954,7 @@ class TestSuiteRunner: elif ret in ('skip','silent'): if ret == 'silent': self.cmd_total += 1 - elif type(ret) == tuple and ret[0] == 'skip_warn': + elif isinstance(ret,tuple) and ret[0] == 'skip_warn': self.skipped_warnings.append( 'Test {!r} was skipped:\n {}'.format(cmd,'\n '.join(ret[1].split('\n')))) else: diff --git a/test/tooltest2.py b/test/tooltest2.py index 3b1b56c3..57072e4a 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -44,7 +44,7 @@ skipped_tests = ['mn2hex_interactive'] NL = ('\n','\r\n')[gc.platform=='win'] def is_str(s): - return type(s) == str + return isinstance(s,str) from mmgen.key import is_wif from mmgen.addr import is_coin_addr @@ -834,7 +834,7 @@ def check_output(out,chk): if type(chk).__name__ == 'function': assert chk(outd), f'{chk.__name__}({outd}) failed!' - elif type(chk) == dict: + elif isinstance(chk,dict): for k,v in chk.items(): if k == 'boolfunc': assert v(outd), f'{v.__name__}({outd}) failed!' @@ -876,7 +876,7 @@ async def run_test(cls,gid,cmd_name): for d in data: args,out,opts,mmtype = d + tuple([None] * (4-len(d))) stdin_input = None - if args and type(args[0]) == bytes: + if args and isinstance(args[0],bytes): stdin_input = args[0] args[0] = '-' @@ -898,7 +898,7 @@ async def run_test(cls,gid,cmd_name): except: vmsg(f'Output:\n{cmd_out!r}\n') - if type(out) == tuple and type(out[0]).__name__ == 'function': + if isinstance(out,tuple) and type(out[0]).__name__ == 'function': func_out = out[0](cmd_out) assert func_out == out[1],( '{}({}) == {} failed!\nOutput: {}'.format( diff --git a/test/unit_tests_d/ut_scrypt.py b/test/unit_tests_d/ut_scrypt.py index f4ba9680..b65d856d 100755 --- a/test/unit_tests_d/ut_scrypt.py +++ b/test/unit_tests_d/ut_scrypt.py @@ -36,7 +36,7 @@ class unit_test: def test_passwords(): for pw_base,res in pws: for pw in (pw_base,pw_base.encode()): - pw_disp = "'"+pw+"'" if type(pw) == str else "b'"+pw.decode()+"'" + pw_disp = "'"+pw+"'" if isinstance(pw,str) else "b'"+pw.decode()+"'" if cfg.quiet: omsg_r('.') else: diff --git a/test/unit_tests_d/ut_tx_deserialize.py b/test/unit_tests_d/ut_tx_deserialize.py index 72931fa7..7528f282 100755 --- a/test/unit_tests_d/ut_tx_deserialize.py +++ b/test/unit_tests_d/ut_tx_deserialize.py @@ -120,7 +120,7 @@ class unit_tests: print_info(name,'Bitcoin Core test vectors') n = 1 for e in core_data: - if type(e[0]) == list: + if isinstance(e[0],list): await test_tx( tx_proto = init_proto( cfg, 'btc', need_amt=True ), tx_hex = e[1],