diff options
author | Guido van Rossum <guido@python.org> | 2006-08-18 22:13:04 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-08-18 22:13:04 (GMT) |
commit | e2b70bcf7401477936fba99a8bf4a1f759ecc8a3 (patch) | |
tree | 4c9b65b7fd8c26a3d2f1b64ecd6b4c72a756b4b2 /Lib/test | |
parent | d2dbecb4ae9177e2e87adcb047147c6bcbf28cc1 (diff) | |
download | cpython-e2b70bcf7401477936fba99a8bf4a1f759ecc8a3.zip cpython-e2b70bcf7401477936fba99a8bf4a1f759ecc8a3.tar.gz cpython-e2b70bcf7401477936fba99a8bf4a1f759ecc8a3.tar.bz2 |
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Not all code has been fixed yet; this is just a checkpoint...
The C API still has PyDict_HasKey() and _HasKeyString(); not sure
if I want to change those just yet.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/mapping_tests.py | 14 | ||||
-rwxr-xr-x | Lib/test/regrtest.py | 1 | ||||
-rw-r--r-- | Lib/test/test___all__.py | 2 | ||||
-rw-r--r-- | Lib/test/test_bool.py | 6 | ||||
-rwxr-xr-x | Lib/test/test_bsddb.py | 5 | ||||
-rw-r--r-- | Lib/test/test_builtin.py | 10 | ||||
-rw-r--r-- | Lib/test/test_call.py | 18 | ||||
-rw-r--r-- | Lib/test/test_cgi.py | 4 | ||||
-rwxr-xr-x | Lib/test/test_dbm.py | 2 | ||||
-rw-r--r-- | Lib/test/test_dict.py | 14 | ||||
-rwxr-xr-x | Lib/test/test_gdbm.py | 2 | ||||
-rw-r--r-- | Lib/test/test_grammar.py | 6 | ||||
-rw-r--r-- | Lib/test/test_mailbox.py | 11 | ||||
-rw-r--r-- | Lib/test/test_multibytecodec_support.py | 2 | ||||
-rw-r--r-- | Lib/test/test_operations.py | 1 | ||||
-rw-r--r-- | Lib/test/test_pkgimport.py | 6 | ||||
-rw-r--r-- | Lib/test/test_pyclbr.py | 6 | ||||
-rw-r--r-- | Lib/test/test_rfc822.py | 2 | ||||
-rw-r--r-- | Lib/test/test_sax.py | 10 | ||||
-rw-r--r-- | Lib/test/test_scope.py | 2 | ||||
-rw-r--r-- | Lib/test/test_site.py | 2 | ||||
-rw-r--r-- | Lib/test/test_struct.py | 4 | ||||
-rw-r--r-- | Lib/test/test_time.py | 2 | ||||
-rw-r--r-- | Lib/test/test_urllib2.py | 2 | ||||
-rw-r--r-- | Lib/test/test_userdict.py | 10 | ||||
-rw-r--r-- | Lib/test/test_weakref.py | 20 | ||||
-rwxr-xr-x | Lib/test/test_wsgiref.py | 8 |
27 files changed, 65 insertions, 107 deletions
diff --git a/Lib/test/mapping_tests.py b/Lib/test/mapping_tests.py index 4b0f797..1c570b6 100644 --- a/Lib/test/mapping_tests.py +++ b/Lib/test/mapping_tests.py @@ -54,12 +54,10 @@ class BasicTestMappingProtocol(unittest.TestCase): #len self.assertEqual(len(p), 0) self.assertEqual(len(d), len(self.reference)) - #has_key + #__contains__ for k in self.reference: - self.assert_(d.has_key(k)) self.assert_(k in d) for k in self.other: - self.failIf(d.has_key(k)) self.failIf(k in d) #cmp self.assertEqual(cmp(p,p), 0) @@ -333,16 +331,6 @@ class TestMappingProtocol(BasicTestMappingProtocol): d = self._full_mapping({1:2}) self.assertEqual(d.items(), [(1, 2)]) - def test_has_key(self): - d = self._empty_mapping() - self.assert_(not d.has_key('a')) - d = self._full_mapping({'a': 1, 'b': 2}) - k = d.keys() - k.sort() - self.assertEqual(k, ['a', 'b']) - - self.assertRaises(TypeError, d.has_key) - def test_contains(self): d = self._empty_mapping() self.assert_(not ('a' in d)) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index a6e146b..8c0f2e4 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -1034,7 +1034,6 @@ _expectations = { 'darwin': """ test_al - test_bsddb3 test_cd test_cl test_gdbm diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py index c45e139..dba9161 100644 --- a/Lib/test/test___all__.py +++ b/Lib/test/test___all__.py @@ -24,7 +24,7 @@ class AllTest(unittest.TestCase): "%s has no __all__ attribute" % modname) names = {} exec "from %s import *" % modname in names - if names.has_key("__builtins__"): + if "__builtins__" in names: del names["__builtins__"] keys = set(names) all = set(sys.modules[modname].__all__) diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 663417d..15e1ef7 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -183,9 +183,9 @@ class BoolTest(unittest.TestCase): self.assertIs(issubclass(bool, int), True) self.assertIs(issubclass(int, bool), False) - def test_haskey(self): - self.assertIs({}.has_key(1), False) - self.assertIs({1:1}.has_key(1), True) + def test_contains(self): + self.assertIs(1 in {}, False) + self.assertIs(1 in {1:1}, True) def test_string(self): self.assertIs("xyz".endswith("z"), True) diff --git a/Lib/test/test_bsddb.py b/Lib/test/test_bsddb.py index 474f3da..91c1cca 100755 --- a/Lib/test/test_bsddb.py +++ b/Lib/test/test_bsddb.py @@ -135,11 +135,6 @@ class TestBSDDB(unittest.TestCase): self.assert_(k in self.f) self.assert_('not here' not in self.f) - def test_has_key(self): - for k in self.d: - self.assert_(self.f.has_key(k)) - self.assert_(not self.f.has_key('not here')) - def test_clear(self): self.f.clear() self.assertEqual(len(self.f), 0) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index c7e4394..5797aef 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -630,9 +630,9 @@ class BuiltinTest(unittest.TestCase): def test_hex(self): self.assertEqual(hex(16), '0x10') - self.assertEqual(hex(16L), '0x10L') + self.assertEqual(hex(16L), '0x10') self.assertEqual(hex(-16), '-0x10') - self.assertEqual(hex(-16L), '-0x10L') + self.assertEqual(hex(-16L), '-0x10') self.assertRaises(TypeError, hex, {}) def test_id(self): @@ -1240,9 +1240,9 @@ class BuiltinTest(unittest.TestCase): def test_oct(self): self.assertEqual(oct(100), '0144') - self.assertEqual(oct(100L), '0144L') + self.assertEqual(oct(100L), '0144') self.assertEqual(oct(-100), '-0144') - self.assertEqual(oct(-100L), '-0144L') + self.assertEqual(oct(-100L), '-0144') self.assertRaises(TypeError, oct, ()) def write_testfile(self): @@ -1441,7 +1441,7 @@ class BuiltinTest(unittest.TestCase): def test_repr(self): self.assertEqual(repr(''), '\'\'') self.assertEqual(repr(0), '0') - self.assertEqual(repr(0L), '0L') + self.assertEqual(repr(0L), '0') self.assertEqual(repr(()), '()') self.assertEqual(repr([]), '[]') self.assertEqual(repr({}), '{}') diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index f3c7c8c..2652343 100644 --- a/Lib/test/test_call.py +++ b/Lib/test/test_call.py @@ -9,39 +9,39 @@ from test import test_support class CFunctionCalls(unittest.TestCase): def test_varargs0(self): - self.assertRaises(TypeError, {}.has_key) + self.assertRaises(TypeError, {}.__contains__) def test_varargs1(self): - {}.has_key(0) + {}.__contains__(0) def test_varargs2(self): - self.assertRaises(TypeError, {}.has_key, 0, 1) + self.assertRaises(TypeError, {}.__contains__, 0, 1) def test_varargs0_ext(self): try: - {}.has_key(*()) + {}.__contains__(*()) except TypeError: pass def test_varargs1_ext(self): - {}.has_key(*(0,)) + {}.__contains__(*(0,)) def test_varargs2_ext(self): try: - {}.has_key(*(1, 2)) + {}.__contains__(*(1, 2)) except TypeError: pass else: raise RuntimeError def test_varargs0_kw(self): - self.assertRaises(TypeError, {}.has_key, x=2) + self.assertRaises(TypeError, {}.__contains__, x=2) def test_varargs1_kw(self): - self.assertRaises(TypeError, {}.has_key, x=2) + self.assertRaises(TypeError, {}.__contains__, x=2) def test_varargs2_kw(self): - self.assertRaises(TypeError, {}.has_key, x=2, y=2) + self.assertRaises(TypeError, {}.__contains__, x=2, y=2) def test_oldargs0_0(self): {}.keys() diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index 130b19d..8b0b482 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -158,10 +158,10 @@ def main(): # test individual fields for key in expect.keys(): expect_val = expect[key] - verify(fcd.has_key(key)) + verify(key in fcd) verify(norm(fcd[key]) == norm(expect[key])) verify(fcd.get(key, "default") == fcd[key]) - verify(fs.has_key(key)) + verify(key in fs) if len(expect_val) > 1: single_value = 0 else: diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py index e5757c9..8fdd262 100755 --- a/Lib/test/test_dbm.py +++ b/Lib/test/test_dbm.py @@ -28,7 +28,7 @@ def test_keys(): d['a'] = 'b' d['12345678910'] = '019237410982340912840198242' d.keys() - if d.has_key('a'): + if 'a' in d: if verbose: print 'Test dbm keys: ', d.keys() diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index bbca798..f168846 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -21,8 +21,8 @@ class DictTest(unittest.TestCase): self.assertEqual(d.keys(), []) d = {'a': 1, 'b': 2} k = d.keys() - self.assert_(d.has_key('a')) - self.assert_(d.has_key('b')) + self.assert_('a' in d) + self.assert_('b' in d) self.assertRaises(TypeError, d.keys, None) @@ -43,16 +43,6 @@ class DictTest(unittest.TestCase): self.assertRaises(TypeError, d.items, None) - def test_has_key(self): - d = {} - self.assert_(not d.has_key('a')) - d = {'a': 1, 'b': 2} - k = d.keys() - k.sort() - self.assertEqual(k, ['a', 'b']) - - self.assertRaises(TypeError, d.has_key) - def test_contains(self): d = {} self.assert_(not ('a' in d)) diff --git a/Lib/test/test_gdbm.py b/Lib/test/test_gdbm.py index 03a47d9..e76539a 100755 --- a/Lib/test/test_gdbm.py +++ b/Lib/test/test_gdbm.py @@ -17,7 +17,7 @@ a = g.keys() if verbose: print 'Test gdbm file keys: ', a -g.has_key('a') +'a' in g g.close() try: g['a'] diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index f160867..296dc9b 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -472,7 +472,7 @@ def f(): f() g = {} exec 'z = 1' in g -if g.has_key('__builtins__'): del g['__builtins__'] +if '__builtins__' in g: del g['__builtins__'] if g != {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g' g = {} l = {} @@ -480,8 +480,8 @@ l = {} import warnings warnings.filterwarnings("ignore", "global statement", module="<string>") exec 'global a; a = 1; b = 2' in g, l -if g.has_key('__builtins__'): del g['__builtins__'] -if l.has_key('__builtins__'): del l['__builtins__'] +if '__builtins__' in g: del g['__builtins__'] +if '__builtins__' in l: del l['__builtins__'] if (g, l) != ({'a':1}, {'b':2}): raise TestFailed, 'exec ... in g (%s), l (%s)' %(g,l) diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index 45dd118..04e856f 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -229,16 +229,9 @@ class TestMailbox(TestBase): count += 1 self.assert_(len(values) == count) - def test_has_key(self): - # Check existence of keys using has_key() - self._test_has_key_or_contains(self._box.has_key) - def test_contains(self): # Check existence of keys using __contains__() - self._test_has_key_or_contains(self._box.__contains__) - - def _test_has_key_or_contains(self, method): - # (Used by test_has_key() and test_contains().) + method = self._box.__contains__ self.assert_(not method('foo')) key0 = self._box.add(self._template % 0) self.assert_(method(key0)) @@ -442,7 +435,7 @@ class TestMailboxSuperclass(TestBase): self.assertRaises(NotImplementedError, lambda: box.get_message('')) self.assertRaises(NotImplementedError, lambda: box.get_string('')) self.assertRaises(NotImplementedError, lambda: box.get_file('')) - self.assertRaises(NotImplementedError, lambda: box.has_key('')) + self.assertRaises(NotImplementedError, lambda: '' in box) self.assertRaises(NotImplementedError, lambda: box.__contains__('')) self.assertRaises(NotImplementedError, lambda: box.__len__()) self.assertRaises(NotImplementedError, lambda: box.clear()) diff --git a/Lib/test/test_multibytecodec_support.py b/Lib/test/test_multibytecodec_support.py index bec32de..50ed481 100644 --- a/Lib/test/test_multibytecodec_support.py +++ b/Lib/test/test_multibytecodec_support.py @@ -297,7 +297,7 @@ class TestBase_Mapping(unittest.TestCase): continue unich = unichrs(data[1]) - if ord(unich) == 0xfffd or urt_wa.has_key(unich): + if ord(unich) == 0xfffd or unich in urt_wa: continue urt_wa[unich] = csetch diff --git a/Lib/test/test_operations.py b/Lib/test/test_operations.py index fafc062..0b558de 100644 --- a/Lib/test/test_operations.py +++ b/Lib/test/test_operations.py @@ -25,7 +25,6 @@ d[x1] = 1 for stmt in ['d[x2] = 2', 'z = d[x2]', 'x2 in d', - 'd.has_key(x2)', 'd.get(x2)', 'd.setdefault(x2, 42)', 'd.pop(x2)', diff --git a/Lib/test/test_pkgimport.py b/Lib/test/test_pkgimport.py index c87c342..8b5e3ad 100644 --- a/Lib/test/test_pkgimport.py +++ b/Lib/test/test_pkgimport.py @@ -6,14 +6,14 @@ class TestImport(unittest.TestCase): def __init__(self, *args, **kw): self.package_name = 'PACKAGE_' - while sys.modules.has_key(self.package_name): + while self.package_name in sys.modules: self.package_name += random.choose(string.letters) self.module_name = self.package_name + '.foo' unittest.TestCase.__init__(self, *args, **kw) def remove_modules(self): for module_name in (self.package_name, self.module_name): - if sys.modules.has_key(module_name): + if module_name in sys.modules: del sys.modules[module_name] def setUp(self): @@ -52,7 +52,7 @@ class TestImport(unittest.TestCase): try: __import__(self.module_name) except SyntaxError: pass else: raise RuntimeError, 'Failed to induce SyntaxError' - self.assert_(not sys.modules.has_key(self.module_name) and + self.assert_(self.module_name not in sys.modules and not hasattr(sys.modules[self.package_name], 'foo')) # ...make up a variable name that isn't bound in __builtins__ diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py index 2410b03..01703b5 100644 --- a/Lib/test/test_pyclbr.py +++ b/Lib/test/test_pyclbr.py @@ -40,11 +40,11 @@ class PyclbrTest(TestCase): def assertHaskey(self, obj, key, ignore): - ''' succeed iff obj.has_key(key) or key in ignore. ''' + ''' succeed iff key in obj or key in ignore. ''' if key in ignore: return - if not obj.has_key(key): + if key not in obj: print >>sys.stderr, "***",key - self.failUnless(obj.has_key(key)) + self.failUnless(key) in obj def assertEqualsOrIgnored(self, a, b, ignore): ''' succeed iff a == b or a in ignore or b in ignore ''' diff --git a/Lib/test/test_rfc822.py b/Lib/test/test_rfc822.py index 6d22825..de577da 100644 --- a/Lib/test/test_rfc822.py +++ b/Lib/test/test_rfc822.py @@ -25,7 +25,7 @@ class MessageTestCase(unittest.TestCase): def test_setdefault(self): msg = self.create_message( 'To: "last, first" <userid@foo.net>\n\ntest\n') - self.assert_(not msg.has_key("New-Header")) + self.assert_("New-Header" not in msg) self.assert_(msg.setdefault("New-Header", "New-Value") == "New-Value") self.assert_(msg.setdefault("New-Header", "Different-Value") == "New-Value") diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index af4c7dd..83ffcf1 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -357,7 +357,7 @@ def test_expat_nsattrs_wattr(): attrs.getNames() == [(ns_uri, "attr")] and \ (attrs.getQNames() == [] or attrs.getQNames() == ["ns:attr"]) and \ len(attrs) == 1 and \ - attrs.has_key((ns_uri, "attr")) and \ + (ns_uri, "attr") in attrs and \ attrs.keys() == [(ns_uri, "attr")] and \ attrs.get((ns_uri, "attr")) == "val" and \ attrs.get((ns_uri, "attr"), 25) == "val" and \ @@ -571,7 +571,7 @@ def verify_empty_attrs(attrs): attrs.getNames() == [] and \ attrs.getQNames() == [] and \ len(attrs) == 0 and \ - not attrs.has_key("attr") and \ + "attr" not in attrs and \ attrs.keys() == [] and \ attrs.get("attrs") is None and \ attrs.get("attrs", 25) == 25 and \ @@ -584,7 +584,7 @@ def verify_attrs_wattr(attrs): attrs.getNames() == ["attr"] and \ attrs.getQNames() == ["attr"] and \ len(attrs) == 1 and \ - attrs.has_key("attr") and \ + "attr" in attrs and \ attrs.keys() == ["attr"] and \ attrs.get("attr") == "val" and \ attrs.get("attr", 25) == "val" and \ @@ -639,7 +639,7 @@ def verify_empty_nsattrs(attrs): attrs.getNames() == [] and \ attrs.getQNames() == [] and \ len(attrs) == 0 and \ - not attrs.has_key((ns_uri, "attr")) and \ + (ns_uri, "attr") not in attrs and \ attrs.keys() == [] and \ attrs.get((ns_uri, "attr")) is None and \ attrs.get((ns_uri, "attr"), 25) == 25 and \ @@ -658,7 +658,7 @@ def test_nsattrs_wattr(): attrs.getNames() == [(ns_uri, "attr")] and \ attrs.getQNames() == ["ns:attr"] and \ len(attrs) == 1 and \ - attrs.has_key((ns_uri, "attr")) and \ + (ns_uri, "attr") in attrs and \ attrs.keys() == [(ns_uri, "attr")] and \ attrs.get((ns_uri, "attr")) == "val" and \ attrs.get((ns_uri, "attr"), 25) == "val" and \ diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index 239745c..98b7ef3 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -472,7 +472,7 @@ def f(x): return g d = f(2)(4) -verify(d.has_key('h')) +verify('h' in d) del d['h'] vereq(d, {'x': 2, 'y': 7, 'w': 6}) diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 3a8b9d3..05a4ac4 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -216,7 +216,7 @@ class ImportSideEffectTests(unittest.TestCase): def test_sitecustomize_executed(self): # If sitecustomize is available, it should have been imported. - if not sys.modules.has_key("sitecustomize"): + if "sitecustomize" not in sys.modules: try: import sitecustomize except ImportError: diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 66fd667..302698b 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -266,7 +266,7 @@ class IntTester: if x < 0: expected += 1L << self.bitsize assert expected > 0 - expected = hex(expected)[2:-1] # chop "0x" and trailing 'L' + expected = hex(expected)[2:] # chop "0x" if len(expected) & 1: expected = "0" + expected expected = unhexlify(expected) @@ -322,7 +322,7 @@ class IntTester: # Try big-endian. format = ">" + code expected = long(x) - expected = hex(expected)[2:-1] # chop "0x" and trailing 'L' + expected = hex(expected)[2:] # chop "0x" if len(expected) & 1: expected = "0" + expected expected = unhexlify(expected) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index f4be759..4fd7834 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -180,7 +180,7 @@ class TimeTestCase(unittest.TestCase): # rely on it. if org_TZ is not None: environ['TZ'] = org_TZ - elif environ.has_key('TZ'): + elif 'TZ' in environ: del environ['TZ'] time.tzset() diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 67218b8..4df854e 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -653,7 +653,7 @@ class HandlerTests(unittest.TestCase): r.info; r.geturl # addinfourl methods r.code, r.msg == 200, "OK" # added from MockHTTPClass.getreply() hdrs = r.info() - hdrs.get; hdrs.has_key # r.info() gives dict from .getreply() + hdrs.get; hdrs.__contains__ # r.info() gives dict from .getreply() self.assertEqual(r.geturl(), url) self.assertEqual(http.host, "example.com") diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py index a4b7de4..ecb33d1 100644 --- a/Lib/test/test_userdict.py +++ b/Lib/test/test_userdict.py @@ -94,13 +94,10 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol): self.assertEqual(u2.items(), d2.items()) self.assertEqual(u2.values(), d2.values()) - # Test has_key and "in". + # Test "in". for i in u2.keys(): - self.assert_(u2.has_key(i)) self.assert_(i in u2) - self.assertEqual(u1.has_key(i), d1.has_key(i)) self.assertEqual(i in u1, i in d1) - self.assertEqual(u0.has_key(i), d0.has_key(i)) self.assertEqual(i in u0, i in d0) # Test update @@ -132,7 +129,7 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol): # Test setdefault t = UserDict.UserDict() self.assertEqual(t.setdefault("x", 42), 42) - self.assert_(t.has_key("x")) + self.assert_("x" in t) self.assertEqual(t.setdefault("x", 23), 42) # Test pop @@ -269,9 +266,6 @@ class UserDictMixinTest(mapping_tests.TestMappingProtocol): self.assertEqual(s.keys(), [10, 30]) ## Now, test the DictMixin methods one by one - # has_key - self.assert_(s.has_key(10)) - self.assert_(not s.has_key(20)) # __contains__ self.assert_(10 in s) diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 1f65010..a4fb7f3 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -739,7 +739,7 @@ class MappingTestCase(TestBase): def test_weak_keys(self): # # This exercises d.copy(), d.items(), d[] = v, d[], del d[], - # len(d), d.has_key(). + # len(d), k in d. # dict, objects = self.make_weak_keyed_dict() for o in objects: @@ -761,8 +761,8 @@ class MappingTestCase(TestBase): "deleting the keys did not clear the dictionary") o = Object(42) dict[o] = "What is the meaning of the universe?" - self.assert_(dict.has_key(o)) - self.assert_(not dict.has_key(34)) + self.assert_(o in dict) + self.assert_(34 not in dict) def test_weak_keyed_iters(self): dict, objects = self.make_weak_keyed_dict() @@ -774,7 +774,7 @@ class MappingTestCase(TestBase): objects2 = list(objects) for wr in refs: ob = wr() - self.assert_(dict.has_key(ob)) + self.assert_(ob in dict) self.assert_(ob in dict) self.assertEqual(ob.arg, dict[ob]) objects2.remove(ob) @@ -785,7 +785,7 @@ class MappingTestCase(TestBase): self.assertEqual(len(list(dict.iterkeyrefs())), len(objects)) for wr in dict.iterkeyrefs(): ob = wr() - self.assert_(dict.has_key(ob)) + self.assert_(ob in dict) self.assert_(ob in dict) self.assertEqual(ob.arg, dict[ob]) objects2.remove(ob) @@ -900,13 +900,13 @@ class MappingTestCase(TestBase): weakdict = klass() o = weakdict.setdefault(key, value1) self.assert_(o is value1) - self.assert_(weakdict.has_key(key)) + self.assert_(key in weakdict) self.assert_(weakdict.get(key) is value1) self.assert_(weakdict[key] is value1) o = weakdict.setdefault(key, value2) self.assert_(o is value1) - self.assert_(weakdict.has_key(key)) + self.assert_(key in weakdict) self.assert_(weakdict.get(key) is value1) self.assert_(weakdict[key] is value1) @@ -920,20 +920,20 @@ class MappingTestCase(TestBase): def check_update(self, klass, dict): # - # This exercises d.update(), len(d), d.keys(), d.has_key(), + # This exercises d.update(), len(d), d.keys(), k in d, # d.get(), d[]. # weakdict = klass() weakdict.update(dict) self.assert_(len(weakdict) == len(dict)) for k in weakdict.keys(): - self.assert_(dict.has_key(k), + self.assert_(k in dict, "mysterious new key appeared in weak dict") v = dict.get(k) self.assert_(v is weakdict[k]) self.assert_(v is weakdict.get(k)) for k in dict.keys(): - self.assert_(weakdict.has_key(k), + self.assert_(k in weakdict, "original key disappeared in weak dict") v = dict[k] self.assert_(v is weakdict[k]) diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py index 1ec271b..b42f437 100755 --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -341,7 +341,7 @@ class HeaderTests(TestCase): del h['foo'] # should not raise an error h['Foo'] = 'bar' - for m in h.has_key, h.__contains__, h.get, h.get_all, h.__getitem__: + for m in h.__contains__, h.get, h.get_all, h.__getitem__: self.failUnless(m('foo')) self.failUnless(m('Foo')) self.failUnless(m('FOO')) @@ -424,10 +424,10 @@ class HandlerTests(TestCase): env = handler.environ from os import environ for k,v in environ.items(): - if not empty.has_key(k): + if k not in empty: self.assertEqual(env[k],v) for k,v in empty.items(): - self.failUnless(env.has_key(k)) + self.failUnless(k in env) def testEnviron(self): h = TestHandler(X="Y") @@ -440,7 +440,7 @@ class HandlerTests(TestCase): h = BaseCGIHandler(None,None,None,{}) h.setup_environ() for key in 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors': - self.assert_(h.environ.has_key(key)) + self.assert_(key in h.environ) def testScheme(self): h=TestHandler(HTTPS="on"); h.setup_environ() |