From 033822f5652b9466579d2bf2750acdc2079f7b1f 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) - use "is" for bool,None,type equality --- test/colortest.py | 4 ++-- test/gentest.py | 4 ++-- test/include/pexpect.py | 2 +- test/objattrtest.py | 6 +++--- test/objtest.py | 4 ++-- test/test.py | 4 ++-- test/test_py_d/ts_autosign.py | 4 ++-- test/test_py_d/ts_ethdev.py | 2 +- test/test_py_d/ts_main.py | 2 +- test/test_py_d/ts_ref.py | 2 +- test/test_py_d/ts_xmr_autosign.py | 2 +- test/test_py_d/ts_xmrwallet.py | 2 +- test/tooltest.py | 2 +- test/tooltest2.py | 2 +- test/unit_tests_d/ut_addrparse.py | 2 +- test/unit_tests_d/ut_baseconv.py | 4 ++-- test/unit_tests_d/ut_lockable.py | 10 +++++----- test/unit_tests_d/ut_mn_entry.py | 2 +- test/unit_tests_d/ut_obj.py | 2 +- test/unit_tests_d/ut_subseed.py | 2 +- 20 files changed, 32 insertions(+), 32 deletions(-) diff --git a/test/colortest.py b/test/colortest.py index 5585b482..87265d4a 100755 --- a/test/colortest.py +++ b/test/colortest.py @@ -20,7 +20,7 @@ def test_color(): ymsg("Terminal display:") # init_color() not called yet, so no yellow here for desc,nc in (('pre-init',None),('auto','auto'),('8-color',8),('256-color',256),('disabled',0)): - if nc != None: + if nc is not None: init_color(num_colors=nc) msg('{:9}: {}'.format( desc, @@ -31,7 +31,7 @@ def test_color(): for t,c in (('rxvt',8),('xterm',8),('rxvt-unicode',88),('screen-256color',256),('xterm-256color',256)): ret = get_terminfo_colors(t) - if ret == None: + if ret is None: ymsg(f'Warning: unable to get info for terminal {t!r}') continue msg(f'{t}: {orange(str(ret))}') diff --git a/test/gentest.py b/test/gentest.py index e9238541..706721e7 100755 --- a/test/gentest.py +++ b/test/gentest.py @@ -262,7 +262,7 @@ def find_or_check_tool(proto,addr_type,toolname): toolname = toolname if toolname != 'ext' else None ) if tool and toolname in ext_progs and toolname != tool: sys.exit(3) - if tool == None: + if tool is None: return None return tool @@ -384,7 +384,7 @@ def ab_test(proto,scfg): tool = None else: toolname = find_or_check_tool( proto, addr_type, scfg.tool ) - if toolname == None: + if toolname is None: ymsg(f'Warning: skipping tool {scfg.tool!r} for {proto.coin} {addr_type.name}') return tool = init_tool( proto, addr_type, toolname ) diff --git a/test/include/pexpect.py b/test/include/pexpect.py index 3c3a47a8..744a6de9 100755 --- a/test/include/pexpect.py +++ b/test/include/pexpect.py @@ -212,7 +212,7 @@ class MMGenPexpect: raise m1 = f'\nERROR. Expect {s!r} timed out. Exiting\n' m2 = f'before: [{self.p.before}]\n' - m3 = f'sent value: [{self.sent_value}]' if self.sent_value != None else '' + m3 = f'sent value: [{self.sent_value}]' if self.sent_value is not None else '' raise pexpect.TIMEOUT(m1+m2+m3) if cfg.debug_pexpect: diff --git a/test/objattrtest.py b/test/objattrtest.py index 91487f4e..dfc346d5 100755 --- a/test/objattrtest.py +++ b/test/objattrtest.py @@ -95,7 +95,7 @@ def test_attr_perm(obj,attrname,perm_name,perm_value,dobj,attrval_type): except: raise SampleObjError(f'unable to find sample object of type {attrval_type.__name__!r}') # ListItemAttr allows setting an attribute if its value is None - if type(dobj) == ListItemAttr and getattr(obj,attrname) == None: + if type(dobj) is ListItemAttr and getattr(obj,attrname) is None: setattr(obj,attrname,so) setattr(obj,attrname,so) elif perm_name == 'delete_ok': @@ -103,11 +103,11 @@ def test_attr_perm(obj,attrname,perm_name,perm_value,dobj,attrval_type): except SampleObjError as e: die(4,f'Test script error ({e})') except Exception as e: - if perm_value == True: + if perm_value is True: fs = '{!r}: unable to {} attribute {!r}, though {}ing is allowed ({})' die(4,fs.format(type(obj).__name__,pname,attrname,pstem,e)) else: - if perm_value == False: + if perm_value is False: fs = '{!r}: attribute {!r} is {n}able, though {n}ing is forbidden' die(4,fs.format(type(obj).__name__,attrname,n=pstem)) diff --git a/test/objtest.py b/test/objtest.py index ad3acbd0..5c10b86f 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -124,7 +124,7 @@ def run_test(mod,test,arg,input_data,arg1,exc_name): if cfg.getobj: if input_data == 'bad': - assert ret == False, 'non-False return on bad input data' + assert ret is False, 'non-False return on bad input data' else: if (cfg.silent and input_data=='bad' and ret!=bad_ret) or (not cfg.silent and input_data=='bad'): raise UserWarning(f"Non-'None' return value {ret!r} with bad input data") @@ -187,7 +187,7 @@ def do_loop(): arg1 = test_data[test].get('arg1') if utests and test not in utests: continue - nl = ('\n','')[bool(cfg.super_silent) or clr == None] + nl = ('\n','')[bool(cfg.super_silent) or clr is None] clr = (blue,nocolor)[bool(cfg.super_silent)] if cfg.getobj and arg1 is None: diff --git a/test/test.py b/test/test.py index 547d3b39..7f7ac829 100755 --- a/test/test.py +++ b/test/test.py @@ -417,7 +417,7 @@ class CmdGroupMgr: def load_mod(self,gname,modname=None): clsname,kwargs = self.cmd_groups[gname] - if modname == None and 'modname' in kwargs: + if modname is None and 'modname' in kwargs: modname = kwargs['modname'] import importlib modpath = f'test.test_py_d.ts_{modname or gname}' @@ -881,7 +881,7 @@ class TestSuiteRunner: do_between() else: # If prog produces multiple files: - if cmd not in self.rebuild_list or rerun == True: + if cmd not in self.rebuild_list or rerun is True: self.rebuild_list[cmd] = (rerun,fns[0] if fns else '') # FIX return rerun diff --git a/test/test_py_d/ts_autosign.py b/test/test_py_d/ts_autosign.py index ded966b8..043a8333 100755 --- a/test/test_py_d/ts_autosign.py +++ b/test/test_py_d/ts_autosign.py @@ -101,7 +101,7 @@ class TestSuiteAutosignBase(TestSuiteBase): super().__init__(trunner,cfgs,spawn) - if trunner == None: + if trunner is None: return self.network_ids = [c+'_tn' for c in self.daemon_coins] + self.daemon_coins @@ -162,7 +162,7 @@ class TestSuiteAutosignBase(TestSuiteBase): self.bad_msg_count = 0 def __del__(self): - if gc.platform == 'win' or self.tr == None: + if gc.platform == 'win' or self.tr is None: return if self.simulate or not self.live: LEDControl.delete_dummy_control_files() diff --git a/test/test_py_d/ts_ethdev.py b/test/test_py_d/ts_ethdev.py index 5fe66f73..b2f7b8a6 100755 --- a/test/test_py_d/ts_ethdev.py +++ b/test/test_py_d/ts_ethdev.py @@ -385,7 +385,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared): def __init__(self,trunner,cfgs,spawn): TestSuiteBase.__init__(self,trunner,cfgs,spawn) - if trunner == None: + if trunner is None: return from mmgen.protocol import init_proto diff --git a/test/test_py_d/ts_main.py b/test/test_py_d/ts_main.py index 16098fbf..8ffbd489 100755 --- a/test/test_py_d/ts_main.py +++ b/test/test_py_d/ts_main.py @@ -307,7 +307,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared): def __init__(self,trunner,cfgs,spawn): TestSuiteBase.__init__(self,trunner,cfgs,spawn) - if trunner == None or self.proto.coin.lower() not in self.networks: + if trunner is None or self.proto.coin.lower() not in self.networks: return self.rpc = async_run(rpc_init(cfg,self.proto)) self.lbl_id = ('account','label')['label_api' in self.rpc.caps] diff --git a/test/test_py_d/ts_ref.py b/test/test_py_d/ts_ref.py index 8e59df8f..69501f2f 100755 --- a/test/test_py_d/ts_ref.py +++ b/test/test_py_d/ts_ref.py @@ -240,7 +240,7 @@ class TestSuiteRef(TestSuiteBase,TestSuiteShared): af_key = f'ref_{ftype}file' + ('_' + id_key if id_key else '') af_fn = TestSuiteRef.sources[af_key].format(pfx or self.altcoin_pfx,'' if coin else self.tn_ext) af = joinpath(ref_dir,(subdir or self.ref_subdir,'')[ftype=='passwd'],af_fn) - coin_arg = [] if coin == None else ['--coin='+coin] + coin_arg = [] if coin is None else ['--coin='+coin] tool_cmd = ftype.replace('segwit','').replace('bech32','')+'file_chksum' t = self.spawn( 'mmgen-tool', coin_arg + ['--verbose','-p1',tool_cmd,af] ) if ftype == 'keyaddr': diff --git a/test/test_py_d/ts_xmr_autosign.py b/test/test_py_d/ts_xmr_autosign.py index 7df716dd..940db10b 100755 --- a/test/test_py_d/ts_xmr_autosign.py +++ b/test/test_py_d/ts_xmr_autosign.py @@ -109,7 +109,7 @@ class TestSuiteXMRAutosign(TestSuiteXMRWallet,TestSuiteAutosignBase): TestSuiteXMRWallet.__init__(self,trunner,cfgs,spawn) TestSuiteAutosignBase.__init__(self,trunner,cfgs,spawn) - if trunner == None: + if trunner is None: return from mmgen.cfg import Config diff --git a/test/test_py_d/ts_xmrwallet.py b/test/test_py_d/ts_xmrwallet.py index c6f3e7df..3d1e6bd5 100755 --- a/test/test_py_d/ts_xmrwallet.py +++ b/test/test_py_d/ts_xmrwallet.py @@ -119,7 +119,7 @@ class TestSuiteXMRWallet(TestSuiteBase): def __init__(self,trunner,cfgs,spawn): TestSuiteBase.__init__(self,trunner,cfgs,spawn) - if trunner == None: + if trunner is None: return from mmgen.protocol import init_proto diff --git a/test/tooltest.py b/test/tooltest.py index ffefeae1..1cd09e45 100755 --- a/test/tooltest.py +++ b/test/tooltest.py @@ -157,7 +157,7 @@ elif gc.platform == 'win': add_spawn_args = ['--data-dir='+tcfg['tmpdir']] + ['--{}{}'.format( k.replace('_','-'), - '='+getattr(cfg,k) if getattr(cfg,k) != True else '') + '='+getattr(cfg,k) if getattr(cfg,k) is not True else '') for k in ('testnet','rpc_host','regtest','coin','type') if getattr(cfg,k)] if cfg.list_cmds: diff --git a/test/tooltest2.py b/test/tooltest2.py index 57072e4a..3f00bd0a 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -983,7 +983,7 @@ if cfg.fork: tool_cmd = [ tool_exec, '--skip-cfg-file' ] + [ '--{}{}'.format( k.replace('_','-'), - '='+getattr(cfg,k) if getattr(cfg,k) != True else '') + '='+getattr(cfg,k) if getattr(cfg,k) is not True else '') for k in passthru_args if getattr(cfg,k) ] if cfg.coverage: diff --git a/test/unit_tests_d/ut_addrparse.py b/test/unit_tests_d/ut_addrparse.py index f500de9a..9ea5ec95 100755 --- a/test/unit_tests_d/ut_addrparse.py +++ b/test/unit_tests_d/ut_addrparse.py @@ -70,7 +70,7 @@ def test_network(proto,addrs): a1 = CoinAddr(proto,addr['std']) print_info(a1) check_bytes(a1) - assert not hasattr(a1.parsed,'payment_id') or a1.parsed.payment_id == None + assert not hasattr(a1.parsed,'payment_id') or a1.parsed.payment_id is None if 'int' in addr: a2 = CoinAddr(proto,addr['int']) diff --git a/test/unit_tests_d/ut_baseconv.py b/test/unit_tests_d/ut_baseconv.py index 154d5912..a0989248 100755 --- a/test/unit_tests_d/ut_baseconv.py +++ b/test/unit_tests_d/ut_baseconv.py @@ -187,10 +187,10 @@ class unit_test: vmsg(f'\nBase: {base}') vmsg(fs.format(h='Input',p='Pad',r='Output')) for (hexstr,pad),ret_chk in data: - if type(pad) == int: + if type(pad) is int: pad = len(hexstr) ret = baseconv(base).tohex( ret_chk.split() if base == 'mmgen' else ret_chk, pad=pad ) - if pad == None: + if pad is None: assert int(ret,16) == int(hexstr,16), rerr.format(int(ret,16),int(hexstr,16)) else: assert ret == hexstr, rerr.format(ret,hexstr) diff --git a/test/unit_tests_d/ut_lockable.py b/test/unit_tests_d/ut_lockable.py index 5b03096d..a403f2be 100755 --- a/test/unit_tests_d/ut_lockable.py +++ b/test/unit_tests_d/ut_lockable.py @@ -49,8 +49,8 @@ class unit_test: acdn = MyAttrCtrlDflNone() assert acdn.foo == 'fooval', f'{acdn.foo}' - assert acdn.bar == None, f'{acdn.bar}' - assert acdn.baz == None, f'{acdn.baz}' + assert acdn.bar is None, f'{acdn.bar}' + assert acdn.baz is None, f'{acdn.baz}' qmsg('OK') qmsg_r('Testing class Lockable...') @@ -110,9 +110,9 @@ class unit_test: self.foo = True lca = MyLockableAutolock() - assert lca._autolock == True - assert lca._locked == True - assert lca.foo == True + assert lca._autolock is True + assert lca._locked is True + assert lca.foo is True class MyLockableAutolockDflNone(Lockable): _default_to_none = True diff --git a/test/unit_tests_d/ut_mn_entry.py b/test/unit_tests_d/ut_mn_entry.py index 2219261c..63e6deb1 100755 --- a/test/unit_tests_d/ut_mn_entry.py +++ b/test/unit_tests_d/ut_mn_entry.py @@ -76,7 +76,7 @@ class unit_test: if chk is False: assert b is None, (b,None) elif chk is None: - assert type(b) == tuple, (type(b),tuple) + assert type(b) is tuple, (type(b),tuple) elif type(chk) is int: assert b == chk, (b,chk) msg('OK') diff --git a/test/unit_tests_d/ut_obj.py b/test/unit_tests_d/ut_obj.py index b8a3f5a0..88a4a7cb 100755 --- a/test/unit_tests_d/ut_obj.py +++ b/test/unit_tests_d/ut_obj.py @@ -25,7 +25,7 @@ class unit_tests: vmsg(f'{desc:10} = {res:<{cls.max_prec+10}} [{type(res).__name__}]') if chk is not None: assert res == chk, f'{res} != {chk}' - assert type(res) == cls, f'{type(res).__name__} != {cls.__name__}' + assert type(res) is cls, f'{type(res).__name__} != {cls.__name__}' qmsg_r(f'Testing {cls.__name__} arithmetic operations...') vmsg('') diff --git a/test/unit_tests_d/ut_subseed.py b/test/unit_tests_d/ut_subseed.py index 864d4df5..902a84f3 100755 --- a/test/unit_tests_d/ut_subseed.py +++ b/test/unit_tests_d/ut_subseed.py @@ -125,7 +125,7 @@ class unit_test: seed = Seed( cfg, seed_bin ) subseed = seed.subseed_by_seed_id('803B165C',last_idx=1) assert len(ss.data['long']) == len(ss.data['short']), len(ss.data['short']) - assert subseed == None, subseed + assert subseed is None, subseed r = SubSeedIdxRange('1-5') r2 = SubSeedIdxRange(1,5)