pylint (test suite) - use "is" for bool,None,type equality

This commit is contained in:
The MMGen Project 2023-10-11 12:58:52 +00:00
commit 033822f565
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
20 changed files with 32 additions and 32 deletions

View file

@ -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))}')

View file

@ -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 )

View file

@ -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:

View file

@ -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))

View file

@ -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:

View file

@ -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

View file

@ -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()

View file

@ -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

View file

@ -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]

View file

@ -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':

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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:

View file

@ -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'])

View file

@ -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)

View file

@ -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

View file

@ -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')

View file

@ -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('')

View file

@ -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)