diff --git a/Lib/bsddb/dbshelve.py b/Lib/bsddb/dbshelve.py index fb0b7624046..1706ca86f40 100644 --- a/Lib/bsddb/dbshelve.py +++ b/Lib/bsddb/dbshelve.py @@ -157,7 +157,7 @@ class DBShelf(MutableMapping): def keys(self, txn=None): - if txn != None: + if txn is not None: return self.db.keys(txn) else: return self.db.keys() @@ -185,7 +185,7 @@ class DBShelf(MutableMapping): def items(self, txn=None): - if txn != None: + if txn is not None: items = self.db.items(txn) else: items = self.db.items() @@ -196,7 +196,7 @@ class DBShelf(MutableMapping): return newitems def values(self, txn=None): - if txn != None: + if txn is not None: values = self.db.values(txn) else: values = self.db.values() diff --git a/Lib/bsddb/dbtables.py b/Lib/bsddb/dbtables.py index b728570ee25..02ddcdc979c 100644 --- a/Lib/bsddb/dbtables.py +++ b/Lib/bsddb/dbtables.py @@ -179,14 +179,14 @@ class bsdTableDB : def set_range(self, search) : v = self._dbcursor.set_range(bytes(search, "iso8859-1")) - if v != None : + if v is not None : v = (v[0].decode("iso8859-1"), v[1].decode("iso8859-1")) return v def __next__(self) : v = getattr(self._dbcursor, "next")() - if v != None : + if v is not None : v = (v[0].decode("iso8859-1"), v[1].decode("iso8859-1")) return v @@ -204,7 +204,7 @@ class bsdTableDB : def put(self, key, value, flags=0, txn=None) : key = bytes(key, "iso8859-1") - if value != None : + if value is not None : value = bytes(value, "iso8859-1") return self._db.put(key, value, flags=flags, txn=txn) @@ -215,7 +215,7 @@ class bsdTableDB : def get(self, key, txn=None, flags=0) : key = bytes(key, "iso8859-1") v = self._db.get(key, txn=txn, flags=flags) - if v != None : + if v is not None : v = v.decode("iso8859-1") return v @@ -540,7 +540,7 @@ class bsdTableDB : # error dataitem = None dataitem = mappings[column](dataitem) - if dataitem != None: + if dataitem is not None: self.db.put( _data_key(table, column, rowid), dataitem, txn=txn) diff --git a/Lib/bsddb/test/test_all.py b/Lib/bsddb/test/test_all.py index a8b32eff195..39231c6f23c 100644 --- a/Lib/bsddb/test/test_all.py +++ b/Lib/bsddb/test/test_all.py @@ -23,7 +23,7 @@ if sys.version_info[0] >= 3 : return getattr(self._dbcursor, v) def _fix(self, v) : - if v == None : return None + if v is None : return None key, value = v if isinstance(key, bytes) : key = key.decode(charset) @@ -90,7 +90,7 @@ if sys.version_info[0] >= 3 : def pget(self, key=None, data=None, flags=0) : # Incorrect because key can be a bare number, # but enough to pass testsuite - if isinstance(key, int) and (data==None) and (flags==0) : + if isinstance(key, int) and (data is None) and (flags == 0) : flags = key key = None if isinstance(key, str) : @@ -101,7 +101,7 @@ if sys.version_info[0] >= 3 : if isinstance(data, str) : data = bytes(data, charset) v=self._dbcursor.pget(key=key, data=data, flags=flags) - if v != None : + if v is not None : v1, v2, v3 = v if isinstance(v1, bytes) : v1 = v1.decode(charset) @@ -114,7 +114,7 @@ if sys.version_info[0] >= 3 : def join_item(self) : v = self._dbcursor.join_item() - if v != None : + if v is not None : v = v.decode(charset) return v @@ -134,7 +134,7 @@ if sys.version_info[0] >= 3 : args =(k, d, f) v = self._dbcursor.get(*args, **kwargs) - if v != None : + if v is not None : k, v = v if isinstance(k, bytes) : k = k.decode(charset) @@ -176,7 +176,7 @@ if sys.version_info[0] >= 3 : if isinstance(k, str) : k = bytes(k, charset) v = self._db[k] - if v != None : + if v is not None : v = v.decode(charset) return v @@ -230,7 +230,7 @@ if sys.version_info[0] >= 3 : else : v=self._db.get(key, txn=txn, flags=flags, dlen=dlen, doff=doff) - if (v != None) and isinstance(v, bytes) : + if (v is not None) and isinstance(v, bytes) : v = v.decode(charset) return v @@ -238,7 +238,7 @@ if sys.version_info[0] >= 3 : if isinstance(key, str) : key = bytes(key, charset) v=self._db.pget(key, txn=txn) - if v != None : + if v is not None : v1, v2 = v if isinstance(v1, bytes) : v1 = v1.decode(charset) @@ -252,7 +252,7 @@ if sys.version_info[0] >= 3 : if isinstance(value, str) : value = bytes(value, charset) v=self._db.get_both(key, value, txn=txn, flags=flags) - if v != None : + if v is not None : v = v.decode(charset) return v diff --git a/Lib/bsddb/test/test_basics.py b/Lib/bsddb/test/test_basics.py index 5d6ffe39ee6..c5579de75cf 100644 --- a/Lib/bsddb/test/test_basics.py +++ b/Lib/bsddb/test/test_basics.py @@ -342,7 +342,7 @@ class BasicTestCase(unittest.TestCase): else: if set_raises_error: self.fail("expected exception") - if n != None: + if n is not None: self.fail("expected None: %r" % (n,)) rec = c.get_both('0404', self.makeData('0404')) @@ -356,7 +356,7 @@ class BasicTestCase(unittest.TestCase): else: if get_raises_error: self.fail("expected exception") - if n != None: + if n is not None: self.fail("expected None: %r" % (n,)) if self.d.get_type() == db.DB_BTREE: diff --git a/Lib/bsddb/test/test_compare.py b/Lib/bsddb/test/test_compare.py index d9637c1bdf3..045ee259329 100644 --- a/Lib/bsddb/test/test_compare.py +++ b/Lib/bsddb/test/test_compare.py @@ -238,12 +238,7 @@ class BtreeExceptionsTestCase (AbstractBtreeKeyCompareTestCase): self.startTest () self.createDB (my_compare) - try: - self.db.set_bt_compare (my_compare) - self.assert_(0, "this set should fail") - - except RuntimeError, msg: - pass + self.assertRaises (RuntimeError, self.db.set_bt_compare, my_compare) def test_suite (): res = unittest.TestSuite () diff --git a/Lib/bsddb/test/test_dbtables.py b/Lib/bsddb/test/test_dbtables.py index e655100cbd9..935c9d5acb2 100644 --- a/Lib/bsddb/test/test_dbtables.py +++ b/Lib/bsddb/test/test_dbtables.py @@ -341,7 +341,7 @@ class TableDBTestCase(unittest.TestCase): self.tdb.Insert(tabname, {'Type': 'Unknown', 'Access': '0'}) def set_type(type): - if type == None: + if type is None: return 'MP3' return type diff --git a/Lib/bsddb/test/test_recno.py b/Lib/bsddb/test/test_recno.py index 5f3bf3ad5c8..0a10ec99042 100644 --- a/Lib/bsddb/test/test_recno.py +++ b/Lib/bsddb/test/test_recno.py @@ -38,8 +38,8 @@ class SimpleRecnoTestCase(unittest.TestCase): for x in letters: recno = d.append(x * 60) - self.assertEqual(type(recno), type(0)) - self.assert_(recno >= 1) + self.assertIsInstance(recno, int) + self.assertGreaterEqual(recno, 1) if verbose: print recno, @@ -54,7 +54,7 @@ class SimpleRecnoTestCase(unittest.TestCase): if verbose: print data - self.assertEqual(type(data), type("")) + self.assertIsInstance(data, str) self.assertEqual(data, d.get(recno)) try: @@ -91,21 +91,21 @@ class SimpleRecnoTestCase(unittest.TestCase): keys = d.keys() if verbose: print keys - self.assertEqual(type(keys), type([])) - self.assertEqual(type(keys[0]), type(123)) + self.assertIsInstance(keys, list) + self.assertIsInstance(keys[0], int) self.assertEqual(len(keys), len(d)) items = d.items() if verbose: pprint(items) - self.assertEqual(type(items), type([])) - self.assertEqual(type(items[0]), type(())) + self.assertIsInstance(items, list) + self.assertIsInstance(items[0], tuple) self.assertEqual(len(items[0]), 2) - self.assertEqual(type(items[0][0]), type(123)) - self.assertEqual(type(items[0][1]), type("")) + self.assertIsInstance(items[0][0], int) + self.assertIsInstance(items[0][1], str) self.assertEqual(len(items), len(d)) - self.assert_(d.has_key(25)) + self.assertTrue(d.has_key(25)) del d[25] self.assertFalse(d.has_key(25)) @@ -177,7 +177,7 @@ class SimpleRecnoTestCase(unittest.TestCase): if get_returns_none: self.fail("unexpected DBKeyEmptyError exception") else: - self.assertEqual(val[0], db.DB_KEYEMPTY) + self.assertEqual(val.args[0], db.DB_KEYEMPTY) if verbose: print val else: if not get_returns_none: diff --git a/Lib/bsddb/test/test_replication.py b/Lib/bsddb/test/test_replication.py index b3775c73303..1817e60bf6e 100644 --- a/Lib/bsddb/test/test_replication.py +++ b/Lib/bsddb/test/test_replication.py @@ -188,11 +188,11 @@ class DBReplicationManager(unittest.TestCase): import time timeout=time.time()+10 v=None - while (time.time()