Commit 1b50c3ea authored by Tres Seaver's avatar Tres Seaver

Avoid 'has_key' usage; test it only under Python2.

parent b126c076
......@@ -15,6 +15,9 @@ import sys
if sys.version_info[0] < 3: #pragma NO COVER Python2
PY2 = True
PY3 = False
from StringIO import StringIO
BytesIO = StringIO
......@@ -29,6 +32,9 @@ if sys.version_info[0] < 3: #pragma NO COVER Python2
else: #pragma NO COVER Python3
PY2 = False
PY3 = True
from io import StringIO
from io import BytesIO
......
......@@ -251,8 +251,10 @@ class MappingBase(Base):
self.assertEqual(len(t) , len(addl), len(t))
def testHasKeyWorks(self):
from .._compat import PY2
t = self._makeOne()
t[1] = 1
if PY2:
self.assert_(t.has_key(1))
self.assert_(1 in t)
self.assert_(0 not in t)
......@@ -830,7 +832,7 @@ class BTreeTests(MappingBase):
r = range(100)
for x in r:
k = random.choice(r)
if not added.has_key(k):
if k not in added:
t[k] = x
added[k] = 1
addl = sorted(added.keys())
......@@ -864,15 +866,15 @@ class BTreeTests(MappingBase):
deleted = []
for x in r:
k = random.choice(r)
if t.has_key(k):
if k in t:
self.assert_(k in t)
del t[k]
deleted.append(k)
if t.has_key(k):
if k in t:
self.fail( "had problems deleting %s" % k )
badones = []
for x in deleted:
if t.has_key(x):
if x in t:
badones.append(x)
self.assertEqual(badones , [], (badones, added, deleted))
self._checkIt(t)
......@@ -959,9 +961,10 @@ class BTreeTests(MappingBase):
for x in add_order:
t[x] = 1
for x in delete_order:
try: del t[x]
try:
del t[x]
except KeyError:
if t.has_key(x):
if x in t:
self.assertEqual(1,2,"failed to delete %s" % x)
self._checkIt(t)
......@@ -1073,18 +1076,22 @@ class NormalSetTests(Base):
self.assertEqual(t.add(5) , 0)
def testInsert(self):
from .._compat import PY2
t = self._makeOne()
t.insert(1)
if PY2:
self.assert_(t.has_key(1))
self.assert_(1 in t)
self.assert_(2 not in t)
def testBigInsert(self):
from .._compat import PY2
t = self._makeOne()
r = xrange(10000)
for x in r:
t.insert(x)
for x in r:
if PY2:
self.assert_(t.has_key(x))
self.assert_(x in t)
......@@ -1101,7 +1108,9 @@ class NormalSetTests(Base):
self._makeOne().remove(1)
def testHasKeyFails(self):
from .._compat import PY2
t = self._makeOne()
if PY2:
self.assert_(not t.has_key(1))
self.assert_(1 not in t)
......
......@@ -52,7 +52,7 @@ class TestBTreesUnicode(unittest.TestCase):
for k, v in self.data:
if isinstance(k, str):
k = unicode(k, encoding)
self.assert_(self.tree.has_key(k))
self.assertTrue(k in self.tree)
self.assertEqual(self.tree[k], v)
@_skip_under_Py3k
......
......@@ -136,7 +136,7 @@ class NastyConfictFunctionalTests(ConflictTestBase, unittest.TestCase):
numtoadd = 16
candidate = 60
while numtoadd:
if not b.has_key(candidate):
if candidate not in b:
b[candidate] = candidate
numtoadd -= 1
candidate += 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment