gps pointed out that "== and != work in most cases but its better to use is
and is not as you'll never run into a case where someone's __eq__ or __ne__
method do the wrong thing."
Signed-off-by: Martin J. Bligh <mbligh@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@2533 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/CODING_STYLE b/CODING_STYLE
index 452e5f7..7c655fe 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -38,6 +38,7 @@
of your variable_names please. I shall make a bedgrudging exception for class
names I suppose, but I'll still whine about it a lot.
+
Importing modules
The order of imports should be as follows:
@@ -62,6 +63,12 @@
import MySQLdb
from common_lib import error
+Testing None
+
+Use "is None" rather than "== None" and "is not None" rather than "!= None".
+This way you'll never run into a case where someone's __eq__ or __ne__
+method do the wrong thing
+
Comments
diff --git a/cli/cli_mock.py b/cli/cli_mock.py
index 4acf976..c616bee 100755
--- a/cli/cli_mock.py
+++ b/cli/cli_mock.py
@@ -100,7 +100,7 @@
if not (CLI_USING_PDB and CLI_UT_DEBUG):
self.god.mock_io()
- if exit_code != None:
+ if exit_code is not None:
sys.exit.expect_call(exit_code).and_raises(ExitException)
self.assertRaises(ExitException, atest.main)
else:
diff --git a/cli/topic_common.py b/cli/topic_common.py
index e500c19..f639de7 100755
--- a/cli/topic_common.py
+++ b/cli/topic_common.py
@@ -338,7 +338,7 @@
True in the list.
Also check if the req_items is not empty after parsing."""
(options, leftover) = atest.parse(self)
- if leftover == None:
+ if leftover is None:
leftover = []
for (attribute, opt_fname, opt_list, use_leftover) in flists:
diff --git a/client/bin/cpuset.py b/client/bin/cpuset.py
index 499d222..78f040e 100644
--- a/client/bin/cpuset.py
+++ b/client/bin/cpuset.py
@@ -244,7 +244,7 @@
self.name = name
- if root == None:
+ if root is None:
# default to nested in process's current container
root = my_container_name()[1:]
self.root = os.path.join(super_root, root)
@@ -252,7 +252,7 @@
raise error.AutotestError(('Parent container %s does not exist')
% self.root)
- if job_size == None:
+ if job_size is None:
# default to biggest container we can make under root
job_size = int( mbytes_per_mem_node() *
len(available_exclusive_mem_nodes(self.root)) )
@@ -260,7 +260,7 @@
raise error.AutotestError('Creating container with no mem')
self.memory = job_size
- if cpus == None:
+ if cpus is None:
# default to biggest container we can make under root
cpus = get_cpus(self.root)
if not cpus:
diff --git a/client/bin/kernel.py b/client/bin/kernel.py
index 360bdb1..0432761 100755
--- a/client/bin/kernel.py
+++ b/client/bin/kernel.py
@@ -556,7 +556,7 @@
self.set_build_target(build_target)
# If no 'target_arch' given assume native compilation
- if target_arch == None:
+ if target_arch is None:
target_arch = autotest_utils.get_current_kernel_arch()
if target_arch == 'ppc64':
if self.build_target == 'bzImage':
diff --git a/client/bin/net/net_utils.py b/client/bin/net/net_utils.py
index 2898d7e..960b581 100755
--- a/client/bin/net/net_utils.py
+++ b/client/bin/net/net_utils.py
@@ -450,7 +450,7 @@
self._socket = None
self._socket_timeout = raw_socket.SOCKET_TIMEOUT
socket.setdefaulttimeout(self._socket_timeout)
- if self._name == None:
+ if self._name is None:
raise error.TestError('Invalid interface name')
@@ -477,10 +477,10 @@
Args:
protocol : short in host byte order. None if ALL
"""
- if self._socket != None:
+ if self._socket is not None:
raise error.TestError('Raw socket already open')
- if protocol == None:
+ if protocol is None:
self._socket = socket.socket(socket.PF_PACKET,
socket.SOCK_RAW)
@@ -495,7 +495,7 @@
def close(self):
""" Close the raw socket"""
- if self._socket != None:
+ if self._socket is not None:
self._socket.close()
self._socket = None
else:
@@ -519,7 +519,7 @@
a binary string containing the received packet.
time_left: amount of time left in timeout
"""
- if self._socket == None:
+ if self._socket is None:
raise error.TestError('Raw socket not open')
time_left = timeout
@@ -542,7 +542,7 @@
def send(self, packet):
"""Send an ethernet packet."""
- if self._socket == None:
+ if self._socket is None:
raise error.TestError('Raw socket not open')
self._socket.send(packet)
@@ -559,7 +559,7 @@
protocol: short in host byte order
payload: 'byte string'
"""
- if self._socket == None:
+ if self._socket is None:
raise error.TestError('Raw socket not open')
try:
packet = ethernet.pack(dst_mac, src_mac, protocol, payload)
@@ -594,11 +594,11 @@
while 1:
frame = None
packet, timeout = self.recv(timeout)
- if packet != None:
+ if packet is not None:
frame = ethernet.unpack(packet)
- if ((src_mac == None or frame['src'] == src_mac) and
- (dst_mac == None or frame['dst'] == dst_mac) and
- (protocol == None or frame['proto'] == protocol)):
+ if ((src_mac is None or frame['src'] == src_mac) and
+ (dst_mac is None or frame['dst'] == dst_mac) and
+ (protocol is None or frame['proto'] == protocol)):
break;
elif (timeout == 0 or
time.clock() - start_time > float(self._socket_timeout)):
diff --git a/client/bin/partition.py b/client/bin/partition.py
index 76cb104..ba63466 100755
--- a/client/bin/partition.py
+++ b/client/bin/partition.py
@@ -406,7 +406,7 @@
if fstype is None:
fstype = self.fstype
else:
- assert(self.fstype == None or self.fstype == fstype);
+ assert(self.fstype is None or self.fstype == fstype);
if self.mount_options:
args += ' -o ' + self.mount_options
diff --git a/client/bin/xen.py b/client/bin/xen.py
index 90686fc..2191ab9 100644
--- a/client/bin/xen.py
+++ b/client/bin/xen.py
@@ -52,7 +52,7 @@
utils.system(build_string)
# make a kernel job out of the kernel from the xen src if one isn't provided
- if self.kjob == None:
+ if self.kjob is None:
# get xen kernel tree ready
self.log("prep-ing xen'ified kernel source tree")
utils.system('make prep-kernels')
diff --git a/client/common_lib/global_config.py b/client/common_lib/global_config.py
index f6e5c08..18c810e 100644
--- a/client/common_lib/global_config.py
+++ b/client/common_lib/global_config.py
@@ -44,7 +44,7 @@
try:
val = self.config.get(section, key)
except:
- if default == None:
+ if default is None:
msg = ("Value '%s' not found in section '%s'" %
(key, section))
raise ConfigError(msg)
@@ -71,7 +71,7 @@
def _ensure_config_parsed(self):
- if self.config == None:
+ if self.config is None:
self.parse_config_file()
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index f85213f..ec5a92f 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -441,7 +441,7 @@
for i in range(5):
rc = subproc.poll()
- if rc != None:
+ if rc is not None:
return rc
time.sleep(1)
diff --git a/client/profilers/oprofile/oprofile.py b/client/profilers/oprofile/oprofile.py
index 5913d1d..c86326a 100755
--- a/client/profilers/oprofile/oprofile.py
+++ b/client/profilers/oprofile/oprofile.py
@@ -80,7 +80,7 @@
src_opreport = os.path.join(self.srcdir, '/bin/opreport')
src_opcontrol = os.path.join(self.srcdir, '/bin/opcontrol')
- if local == False or (local == None and
+ if local == False or (local is None and
os.path.exists(src_opreport) and
os.path.exists(src_opcontrol)):
print "Using source-built copy of oprofile"
diff --git a/client/tests/iperf/iperf.py b/client/tests/iperf/iperf.py
index 8549651..69f1388 100644
--- a/client/tests/iperf/iperf.py
+++ b/client/tests/iperf/iperf.py
@@ -170,7 +170,7 @@
'Jitter_S2C':[], 'Jitter_C2S':[]}
# Short circuit to handle errors due to client timeouts
- if output == None:
+ if output is None:
self.write_iteration_keyval(attr, keyval)
continue
diff --git a/client/tests/kvmtest/control.with_modbuild b/client/tests/kvmtest/control.with_modbuild
index fcef2e7..a620b6c 100644
--- a/client/tests/kvmtest/control.with_modbuild
+++ b/client/tests/kvmtest/control.with_modbuild
@@ -36,7 +36,7 @@
print "kvm srcdir->%s"%(srcdir)
# ex: http://people.qumranet.com/avi/snapshots/kvm-snapshot-20071021.tar.gz
- if tarball == None:
+ if tarball is None:
d = (date.today() - timedelta(days=daysold)).strftime('%Y%m%d')
tarball = base+'kvm-snapshot-%s.tar.gz' %(d)
sys.stderr.write("tarball url: %s\n" %(tarball))
diff --git a/client/tests/memory_api/memory_api.py b/client/tests/memory_api/memory_api.py
index 10ec5d6..954ebc5 100755
--- a/client/tests/memory_api/memory_api.py
+++ b/client/tests/memory_api/memory_api.py
@@ -34,7 +34,7 @@
p1 = subprocess.Popen('%s/memory_api ' % self.tmpdir + memsize,
shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
- while p1.poll() == None:
+ while p1.poll() is None:
output = p1.stdout.readline().rstrip()
m = memory_re.search(output)
mem_start = 0
@@ -66,7 +66,7 @@
raise error.TestFail("VmaCountMismatch")
print "%s %s %d %d" % (hex(mem_start), hex(mem_len),
vma_count, expected_vma_count)
- if p1.poll() == None:
+ if p1.poll() is None:
p1.stdin.write("\n")
p1.stdin.flush()
diff --git a/client/tests/unixbench/unixbench.py b/client/tests/unixbench/unixbench.py
index 3ceac0f..81e8fae 100755
--- a/client/tests/unixbench/unixbench.py
+++ b/client/tests/unixbench/unixbench.py
@@ -43,7 +43,7 @@
def cleanup(self):
# check err string and possible throw
- if self.err != None:
+ if self.err is not None:
raise error.TestError(self.err)
@@ -52,7 +52,7 @@
if l >= 3 and words[-3:l] == ['no', 'measured', 'results']:
# found a problem so record it in err string
key = '_'.join(words[:-3])
- if self.err == None:
+ if self.err is None:
self.err = key
else:
self.err = self.err + " " + key
diff --git a/contrib/coverage.py b/contrib/coverage.py
index bd797bb..341b383 100644
--- a/contrib/coverage.py
+++ b/contrib/coverage.py
@@ -735,7 +735,7 @@
pairs = []
while i < len(statements) and j < len(lines):
if statements[i] == lines[j]:
- if start == None:
+ if start is None:
start = lines[j]
end = lines[j]
j = j + 1
diff --git a/frontend/afe/json_rpc/proxy.py b/frontend/afe/json_rpc/proxy.py
index 865ab3c..d0773c8 100644
--- a/frontend/afe/json_rpc/proxy.py
+++ b/frontend/afe/json_rpc/proxy.py
@@ -34,7 +34,7 @@
self.__headers = headers or {}
def __getattr__(self, name):
- if self.__serviceName != None:
+ if self.__serviceName is not None:
name = "%s.%s" % (self.__serviceName, name)
return ServiceProxy(self.__serviceURL, name, self.__headers)
@@ -49,7 +49,7 @@
resp = json_decoder.decode(respdata)
except ValueError:
raise JSONRPCException('Error decoding JSON reponse:\n' + respdata)
- if resp['error'] != None:
+ if resp['error'] is not None:
error_message = (resp['error']['name'] + ': ' +
resp['error']['message'] + '\n' +
resp['error']['traceback'])
diff --git a/frontend/afe/json_rpc/serviceHandler.py b/frontend/afe/json_rpc/serviceHandler.py
index 630363b..5a6ba29 100644
--- a/frontend/afe/json_rpc/serviceHandler.py
+++ b/frontend/afe/json_rpc/serviceHandler.py
@@ -92,7 +92,7 @@
except:
err = BadServiceRequest(json)
- if err == None:
+ if err is None:
try:
meth = self.findServiceEndpoint(methName)
except Exception, e:
@@ -100,7 +100,7 @@
print err_traceback
err = e
- if err == None:
+ if err is None:
try:
result = self.invokeServiceEndpoint(meth, args)
except Exception, e:
@@ -134,7 +134,7 @@
return meth(*args)
def translateResult(self, rslt, err, err_traceback, id_):
- if err != None:
+ if err is not None:
err = {"name": err.__class__.__name__, "message":str(err),
"traceback": err_traceback}
rslt = None
diff --git a/scheduler/monitor_db.py b/scheduler/monitor_db.py
index db49221..9b2dfe7 100644
--- a/scheduler/monitor_db.py
+++ b/scheduler/monitor_db.py
@@ -224,7 +224,7 @@
print 'killing', pid
if poll_fn is None:
poll_fn = get_proc_poll_fn(pid)
- if poll_fn() == None:
+ if poll_fn() is None:
os.kill(pid, signal.SIGCONT)
os.kill(pid, signal.SIGTERM)
@@ -1140,7 +1140,7 @@
def is_done(self):
- return self.active_task == None and self.queue.empty()
+ return self.active_task is None and self.queue.empty()
def start(self):
diff --git a/scheduler/monitor_db_babysitter b/scheduler/monitor_db_babysitter
index c463a2e..86bd6e7 100644
--- a/scheduler/monitor_db_babysitter
+++ b/scheduler/monitor_db_babysitter
@@ -71,7 +71,7 @@
def is_running(self):
- if self.proc.poll() != None:
+ if self.proc.poll() is not None:
bprint("monitor_db DIED")
return False
diff --git a/server/git.py b/server/git.py
index ee34980..93833ec 100644
--- a/server/git.py
+++ b/server/git.py
@@ -29,14 +29,14 @@
def __init__(self, repodir, giturl, weburl):
super(installable_object.InstallableObject, self).__init__()
- if repodir == None:
+ if repodir is None:
e_msg = 'You must provide a directory to hold the git repository'
raise ValueError(e_msg)
self.repodir = utils.sh_escape(repodir)
- if giturl == None:
+ if giturl is None:
raise ValueError('You must provide a git URL to the repository')
self.giturl = giturl
- if weburl == None:
+ if weburl is None:
raise ValueError('You must provide a http URL to the repository')
self.weburl = weburl
diff --git a/server/hosts/serial.py b/server/hosts/serial.py
index e28ad4a..3871cec 100644
--- a/server/hosts/serial.py
+++ b/server/hosts/serial.py
@@ -58,7 +58,7 @@
def start_loggers(self):
super(SerialHost, self).start_loggers()
- if self.__console_log == None:
+ if self.__console_log is None:
return
if not self.conmux_attach or not os.path.exists(self.conmux_attach):
diff --git a/server/samples/run_test.srv b/server/samples/run_test.srv
index f0129de..a3255f5 100644
--- a/server/samples/run_test.srv
+++ b/server/samples/run_test.srv
@@ -31,7 +31,7 @@
elif flag == '-l':
logdir = value
- if test == None or logdir == None:
+ if test is None or logdir is None:
usage()
sys.exit(1)
diff --git a/tko/compose_query.cgi b/tko/compose_query.cgi
index f02d219..9bae9c7 100755
--- a/tko/compose_query.cgi
+++ b/tko/compose_query.cgi
@@ -239,7 +239,7 @@
def map_kernel(name):
global map_kernel_map
- if map_kernel_map == None:
+ if map_kernel_map is None:
map_kernel_map = map_kernel_init()
if map_kernel_map.has_key(name):
diff --git a/tko/db.py b/tko/db.py
index 08a0e00..d66db28 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -197,7 +197,7 @@
def exec_sql():
sql = ' '.join(cmd)
numRec = self.cur.execute(sql, values)
- if max_rows != None and numRec > max_rows:
+ if max_rows is not None and numRec > max_rows:
msg = 'Exceeded allowed number of records'
raise MySQLTooManyRows(msg)
return self.cur.fetchall()
@@ -261,7 +261,7 @@
def delete(self, table, where, commit = None):
cmd = ['delete from', table]
- if commit == None:
+ if commit is None:
commit = self.autocommit
if where and isinstance(where, types.DictionaryType):
keys = [field + '=%s' for field in where.keys()]
@@ -280,7 +280,7 @@
data:
dictionary of fields and data
"""
- if commit == None:
+ if commit is None:
commit = self.autocommit
cmd = 'update %s ' % table
fields = data.keys()
diff --git a/tko/save_query.cgi b/tko/save_query.cgi
index 80c91fc..78d65ea 100755
--- a/tko/save_query.cgi
+++ b/tko/save_query.cgi
@@ -16,7 +16,7 @@
tm = time.asctime()
uid = unique_cookie.unique_id('tko_history')
HTTP_REFERER = os.environ.get('HTTP_REFERER')
-if HTTP_REFERER == None:
+if HTTP_REFERER is None:
## fall back strategy for proxy connection
## substitute relative url
HTTP_REFERER = 'compose_query.cgi?' + urllib.urlencode(dict_url)