Fixes 'not in' operator usage
Change-Id: I1e26a8fcb9fa564308e63c11a72aaa55119e4eee
This commit is contained in:
12
HACKING.rst
12
HACKING.rst
@@ -29,6 +29,18 @@ General
|
||||
mylist = Foo().list() # OKAY, does not shadow built-in
|
||||
|
||||
|
||||
- Use the "not in" operator for collection membership evaluation. Example::
|
||||
|
||||
if not X in Y: # BAD, hard to understand
|
||||
pass
|
||||
|
||||
if X not in Y: # OKAY, intuitive
|
||||
pass
|
||||
|
||||
if not (X in Y or X is Z): # OKAY, still better than all those 'not's
|
||||
pass
|
||||
|
||||
|
||||
Imports
|
||||
-------
|
||||
- Do not import objects, only modules (*)
|
||||
|
||||
@@ -3848,7 +3848,7 @@ class IptablesFirewallTestCase(test.TestCase):
|
||||
in_rules = filter(lambda l: not l.startswith('#'),
|
||||
self.in_rules)
|
||||
for rule in in_rules:
|
||||
if not 'nova' in rule:
|
||||
if 'nova' not in rule:
|
||||
self.assertTrue(rule in self.out_rules,
|
||||
'Rule went missing: %s' % rule)
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ def fake_execute(*args, **kwargs):
|
||||
elif args[0] == "chown":
|
||||
owner = args[1]
|
||||
path = args[2]
|
||||
if not path in files:
|
||||
if path not in files:
|
||||
raise Exception("No such file: " + path)
|
||||
|
||||
sep = owner.find(':')
|
||||
@@ -72,7 +72,7 @@ def fake_execute(*args, **kwargs):
|
||||
elif args[0] == "chgrp":
|
||||
group = args[1]
|
||||
path = args[2]
|
||||
if not path in files:
|
||||
if path not in files:
|
||||
raise Exception("No such file: " + path)
|
||||
|
||||
if group == "users":
|
||||
@@ -83,13 +83,13 @@ def fake_execute(*args, **kwargs):
|
||||
elif args[0] == "chmod":
|
||||
mode = args[1]
|
||||
path = args[2]
|
||||
if not path in files:
|
||||
if path not in files:
|
||||
raise Exception("No such file: " + path)
|
||||
|
||||
files[path]["mode"] = int(mode, 8)
|
||||
elif args[0] == "cat":
|
||||
path = args[1]
|
||||
if not path in files:
|
||||
if path not in files:
|
||||
files[path] = {
|
||||
"content": "Hello World",
|
||||
"gid": 100,
|
||||
@@ -104,7 +104,7 @@ def fake_execute(*args, **kwargs):
|
||||
else:
|
||||
path = args[1]
|
||||
append = False
|
||||
if not path in files:
|
||||
if path not in files:
|
||||
files[path] = {
|
||||
"content": "Hello World",
|
||||
"gid": 100,
|
||||
|
||||
@@ -595,7 +595,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
||||
|
||||
def _check_vdis(self, start_list, end_list):
|
||||
for vdi_ref in end_list:
|
||||
if not vdi_ref in start_list:
|
||||
if vdi_ref not in start_list:
|
||||
vdi_rec = xenapi_fake.get_record('VDI', vdi_ref)
|
||||
# If the cache is turned on then the base disk will be
|
||||
# there even after the cleanup
|
||||
@@ -1949,7 +1949,7 @@ class XenAPIDom0IptablesFirewallTestCase(stubs.XenAPITestBase):
|
||||
in_rules = filter(lambda l: not l.startswith('#'),
|
||||
self._in_rules)
|
||||
for rule in in_rules:
|
||||
if not 'nova' in rule:
|
||||
if 'nova' not in rule:
|
||||
self.assertTrue(rule in self._out_rules,
|
||||
'Rule went missing: %s' % rule)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user