[Python-3000-checkins] r56139 - in python/branches/p3yk/Lib: cgi.py csv.py difflib.py distutils/version.py filecmp.py test/test_bisect.py test/test_bytes.py test/test_cgi.py test/test_datetime.py test/test_decimal.py test/test_extcall.py test/test_functools.py test/test_genexps.py test/test_grp.py test/test_hash.py test/test_inspect.py

georg.brandl python-3000-checkins at python.org
Sun Jul 1 18:20:59 CEST 2007


Author: georg.brandl
Date: Sun Jul  1 18:20:58 2007
New Revision: 56139

Modified:
   python/branches/p3yk/Lib/cgi.py
   python/branches/p3yk/Lib/csv.py
   python/branches/p3yk/Lib/difflib.py
   python/branches/p3yk/Lib/distutils/version.py
   python/branches/p3yk/Lib/filecmp.py
   python/branches/p3yk/Lib/test/test_bisect.py
   python/branches/p3yk/Lib/test/test_bytes.py
   python/branches/p3yk/Lib/test/test_cgi.py
   python/branches/p3yk/Lib/test/test_datetime.py
   python/branches/p3yk/Lib/test/test_decimal.py
   python/branches/p3yk/Lib/test/test_extcall.py
   python/branches/p3yk/Lib/test/test_functools.py
   python/branches/p3yk/Lib/test/test_genexps.py
   python/branches/p3yk/Lib/test/test_grp.py
   python/branches/p3yk/Lib/test/test_hash.py
   python/branches/p3yk/Lib/test/test_inspect.py
Log:
Fix a few test cases after the map->imap change.


Modified: python/branches/p3yk/Lib/cgi.py
==============================================================================
--- python/branches/p3yk/Lib/cgi.py	(original)
+++ python/branches/p3yk/Lib/cgi.py	Sun Jul  1 18:20:58 2007
@@ -575,7 +575,7 @@
         if key in self:
             value = self[key]
             if type(value) is type([]):
-                return map(attrgetter('value'), value)
+                return [x.value for x in value]
             else:
                 return value.value
         else:
@@ -597,7 +597,7 @@
         if key in self:
             value = self[key]
             if type(value) is type([]):
-                return map(attrgetter('value'), value)
+                return [x.value for x in value]
             else:
                 return [value.value]
         else:

Modified: python/branches/p3yk/Lib/csv.py
==============================================================================
--- python/branches/p3yk/Lib/csv.py	(original)
+++ python/branches/p3yk/Lib/csv.py	Sun Jul  1 18:20:58 2007
@@ -256,7 +256,7 @@
         additional chunks as necessary.
         """
 
-        data = filter(None, data.split('\n'))
+        data = list(filter(None, data.split('\n')))
 
         ascii = [chr(c) for c in range(127)] # 7-bit ASCII
 

Modified: python/branches/p3yk/Lib/difflib.py
==============================================================================
--- python/branches/p3yk/Lib/difflib.py	(original)
+++ python/branches/p3yk/Lib/difflib.py	Sun Jul  1 18:20:58 2007
@@ -587,7 +587,7 @@
         Each group is in the same format as returned by get_opcodes().
 
         >>> from pprint import pprint
-        >>> a = map(str, range(1,40))
+        >>> a = list(map(str, range(1,40)))
         >>> b = a[:]
         >>> b[8:8] = ['i']     # Make an insertion
         >>> b[20] += 'x'       # Make a replacement

Modified: python/branches/p3yk/Lib/distutils/version.py
==============================================================================
--- python/branches/p3yk/Lib/distutils/version.py	(original)
+++ python/branches/p3yk/Lib/distutils/version.py	Sun Jul  1 18:20:58 2007
@@ -148,7 +148,7 @@
         if patch:
             self.version = tuple(map(int, [major, minor, patch]))
         else:
-            self.version = tuple(map(int, [major, minor]) + [0])
+            self.version = tuple(map(int, [major, minor])) + (0,)
 
         if prerelease:
             self.prerelease = (prerelease[0], int(prerelease_num))

Modified: python/branches/p3yk/Lib/filecmp.py
==============================================================================
--- python/branches/p3yk/Lib/filecmp.py	(original)
+++ python/branches/p3yk/Lib/filecmp.py	Sun Jul  1 18:20:58 2007
@@ -132,9 +132,9 @@
     def phase1(self): # Compute common names
         a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list))
         b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list))
-        self.common = map(a.__getitem__, ifilter(b.__contains__, a))
-        self.left_only = map(a.__getitem__, ifilterfalse(b.__contains__, a))
-        self.right_only = map(b.__getitem__, ifilterfalse(a.__contains__, b))
+        self.common = list(map(a.__getitem__, ifilter(b.__contains__, a)))
+        self.left_only = list(map(a.__getitem__, ifilterfalse(b.__contains__, a)))
+        self.right_only = list(map(b.__getitem__, ifilterfalse(a.__contains__, b)))
 
     def phase2(self): # Distinguish files, directories, funnies
         self.common_dirs = []

Modified: python/branches/p3yk/Lib/test/test_bisect.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_bisect.py	(original)
+++ python/branches/p3yk/Lib/test/test_bisect.py	Sun Jul  1 18:20:58 2007
@@ -223,7 +223,7 @@
     ...
     >>> grade(66)
     'C'
-    >>> map(grade, [33, 99, 77, 44, 12, 88])
+    >>> list(map(grade, [33, 99, 77, 44, 12, 88]))
     ['E', 'A', 'B', 'D', 'F', 'A']
 
 """

Modified: python/branches/p3yk/Lib/test/test_bytes.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_bytes.py	(original)
+++ python/branches/p3yk/Lib/test/test_bytes.py	Sun Jul  1 18:20:58 2007
@@ -157,7 +157,7 @@
                 b = bytes([ord('x')]*20)
                 n = f.readinto(b)
             self.assertEqual(n, len(short_sample))
-            self.assertEqual(list(b), map(ord, sample))
+            self.assertEqual(list(b), list(map(ord, sample)))
             # Test writing in binary mode
             with open(tfn, "wb") as f:
                 f.write(b)
@@ -171,7 +171,7 @@
                 pass
 
     def test_reversed(self):
-        input = map(ord, "Hello")
+        input = list(map(ord, "Hello"))
         b = bytes(input)
         output = list(reversed(b))
         input.reverse()
@@ -468,7 +468,7 @@
         self.assertEqual(bytes.join([]), bytes())
         self.assertEqual(bytes.join([bytes()]), bytes())
         for part in [("abc",), ("a", "bc"), ("ab", "c"), ("a", "b", "c")]:
-            lst = map(bytes, part)
+            lst = list(map(bytes, part))
             self.assertEqual(bytes.join(lst), bytes("abc"))
             self.assertEqual(bytes.join(tuple(lst)), bytes("abc"))
             self.assertEqual(bytes.join(iter(lst)), bytes("abc"))

Modified: python/branches/p3yk/Lib/test/test_cgi.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_cgi.py	(original)
+++ python/branches/p3yk/Lib/test/test_cgi.py	Sun Jul  1 18:20:58 2007
@@ -121,10 +121,11 @@
     return sorted(seq, key=repr)
 
 def first_elts(list):
-    return map(lambda x:x[0], list)
+    return [p[0] for p in list]
 
 def first_second_elts(list):
-    return map(lambda p:(p[0], p[1][0]), list)
+    return [(p[0], p[1][0]) for p in list]
+
 
 class CgiTests(unittest.TestCase):
 

Modified: python/branches/p3yk/Lib/test/test_datetime.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_datetime.py	(original)
+++ python/branches/p3yk/Lib/test/test_datetime.py	Sun Jul  1 18:20:58 2007
@@ -830,8 +830,7 @@
             320  348  376
             325  353  381
         """
-        iso_long_years = map(int, ISO_LONG_YEARS_TABLE.split())
-        iso_long_years.sort()
+        iso_long_years = sorted(map(int, ISO_LONG_YEARS_TABLE.split()))
         L = []
         for i in range(400):
             d = self.theclass(2000+i, 12, 31)

Modified: python/branches/p3yk/Lib/test/test_decimal.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_decimal.py	(original)
+++ python/branches/p3yk/Lib/test/test_decimal.py	Sun Jul  1 18:20:58 2007
@@ -39,7 +39,7 @@
     threading = None
 
 # Useful Test Constant
-Signals = getcontext().flags.keys()
+Signals = tuple(getcontext().flags.keys())
 
 # Tests are built around these assumed context defaults.
 # test_main() restores the original context.
@@ -171,7 +171,7 @@
             return self.eval_equation(s)
 
     def eval_directive(self, s):
-        funct, value = map(lambda x: x.strip().lower(), s.split(':'))
+        funct, value = (x.strip().lower() for x in s.split(':'))
         if funct == 'rounding':
             value = RoundingDict[value]
         else:
@@ -842,7 +842,7 @@
         self.assertNotEqual(da, object)
 
         # sortable
-        a = map(Decimal, range(100))
+        a = list(map(Decimal, range(100)))
         b =  a[:]
         random.shuffle(a)
         a.sort()

Modified: python/branches/p3yk/Lib/test/test_extcall.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_extcall.py	(original)
+++ python/branches/p3yk/Lib/test/test_extcall.py	Sun Jul  1 18:20:58 2007
@@ -263,8 +263,7 @@
         for vararg in ['', 'v']:
             for kwarg in ['', 'k']:
                 name = 'z' + args + defargs + vararg + kwarg
-                arglist = list(args) + map(
-                    lambda x: '%s="%s"' % (x, x), defargs)
+                arglist = list(args) + ['%s="%s"' % (x, x) for x in defargs]
                 if vararg: arglist.append('*' + vararg)
                 if kwarg: arglist.append('**' + kwarg)
                 decl = (('def %s(%s): print("ok %s", a, b, d, e, v, ' +

Modified: python/branches/p3yk/Lib/test/test_functools.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_functools.py	(original)
+++ python/branches/p3yk/Lib/test/test_functools.py	Sun Jul  1 18:20:58 2007
@@ -19,6 +19,7 @@
     """capture all positional and keyword arguments"""
     return args, kw
 
+
 class TestPartial(unittest.TestCase):
 
     thetype = functools.partial
@@ -28,7 +29,7 @@
         self.assertEqual(p(3, 4, b=30, c=40),
                          ((1, 2, 3, 4), dict(a=10, b=30, c=40)))
         p = self.thetype(map, lambda x: x*10)
-        self.assertEqual(p([1,2,3,4]), [10, 20, 30, 40])
+        self.assertEqual(list(p([1,2,3,4])), [10, 20, 30, 40])
 
     def test_attributes(self):
         p = self.thetype(capture, 1, 2, a=10, b=20)
@@ -134,7 +135,7 @@
         self.assertRaises(ReferenceError, getattr, p, 'func')
 
     def test_with_bound_and_unbound_methods(self):
-        data = map(str, range(10))
+        data = list(map(str, range(10)))
         join = self.thetype(str.join, '')
         self.assertEqual(join(data), '0123456789')
         join = self.thetype(''.join)

Modified: python/branches/p3yk/Lib/test/test_genexps.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_genexps.py	(original)
+++ python/branches/p3yk/Lib/test/test_genexps.py	Sun Jul  1 18:20:58 2007
@@ -128,7 +128,7 @@
 
 Verify re-use of tuples (a side benefit of using genexps over listcomps)
 
-    >>> tupleids = map(id, ((i,i) for i in range(10)))
+    >>> tupleids = list(map(id, ((i,i) for i in range(10))))
     >>> int(max(tupleids) - min(tupleids))
     0
 

Modified: python/branches/p3yk/Lib/test/test_grp.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_grp.py	(original)
+++ python/branches/p3yk/Lib/test/test_grp.py	Sun Jul  1 18:20:58 2007
@@ -54,7 +54,7 @@
         namei = 0
         fakename = allnames[namei]
         while fakename in bynames:
-            chars = map(None, fakename)
+            chars = list(fakename)
             for i in range(len(chars)):
                 if chars[i] == 'z':
                     chars[i] = 'A'
@@ -71,7 +71,7 @@
                 except IndexError:
                     # should never happen... if so, just forget it
                     break
-            fakename = ''.join(map(None, chars))
+            fakename = ''.join(chars)
 
         self.assertRaises(KeyError, grp.getgrnam, fakename)
 

Modified: python/branches/p3yk/Lib/test/test_hash.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_hash.py	(original)
+++ python/branches/p3yk/Lib/test/test_hash.py	Sun Jul  1 18:20:58 2007
@@ -11,7 +11,7 @@
     def same_hash(self, *objlist):
         # Hash each object given and fail if
         # the hash values are not all the same.
-        hashed = map(hash, objlist)
+        hashed = list(map(hash, objlist))
         for h in hashed[1:]:
             if h != hashed[0]:
                 self.fail("hashed values differ: %r" % (objlist,))

Modified: python/branches/p3yk/Lib/test/test_inspect.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_inspect.py	(original)
+++ python/branches/p3yk/Lib/test/test_inspect.py	Sun Jul  1 18:20:58 2007
@@ -43,7 +43,7 @@
 
 class TestPredicates(IsTestBase):
     def test_thirteen(self):
-        count = len(filter(lambda x:x.startswith('is'), dir(inspect)))
+        count = len([x for x in dir(inspect) if x.startswith('is')])
         # Doc/lib/libinspect.tex claims there are 13 such functions
         expected = 13
         err_msg = "There are %d (not %d) is* functions" % (count, expected)


More information about the Python-3000-checkins mailing list