summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/fork_wait.py3
-rw-r--r--Lib/test/mapping_tests.py18
-rw-r--r--Lib/test/pickletester.py4
-rw-r--r--Lib/test/string_tests.py2
-rw-r--r--Lib/test/test_anydbm.py6
-rwxr-xr-xLib/test/test_array.py2
-rwxr-xr-xLib/test/test_bsddb.py22
-rw-r--r--Lib/test/test_builtin.py16
-rw-r--r--Lib/test/test_cfgparser.py11
-rw-r--r--Lib/test/test_cgi.py4
-rw-r--r--Lib/test/test_compile.py4
-rw-r--r--Lib/test/test_cookie.py2
-rw-r--r--Lib/test/test_copy.py2
-rw-r--r--Lib/test/test_descr.py24
-rw-r--r--Lib/test/test_dictviews.py12
-rw-r--r--Lib/test/test_iter.py28
-rw-r--r--Lib/test/test_iterlen.py4
-rw-r--r--Lib/test/test_itertools.py4
-rw-r--r--Lib/test/test_mailbox.py16
-rw-r--r--Lib/test/test_mhlib.py4
-rw-r--r--Lib/test/test_richcmp.py4
-rw-r--r--Lib/test/test_site.py2
-rw-r--r--Lib/test/test_support.py5
-rw-r--r--Lib/test/test_urllib2.py5
-rw-r--r--Lib/test/test_userdict.py10
-rw-r--r--Lib/test/test_uuid.py2
-rw-r--r--Lib/test/test_weakref.py10
-rw-r--r--Lib/test/test_xmlrpc.py2
28 files changed, 107 insertions, 121 deletions
diff --git a/Lib/test/fork_wait.py b/Lib/test/fork_wait.py
index 7eb55f6..9c4df4b 100644
--- a/Lib/test/fork_wait.py
+++ b/Lib/test/fork_wait.py
@@ -51,8 +51,7 @@ class ForkWait(unittest.TestCase):
time.sleep(LONGSLEEP)
- a = self.alive.keys()
- a.sort()
+ a = sorted(self.alive.keys())
self.assertEquals(a, range(NUM_THREADS))
prefork_lives = self.alive.copy()
diff --git a/Lib/test/mapping_tests.py b/Lib/test/mapping_tests.py
index 6b872c4..25fec4e 100644
--- a/Lib/test/mapping_tests.py
+++ b/Lib/test/mapping_tests.py
@@ -73,13 +73,13 @@ class BasicTestMappingProtocol(unittest.TestCase):
self.assert_(hasattr(iter, '__iter__'))
x = list(iter)
self.assert_(set(x)==set(lst)==set(ref))
- check_iterandlist(d.iterkeys(), d.keys(), self.reference.keys())
+ check_iterandlist(d.keys(), d.keys(), self.reference.keys())
check_iterandlist(iter(d), d.keys(), self.reference.keys())
- check_iterandlist(d.itervalues(), d.values(), self.reference.values())
- check_iterandlist(d.iteritems(), d.items(), self.reference.items())
+ check_iterandlist(d.values(), d.values(), self.reference.values())
+ check_iterandlist(d.items(), d.items(), self.reference.items())
#get
- key, value = d.iteritems().next()
- knownkey, knownvalue = self.other.iteritems().next()
+ key, value = d.items().next()
+ knownkey, knownvalue = self.other.items().next()
self.assertEqual(d.get(key, knownvalue), value)
self.assertEqual(d.get(knownkey, knownvalue), knownvalue)
self.failIf(knownkey in d)
@@ -104,8 +104,8 @@ class BasicTestMappingProtocol(unittest.TestCase):
self.assertEqual(dict(p), self.reference)
d = self._full_mapping(self.reference)
#setdefault
- key, value = d.iteritems().next()
- knownkey, knownvalue = self.other.iteritems().next()
+ key, value = d.items().next()
+ knownkey, knownvalue = self.other.items().next()
self.assertEqual(d.setdefault(key, knownvalue), value)
self.assertEqual(d[key], value)
self.assertEqual(d.setdefault(knownkey, knownvalue), knownvalue)
@@ -183,7 +183,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
# Iterator
d = self._empty_mapping()
- d.update(self.other.iteritems())
+ d.update(self.other.items())
self.assertEqual(d.items(), self.other.items())
# FIXME: Doesn't work with UserDict
@@ -400,7 +400,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
# iterator
d = self._full_mapping({1:3, 2:4})
- d.update(self._full_mapping({1:2, 3:4, 5:6}).iteritems())
+ d.update(self._full_mapping({1:2, 3:4, 5:6}).items())
self.assertEqual(d, {1:2, 2:4, 3:4, 5:6})
class SimpleUserDict:
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 5d340b3..cb4b431 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -438,7 +438,7 @@ class AbstractPickleTests(unittest.TestCase):
for proto in protocols:
s = self.dumps(d, proto)
x = self.loads(s)
- self.assertEqual(x.keys(), [1])
+ self.assertEqual(list(x.keys()), [1])
self.assert_(x[1] is x)
def test_recursive_inst(self):
@@ -461,7 +461,7 @@ class AbstractPickleTests(unittest.TestCase):
x = self.loads(s)
self.assertEqual(len(x), 1)
self.assertEqual(dir(x[0]), dir(i))
- self.assertEqual(x[0].attr.keys(), [1])
+ self.assertEqual(list(x[0].attr.keys()), [1])
self.assert_(x[0].attr[1] is x)
def test_garyp(self):
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 17e3389..e6b419f 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -40,7 +40,7 @@ class CommonTest(unittest.TestCase):
elif isinstance(obj, dict):
return dict([
(self.fixtype(key), self.fixtype(value))
- for (key, value) in obj.iteritems()
+ for (key, value) in obj.items()
])
else:
return obj
diff --git a/Lib/test/test_anydbm.py b/Lib/test/test_anydbm.py
index 0cdc2c3..46d46d9 100644
--- a/Lib/test/test_anydbm.py
+++ b/Lib/test/test_anydbm.py
@@ -72,10 +72,8 @@ class AnyDBMTestCase(unittest.TestCase):
f.close()
def keys_helper(self, f):
- keys = f.keys()
- keys.sort()
- dkeys = self._dict.keys()
- dkeys.sort()
+ keys = sorted(f.keys())
+ dkeys = sorted(self._dict.keys())
self.assertEqual(keys, dkeys)
return keys
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 6abfb90..692760c 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -729,7 +729,7 @@ class CharacterTest(StringTest):
self.assertEqual(s.color, "blue")
s.color = "red"
self.assertEqual(s.color, "red")
- self.assertEqual(s.__dict__.keys(), ["color"])
+ self.assertEqual(list(s.__dict__.keys()), ["color"])
def test_nounicode(self):
a = array.array(self.typecode, self.example)
diff --git a/Lib/test/test_bsddb.py b/Lib/test/test_bsddb.py
index 3b33c48..d7f1177 100755
--- a/Lib/test/test_bsddb.py
+++ b/Lib/test/test_bsddb.py
@@ -15,7 +15,7 @@ class TestBSDDB(unittest.TestCase):
def setUp(self):
self.f = self.openmethod[0](self.fname, self.openflag, cachesize=32768)
self.d = dict(q='Guido', w='van', e='Rossum', r='invented', t='Python', y='')
- for k, v in self.d.iteritems():
+ for k, v in self.d.items():
self.f[k] = v
def tearDown(self):
@@ -29,7 +29,7 @@ class TestBSDDB(unittest.TestCase):
pass
def test_getitem(self):
- for k, v in self.d.iteritems():
+ for k, v in self.d.items():
self.assertEqual(self.f[k], v)
def test_len(self):
@@ -48,7 +48,7 @@ class TestBSDDB(unittest.TestCase):
return
self.f.close()
self.f = self.openmethod[0](self.fname, 'w')
- for k, v in self.d.iteritems():
+ for k, v in self.d.items():
self.assertEqual(self.f[k], v)
def assertSetEquals(self, seqn1, seqn2):
@@ -61,9 +61,9 @@ class TestBSDDB(unittest.TestCase):
self.assertSetEquals(d.keys(), f.keys())
self.assertSetEquals(d.values(), f.values())
self.assertSetEquals(d.items(), f.items())
- self.assertSetEquals(d.iterkeys(), f.iterkeys())
- self.assertSetEquals(d.itervalues(), f.itervalues())
- self.assertSetEquals(d.iteritems(), f.iteritems())
+ self.assertSetEquals(d.keys(), f.keys())
+ self.assertSetEquals(d.values(), f.values())
+ self.assertSetEquals(d.items(), f.items())
def test_iter_while_modifying_values(self):
if not hasattr(self.f, '__iter__'):
@@ -94,7 +94,7 @@ class TestBSDDB(unittest.TestCase):
if not hasattr(self.f, 'iteritems'):
return
- di = self.d.iteritems()
+ di = self.d.items()
while 1:
try:
k, v = di.next()
@@ -105,7 +105,7 @@ class TestBSDDB(unittest.TestCase):
# it should behave the same as a dict. modifying values
# of existing keys should not break iteration. (adding
# or removing keys should)
- fi = self.f.iteritems()
+ fi = self.f.items()
while 1:
try:
k, v = fi.next()
@@ -159,7 +159,7 @@ class TestBSDDB(unittest.TestCase):
# test the iterator interface (if present)
if hasattr(self.f, 'iteritems'):
if debug: print("D")
- i = self.f.iteritems()
+ i = self.f.items()
k,v = i.next()
if debug: print("E")
self.f[k] = "please don't deadlock"
@@ -198,7 +198,7 @@ class TestBSDDB(unittest.TestCase):
# do the bsddb._DBWithCursor _iter_mixin internals leak cursors?
nc1 = len(self.f._cursor_refs)
# create iterator
- i = self.f.iteritems()
+ i = self.f.items()
nc2 = len(self.f._cursor_refs)
# use the iterator (should run to the first yeild, creating the cursor)
k, v = i.next()
@@ -240,7 +240,7 @@ class TestBSDDB(unittest.TestCase):
new = dict(y='life', u='of', i='brian')
self.f.update(new)
self.d.update(new)
- for k, v in self.d.iteritems():
+ for k, v in self.d.items():
self.assertEqual(self.f[k], v)
def test_keyordering(self):
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index ab9dfc8..b6ac990 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -290,8 +290,8 @@ class BuiltinTest(unittest.TestCase):
if key == 'a':
return 12
raise KeyError
- def keys(self):
- return list('xyz')
+ def __iter__(self):
+ return iter('xyz')
m = M()
g = globals()
@@ -313,8 +313,8 @@ class BuiltinTest(unittest.TestCase):
if key == 'a':
return 12
return dict.__getitem__(self, key)
- def keys(self):
- return list('xyz')
+ def __iter__(self):
+ return iter('xyz')
d = D()
self.assertEqual(eval('a', g, d), 12)
@@ -346,8 +346,8 @@ class BuiltinTest(unittest.TestCase):
class C:
def __getitem__(self, item):
raise KeyError(item)
- def keys(self):
- return 'a'
+ def __iter__(self):
+ return 'a' # XXX Not quite faithful to the SF bug...
self.assertRaises(TypeError, eval, 'dir()', globals(), C())
# Done outside of the method test_z to get the correct scope
@@ -522,8 +522,8 @@ class BuiltinTest(unittest.TestCase):
unicode("123"): unicode("112233")
}
- for (cls, inps) in inputs.iteritems():
- for (inp, exp) in inps.iteritems():
+ for (cls, inps) in inputs.items():
+ for (inp, exp) in inps.items():
# make sure the output goes through __getitem__
# even if func is None
self.assertEqual(
diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py
index 8aa1df3..2295772 100644
--- a/Lib/test/test_cfgparser.py
+++ b/Lib/test/test_cfgparser.py
@@ -7,18 +7,13 @@ from test import test_support
class SortedDict(UserDict.UserDict):
def items(self):
- result = self.data.items()
- result.sort()
- return result
+ return sorted(self.data.items())
def keys(self):
- result = self.data.keys()
- result.sort()
- return result
+ return sorted(self.data.keys())
def values(self):
- result = self.items()
- return [i[1] for i in values]
+ return [i[1] for i in self.items()]
def iteritems(self): return iter(self.items())
def iterkeys(self): return iter(self.keys())
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
index 9cf6a12..260d9b2 100644
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -118,9 +118,7 @@ parse_strict_test_cases = [
]
def norm(seq):
- if isinstance(seq, list):
- seq.sort(key=repr)
- return seq
+ return sorted(seq, key=repr)
def first_elts(list):
return map(lambda x:x[0], list)
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 1acb4a1..2b5a135 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -53,8 +53,8 @@ class TestSpecifics(unittest.TestCase):
raise KeyError
def __setitem__(self, key, value):
self.results = (key, value)
- def keys(self):
- return list('xyz')
+ def __iter__(self):
+ return iter('xyz')
m = M()
g = globals()
diff --git a/Lib/test/test_cookie.py b/Lib/test/test_cookie.py
index e7c0cf1..e4c8975 100644
--- a/Lib/test/test_cookie.py
+++ b/Lib/test/test_cookie.py
@@ -38,7 +38,7 @@ class CookieTests(unittest.TestCase):
C.load(case['data'])
self.assertEqual(repr(C), case['repr'])
self.assertEqual(C.output(sep='\n'), case['output'])
- for k, v in sorted(case['dict'].iteritems()):
+ for k, v in sorted(case['dict'].items()):
self.assertEqual(C[k].value, v)
def test_load(self):
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index 8a32866..cb075c3 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -491,7 +491,7 @@ class TestCopy(unittest.TestCase):
def test_reduce_5tuple(self):
class C(dict):
def __reduce__(self):
- return (C, (), self.__dict__, None, self.iteritems())
+ return (C, (), self.__dict__, None, self.items())
def __eq__(self, other):
return (dict(self) == dict(other) and
self.__dict__ == other.__dict__)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index aab3331..d369cf6 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -183,7 +183,7 @@ def dict_constructor():
d = dict({1: 2, 'a': 'b'})
vereq(d, {1: 2, 'a': 'b'})
vereq(d, dict(d.items()))
- vereq(d, dict(d.iteritems()))
+ vereq(d, dict(d.items()))
d = dict({'one':1, 'two':2})
vereq(d, dict(one=1, two=2))
vereq(d, dict(**d))
@@ -541,10 +541,10 @@ def spamdicts():
class C(spam.spamdict):
def foo(self): return 1
a = C()
- vereq(a.items(), [])
+ vereq(list(a.items()), [])
vereq(a.foo(), 1)
a['foo'] = 'bar'
- vereq(a.items(), [('foo', 'bar')])
+ vereq(list(a.items()), [('foo', 'bar')])
vereq(a.getstate(), 0)
a.setstate(100)
vereq(a.getstate(), 100)
@@ -714,7 +714,7 @@ def metaclass():
# named _get_x and/or _set_x are found
def __new__(metaclass, name, bases, dict):
hits = {}
- for key, val in dict.iteritems():
+ for key, val in dict.items():
if key.startswith("_get_"):
key = key[5:]
get, set = hits.get(key, (None, None))
@@ -725,7 +725,7 @@ def metaclass():
get, set = hits.get(key, (None, None))
set = val
hits[key] = get, set
- for key, (get, set) in hits.iteritems():
+ for key, (get, set) in hits.items():
dict[key] = property(get, set)
return super(autoproperty, metaclass).__new__(metaclass,
name, bases, dict)
@@ -820,9 +820,9 @@ def multi():
type({}).__init__(self)
C.__init__(self)
d = D()
- vereq(d.keys(), [])
+ vereq(list(d.keys()), [])
d["hello"] = "world"
- vereq(d.items(), [("hello", "world")])
+ vereq(list(d.items()), [("hello", "world")])
vereq(d["hello"], "world")
vereq(d.getstate(), 0)
d.setstate(10)
@@ -2676,9 +2676,7 @@ def pickles():
cPickle = None
def sorteditems(d):
- L = d.items()
- L.sort()
- return L
+ return sorted(d.items())
global C
class C(object):
@@ -3193,7 +3191,7 @@ def dictproxyiterkeys():
def meth(self):
pass
if verbose: print("Testing dict-proxy iterkeys...")
- keys = [ key for key in C.__dict__.iterkeys() ]
+ keys = [ key for key in C.__dict__.keys() ]
keys.sort()
vereq(keys, ['__dict__', '__doc__', '__module__', '__weakref__', 'meth'])
@@ -3202,7 +3200,7 @@ def dictproxyitervalues():
def meth(self):
pass
if verbose: print("Testing dict-proxy itervalues...")
- values = [ values for values in C.__dict__.itervalues() ]
+ values = [ values for values in C.__dict__.values() ]
vereq(len(values), 5)
def dictproxyiteritems():
@@ -3210,7 +3208,7 @@ def dictproxyiteritems():
def meth(self):
pass
if verbose: print("Testing dict-proxy iteritems...")
- keys = [ key for (key, value) in C.__dict__.iteritems() ]
+ keys = [ key for (key, value) in C.__dict__.items() ]
keys.sort()
vereq(keys, ['__dict__', '__doc__', '__module__', '__weakref__', 'meth'])
diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py
index 4c436f7..607d182 100644
--- a/Lib/test/test_dictviews.py
+++ b/Lib/test/test_dictviews.py
@@ -4,19 +4,19 @@ from test import test_support
class DictSetTest(unittest.TestCase):
def test_constructors_not_callable(self):
- kt = type({}.KEYS())
+ kt = type({}.keys())
self.assertRaises(TypeError, kt, {})
self.assertRaises(TypeError, kt)
- it = type({}.ITEMS())
+ it = type({}.items())
self.assertRaises(TypeError, it, {})
self.assertRaises(TypeError, it)
- vt = type({}.VALUES())
+ vt = type({}.values())
self.assertRaises(TypeError, vt, {})
self.assertRaises(TypeError, vt)
def test_dict_keys(self):
d = {1: 10, "a": "ABC"}
- keys = d.KEYS()
+ keys = d.keys()
self.assertEqual(set(keys), {1, "a"})
self.assertEqual(len(keys), 2)
self.assert_(1 in keys)
@@ -26,7 +26,7 @@ class DictSetTest(unittest.TestCase):
def test_dict_items(self):
d = {1: 10, "a": "ABC"}
- items = d.ITEMS()
+ items = d.items()
self.assertEqual(set(items), {(1, 10), ("a", "ABC")})
self.assertEqual(len(items), 2)
self.assert_((1, 10) in items)
@@ -39,7 +39,7 @@ class DictSetTest(unittest.TestCase):
def test_dict_values(self):
d = {1: 10, "a": "ABC"}
- values = d.VALUES()
+ values = d.values()
self.assertEqual(set(values), {10, "ABC"})
self.assertEqual(len(values), 2)
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py
index 76af429..24a4f77 100644
--- a/Lib/test/test_iter.py
+++ b/Lib/test/test_iter.py
@@ -365,8 +365,8 @@ class TestCase(unittest.TestCase):
d = {"one": 1, "two": 2, "three": 3}
self.assertEqual(max(d), "two")
self.assertEqual(min(d), "one")
- self.assertEqual(max(d.itervalues()), 3)
- self.assertEqual(min(iter(d.itervalues())), 1)
+ self.assertEqual(max(d.values()), 3)
+ self.assertEqual(min(iter(d.values())), 1)
f = open(TESTFN, "w")
try:
@@ -402,7 +402,7 @@ class TestCase(unittest.TestCase):
for i in range(5)]
self.assertEqual(map(None, d,
SequenceClass(5),
- iter(d.iterkeys())),
+ iter(d.keys())),
expected)
f = open(TESTFN, "w")
@@ -437,7 +437,7 @@ class TestCase(unittest.TestCase):
[(0,), (1,), (2,)])
d = {"one": 1, "two": 2, "three": 3}
- self.assertEqual(d.items(), list(zip(d, d.itervalues())))
+ self.assertEqual(d.items(), list(zip(d, d.values())))
# Generate all ints starting at constructor arg.
class IntsFrom:
@@ -559,13 +559,13 @@ class TestCase(unittest.TestCase):
d = {"one": 1, "two": 2, "three": 3, 1j: 2j}
for k in d:
self.assert_(k in d)
- self.assert_(k not in d.itervalues())
+ self.assert_(k not in d.values())
for v in d.values():
- self.assert_(v in d.itervalues())
+ self.assert_(v in d.values())
self.assert_(v not in d)
- for k, v in d.iteritems():
- self.assert_((k, v) in d.iteritems())
- self.assert_((v, k) not in d.iteritems())
+ for k, v in d.items():
+ self.assert_((k, v) in d.items())
+ self.assert_((v, k) not in d.items())
f = open(TESTFN, "w")
try:
@@ -600,9 +600,9 @@ class TestCase(unittest.TestCase):
d = {"one": 3, "two": 3, "three": 3, 1j: 2j}
for k in d:
self.assertEqual(countOf(d, k), 1)
- self.assertEqual(countOf(d.itervalues(), 3), 3)
- self.assertEqual(countOf(d.itervalues(), 2j), 1)
- self.assertEqual(countOf(d.itervalues(), 1j), 0)
+ self.assertEqual(countOf(d.values(), 3), 3)
+ self.assertEqual(countOf(d.values(), 2j), 1)
+ self.assertEqual(countOf(d.values(), 1j), 0)
f = open(TESTFN, "w")
try:
@@ -744,7 +744,7 @@ class TestCase(unittest.TestCase):
else:
self.fail("should have raised TypeError")
- a, b, c = {1: 42, 2: 42, 3: 42}.itervalues()
+ a, b, c = {1: 42, 2: 42, 3: 42}.values()
self.assertEqual((a, b, c), (42, 42, 42))
f = open(TESTFN, "w")
@@ -841,7 +841,7 @@ class TestCase(unittest.TestCase):
# XXX For a more thorough test, see towards the end of:
# http://mail.python.org/pipermail/python-dev/2002-July/026512.html
a = {1:1, 2:2, 0:0, 4:4, 3:3}
- for b in iter(a), a.iterkeys(), a.iteritems(), a.itervalues():
+ for b in iter(a), a.keys(), a.items(), a.values():
b = iter(a)
self.assertEqual(len(list(b)), 5)
self.assertEqual(list(b), [])
diff --git a/Lib/test/test_iterlen.py b/Lib/test/test_iterlen.py
index af4467e..e9a6a68 100644
--- a/Lib/test/test_iterlen.py
+++ b/Lib/test/test_iterlen.py
@@ -139,14 +139,14 @@ class TestDictItems(TestTemporarilyImmutable):
def setUp(self):
d = dict.fromkeys(xrange(n))
- self.it = d.iteritems()
+ self.it = d.items()
self.mutate = d.popitem
class TestDictValues(TestTemporarilyImmutable):
def setUp(self):
d = dict.fromkeys(xrange(n))
- self.it = d.itervalues()
+ self.it = d.values()
self.mutate = d.popitem
class TestSet(TestTemporarilyImmutable):
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index a083e7c..ac30495 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -790,7 +790,7 @@ Samuele
>>> from operator import itemgetter
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
->>> di = sorted(sorted(d.iteritems()), key=itemgetter(1))
+>>> di = sorted(sorted(d.items()), key=itemgetter(1))
>>> for k, g in groupby(di, itemgetter(1)):
... print(k, map(itemgetter(0), g))
...
@@ -823,7 +823,7 @@ Samuele
... return imap(function, count())
>>> def iteritems(mapping):
-... return izip(mapping.iterkeys(), mapping.itervalues())
+... return izip(mapping.keys(), mapping.values())
>>> def nth(iterable, n):
... "Returns the nth item"
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index eb675f6..181e32b 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -24,7 +24,7 @@ class TestBase(unittest.TestCase):
# Inspect a mailbox.Message representation of the sample message
self.assert_(isinstance(msg, email.message.Message))
self.assert_(isinstance(msg, mailbox.Message))
- for key, value in _sample_headers.iteritems():
+ for key, value in _sample_headers.items():
self.assert_(value in msg.get_all(key))
self.assert_(msg.is_multipart())
self.assert_(len(msg.get_payload()) == len(_sample_payloads))
@@ -174,7 +174,7 @@ class TestMailbox(TestBase):
def test_iterkeys(self):
# Get keys using iterkeys()
- self._check_iteration(self._box.iterkeys, do_keys=True, do_values=False)
+ self._check_iteration(self._box.keys, do_keys=True, do_values=False)
def test_keys(self):
# Get keys using keys()
@@ -182,7 +182,7 @@ class TestMailbox(TestBase):
def test_itervalues(self):
# Get values using itervalues()
- self._check_iteration(self._box.itervalues, do_keys=False,
+ self._check_iteration(self._box.values, do_keys=False,
do_values=True)
def test_iter(self):
@@ -196,7 +196,7 @@ class TestMailbox(TestBase):
def test_iteritems(self):
# Get keys and values using iteritems()
- self._check_iteration(self._box.iteritems, do_keys=True,
+ self._check_iteration(self._box.items, do_keys=True,
do_values=True)
def test_items(self):
@@ -424,12 +424,12 @@ class TestMailboxSuperclass(TestBase):
self.assertRaises(NotImplementedError, lambda: box.__delitem__(''))
self.assertRaises(NotImplementedError, lambda: box.discard(''))
self.assertRaises(NotImplementedError, lambda: box.__setitem__('', ''))
- self.assertRaises(NotImplementedError, lambda: box.iterkeys())
self.assertRaises(NotImplementedError, lambda: box.keys())
- self.assertRaises(NotImplementedError, lambda: box.itervalues().next())
+ self.assertRaises(NotImplementedError, lambda: box.keys())
+ self.assertRaises(NotImplementedError, lambda: box.values().next())
self.assertRaises(NotImplementedError, lambda: box.__iter__().next())
self.assertRaises(NotImplementedError, lambda: box.values())
- self.assertRaises(NotImplementedError, lambda: box.iteritems().next())
+ self.assertRaises(NotImplementedError, lambda: box.items().next())
self.assertRaises(NotImplementedError, lambda: box.items())
self.assertRaises(NotImplementedError, lambda: box.get(''))
self.assertRaises(NotImplementedError, lambda: box.__getitem__(''))
@@ -709,7 +709,7 @@ class _TestMboxMMDF(TestMailbox):
mtime = os.path.getmtime(self._path)
self._box = self._factory(self._path)
self.assert_(len(self._box) == 3)
- for key in self._box.iterkeys():
+ for key in self._box.keys():
self.assert_(self._box.get_string(key) in values)
self._box.close()
self.assert_(mtime == os.path.getmtime(self._path))
diff --git a/Lib/test/test_mhlib.py b/Lib/test/test_mhlib.py
index a6dc00a..5c8b40d 100644
--- a/Lib/test/test_mhlib.py
+++ b/Lib/test/test_mhlib.py
@@ -46,7 +46,7 @@ def readFile(fname):
return r
def writeProfile(dict):
- contents = [ "%s: %s\n" % (k, v) for k, v in dict.iteritems() ]
+ contents = [ "%s: %s\n" % (k, v) for k, v in dict.items() ]
writeFile(_mhprofile, "".join(contents))
def writeContext(folder):
@@ -61,7 +61,7 @@ def writeCurMessage(folder, cur):
def writeMessage(folder, n, headers, body):
folder = normF(folder)
- headers = "".join([ "%s: %s\n" % (k, v) for k, v in headers.iteritems() ])
+ headers = "".join([ "%s: %s\n" % (k, v) for k, v in headers.items() ])
contents = "%s\n%s\n" % (headers,body)
mkdirs(os.path.join(_mhpath, folder))
writeFile(os.path.join(_mhpath, folder, str(n)), contents)
diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py
index 9c4a7a0..72a6de8 100644
--- a/Lib/test/test_richcmp.py
+++ b/Lib/test/test_richcmp.py
@@ -131,7 +131,7 @@ class VectorTest(unittest.TestCase):
self.checkequal("gt", a, b, [False, False, False, True, True ])
self.checkequal("ge", a, b, [False, False, True, True, True ])
- for ops in opmap.itervalues():
+ for ops in opmap.values():
for op in ops:
# calls __bool__, which should fail
self.assertRaises(TypeError, bool, op(a, b))
@@ -150,7 +150,7 @@ class NumberTest(unittest.TestCase):
continue # the combination int, int is useless
ta = typea(a)
tb = typeb(b)
- for ops in opmap.itervalues():
+ for ops in opmap.values():
for op in ops:
realoutcome = op(a, b)
testoutcome = op(ta, tb)
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 6f32fca..11bb674 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -204,7 +204,7 @@ class ImportSideEffectTests(unittest.TestCase):
if sys.platform == "win32":
import locale
if locale.getdefaultlocale()[1].startswith('cp'):
- for value in encodings.aliases.aliases.itervalues():
+ for value in encodings.aliases.aliases.values():
if value == "mbcs":
break
else:
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 6cc52ea..8b5f73c 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -239,8 +239,7 @@ def vereq(a, b):
def sortdict(dict):
"Like repr(dict), but in sorted order."
- items = dict.items()
- items.sort()
+ items = sorted(dict.items())
reprpairs = ["%r: %r" % pair for pair in items]
withcommas = ", ".join(reprpairs)
return "{%s}" % withcommas
@@ -305,7 +304,7 @@ class EnvironmentVarGuard(object):
return self
def __exit__(self, *ignore_exc):
- for envvar, value in self._reset.iteritems():
+ for envvar, value in self._reset.items():
self._environ[envvar] = value
for unset in self._unset:
del self._environ[unset]
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 0ea606f..6187dad 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -90,8 +90,7 @@ def test_request_headers_methods():
>>> r.header_items()
[('Spam-eggs', 'blah')]
>>> r.add_header("Foo-Bar", "baz")
- >>> items = r.header_items()
- >>> items.sort()
+ >>> items = sorted(r.header_items())
>>> items
[('Foo-bar', 'baz'), ('Spam-eggs', 'blah')]
@@ -235,7 +234,7 @@ class MockFile:
class MockHeaders(dict):
def getheaders(self, name):
- return self.values()
+ return list(self.values())
class MockResponse(StringIO.StringIO):
def __init__(self, code, msg, headers, data, url=None):
diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py
index a7fc60a..05d6d9e 100644
--- a/Lib/test/test_userdict.py
+++ b/Lib/test/test_userdict.py
@@ -208,7 +208,7 @@ class SeqDict(UserDict.DictMixin):
if other is not None:
for (key, value) in other:
self[key] = value
- for (key, value) in kwargs.iteritems():
+ for (key, value) in kwargs.items():
self[key] = value
def __getitem__(self, key):
try:
@@ -234,7 +234,7 @@ class SeqDict(UserDict.DictMixin):
return list(self.keylist)
def copy(self):
d = self.__class__()
- for key, value in self.iteritems():
+ for key, value in self.items():
d[key] = value
return d
@classmethod
@@ -278,13 +278,13 @@ class UserDictMixinTest(mapping_tests.TestMappingProtocol):
self.assertEqual(len(s), 2)
# iteritems
- self.assertEqual(list(s.iteritems()), [(10,'ten'), (30, 'thirty')])
+ self.assertEqual(list(s.items()), [(10,'ten'), (30, 'thirty')])
# iterkeys
- self.assertEqual(list(s.iterkeys()), [10, 30])
+ self.assertEqual(list(s.keys()), [10, 30])
# itervalues
- self.assertEqual(list(s.itervalues()), ['ten', 'thirty'])
+ self.assertEqual(list(s.values()), ['ten', 'thirty'])
# values
self.assertEqual(s.values(), ['ten', 'thirty'])
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
index 3e5f77d..ad3b0b3 100644
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -295,7 +295,7 @@ class TestUUID(TestCase):
if TestUUID.last_node:
if TestUUID.last_node != node:
msg = "different sources disagree on node:\n"
- for s, n in TestUUID.source2node.iteritems():
+ for s, n in TestUUID.source2node.items():
msg += " from source %r, node was %012x\n" % (s, n)
# There's actually no reason to expect the MAC addresses
# to agree across various methods -- e.g., a box may have
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 76169f7..1213b57 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -839,7 +839,7 @@ class MappingTestCase(TestBase):
def check_iters(self, dict):
# item iterator:
items = dict.items()
- for item in dict.iteritems():
+ for item in dict.items():
items.remove(item)
self.assert_(len(items) == 0, "iteritems() did not touch all items")
@@ -851,13 +851,13 @@ class MappingTestCase(TestBase):
# key iterator, via iterkeys():
keys = dict.keys()
- for k in dict.iterkeys():
+ for k in dict.keys():
keys.remove(k)
self.assert_(len(keys) == 0, "iterkeys() did not touch all keys")
# value iterator:
values = dict.values()
- for v in dict.itervalues():
+ for v in dict.values():
values.remove(v)
self.assert_(len(values) == 0,
"itervalues() did not touch all values")
@@ -1093,7 +1093,7 @@ None
... def __init__(self, ob, callback=None, **annotations):
... super(ExtendedRef, self).__init__(ob, callback)
... self.__counter = 0
-... for k, v in annotations.iteritems():
+... for k, v in annotations.items():
... setattr(self, k, v)
... def __call__(self):
... '''Return a pair containing the referent and the number of
@@ -1104,7 +1104,7 @@ None
... self.__counter += 1
... ob = (ob, self.__counter)
... return ob
-...
+...
>>> class A: # not in docs from here, just testing the ExtendedRef
... pass
...
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 795e097..0798fa1 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -145,7 +145,7 @@ class XMLRPCTestCase(unittest.TestCase):
if not setdefaultencoding_existed:
del sys.setdefaultencoding
- items = d.items()
+ items = list(d.items())
if have_unicode:
self.assertEquals(s, u"abc \x95")
self.assert_(isinstance(s, unicode))