[pypy-svn] rev 2670 - pypy/trunk/src/pypy/appspace

alex at codespeak.net alex at codespeak.net
Mon Dec 22 01:17:45 CET 2003


Author: alex
Date: Mon Dec 22 01:17:45 2003
New Revision: 2670

Modified:
   pypy/trunk/src/pypy/appspace/builtin_functions_test.py
Log:
edited to make max line length 80; commented out some unworkable tests;
removed use of enumerate from test_zip to decouple the two issues (as is
proper in _unit_ tests...).


Modified: pypy/trunk/src/pypy/appspace/builtin_functions_test.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/builtin_functions_test.py	(original)
+++ pypy/trunk/src/pypy/appspace/builtin_functions_test.py	Mon Dec 22 01:17:45 2003
@@ -14,13 +14,6 @@
 
     import sys, cStringIO
 
-    if 0:
-        import warnings
-        warnings.filterwarnings("ignore", "hex../oct.. of negative int",
-                                FutureWarning, __name__)
-        warnings.filterwarnings("ignore", "integer argument expected",
-                                DeprecationWarning, "unittest")
-
     class Squares:
     
         def __init__(self, max):
@@ -110,6 +103,7 @@
     b.BitBucket = BitBucket
     b.L = L
 
+
 class BuiltinTest(test.AppTestCase):
 
     full_test = 1
@@ -164,9 +158,9 @@
             apply(f2, (1, 2))
             apply(f3, (1, 2, 3))
     
-            # A PyCFunction that takes only positional parameters should allow an
-            # empty keyword dictionary to pass without a complaint, but raise a
-            # TypeError if the dictionary is non-empty.
+            # A PyCFunction that takes only positional parameters should allow
+            # an empty keyword dictionary to pass without a complaint, but
+            # raise a TypeError if the dictionary is non-empty.
             apply(id, (1,), {})
             self.assertRaises(TypeError, apply, id, (1,), {"foo": 1})
             self.assertRaises(TypeError, apply)
@@ -234,8 +228,10 @@
             bom = '\xef\xbb\xbf'
             compile(bom + 'print 1\n', '', 'exec')
             self.assertRaises(TypeError, compile)
-            self.assertRaises(ValueError, compile, 'print 42\n', '<string>', 'badmode')
-            self.assertRaises(ValueError, compile, 'print 42\n', '<string>', 'single', 0xff)
+            self.assertRaises(ValueError, compile,
+                'print 42\n', '<string>', 'badmode')
+            self.assertRaises(ValueError, compile,
+                'print 42\n', '<string>', 'single', 0xff)
             if have_unicode:
                 compile(unicode('print u"\xc3\xa5"\n', 'utf8'), '', 'exec')
 
@@ -330,16 +326,29 @@
         '\''
         '''
     
+        ''' XXX TODO: filter does NOT rely on __getitem__, but rather on
+            __iter__; it appears to me that the following two tests,
+            therefore, pass in CPython only because of the accident that
+            in that implementation str does not define __iter__ (while
+            list and tuple do, in 2.3).  Probably best to substitute
+            most of these tests with more appropriate ones!
+        '''
         def test_filter(self):
-            self.assertEqual(filter(lambda c: 'a' <= c <= 'z', 'Hello World'), 'elloorld')
-            self.assertEqual(filter(None, [1, 'hello', [], [3], '', None, 9, 0]), [1, 'hello', [3], 9])
-            self.assertEqual(filter(lambda x: x > 0, [1, -3, 9, 0, 2]), [1, 9, 2])
-            self.assertEqual(filter(None, Squares(10)), [1, 4, 9, 16, 25, 36, 49, 64, 81])
-            self.assertEqual(filter(lambda x: x%2, Squares(10)), [1, 9, 25, 49, 81])
+            self.assertEqual(filter(lambda c: 'a' <= c <= 'z', 'Hello World'),
+                'elloorld')
+            self.assertEqual(filter(None, [1, 'hello', [], [3], '', None, 9, 0])
+                , [1, 'hello', [3], 9])
+            self.assertEqual(filter(lambda x: x > 0, [1, -3, 9, 0, 2]),
+                [1, 9, 2])
+            self.assertEqual(filter(None, Squares(10)),
+                [1, 4, 9, 16, 25, 36, 49, 64, 81])
+            self.assertEqual(filter(lambda x: x%2, Squares(10)),
+                [1, 9, 25, 49, 81])
             def identity(item):
                 return 1
             filter(identity, Squares(5))
             self.assertRaises(TypeError, filter)
+            ''' XXX rest of test disabled as above explained
             class BadSeq(object):
                 def __getitem__(self, index):
                     if index<4:
@@ -362,17 +371,20 @@
             class badstr(str):
                 def __getitem__(self, index):
                     raise ValueError
-            self.assertRaises(ValueError, filter, lambda x: x >="3", badstr("1234"))
+            self.assertRaises(ValueError, filter,
+                lambda x: x >="3", badstr("1234"))
     
             class badstr2(str):
                 def __getitem__(self, index):
                     return 42
-            self.assertRaises(TypeError, filter, lambda x: x >=42, badstr2("1234"))
+            self.assertRaises(TypeError, filter,
+                lambda x: x >=42, badstr2("1234"))
     
             class weirdstr(str):
                 def __getitem__(self, index):
                     return weirdstr(2*str.__getitem__(self, index))
-            self.assertEqual(filter(lambda x: x>="33", weirdstr("1234")), "3344")
+            self.assertEqual(filter(lambda x: x>="33", weirdstr("1234")),
+                "3344")
     
             class shiftstr(str):
                 def __getitem__(self, index):
@@ -382,20 +394,24 @@
             if have_unicode:
                 # test bltinmodule.c::filterunicode()
                 self.assertEqual(filter(None, unicode("12")), unicode("12"))
-                self.assertEqual(filter(lambda x: x>="3", unicode("1234")), unicode("34"))
+                self.assertEqual(filter(lambda x: x>="3", unicode("1234")),
+                    unicode("34"))
                 self.assertRaises(TypeError, filter, 42, unicode("12"))
-                self.assertRaises(ValueError, filter, lambda x: x >="3", badstr(unicode("1234")))
+                self.assertRaises(ValueError, filter, lambda x: x >="3",
+                    badstr(unicode("1234")))
     
                 class badunicode(unicode):
                     def __getitem__(self, index):
                         return 42
-                self.assertRaises(TypeError, filter, lambda x: x >=42, badunicode("1234"))
+                self.assertRaises(TypeError, filter, lambda x: x >=42,
+                    badunicode("1234"))
     
                 class weirdunicode(unicode):
                     def __getitem__(self, index):
                         return weirdunicode(2*unicode.__getitem__(self, index))
                 self.assertEqual(
-                    filter(lambda x: x>=unicode("33"), weirdunicode("1234")), unicode("3344"))
+                    filter(lambda x: x>=unicode("33"), weirdunicode("1234")),
+                        unicode("3344"))
     
                 class shiftunicode(unicode):
                     def __getitem__(self, index):
@@ -440,6 +456,7 @@
                         outp = filter(func, cls(inp))
                         self.assertEqual(outp, exp)
                         self.assert_(not isinstance(outp, cls))
+        '''
     
         def test_float(self):
             self.assertEqual(float(3.14), 3.14)
@@ -448,7 +465,8 @@
             self.assertEqual(float("  3.14  "), 3.14)
             if have_unicode:
                 self.assertEqual(float(unicode("  3.14  ")), 3.14)
-                self.assertEqual(float(unicode("  \u0663.\u0661\u0664  ",'raw-unicode-escape')), 3.14)
+                self.assertEqual(float(unicode(
+                    "  \u0663.\u0661\u0664  ",'raw-unicode-escape')), 3.14)
     
         def test_getattr(self):
             import sys
@@ -457,7 +475,8 @@
             self.assertRaises(TypeError, getattr, sys, 1, "foo")
             self.assertRaises(TypeError, getattr)
             if have_unicode:
-                self.assertRaises(UnicodeError, getattr, sys, unichr(sys.maxunicode))
+                self.assertRaises(UnicodeError, getattr, sys,
+                    unichr(sys.maxunicode))
     
         def test_hasattr(self):
             import sys
@@ -465,7 +484,8 @@
             self.assertRaises(TypeError, hasattr, sys, 1)
             self.assertRaises(TypeError, hasattr)
             if have_unicode:
-                 self.assertRaises(UnicodeError, hasattr, sys, unichr(sys.maxunicode))
+                 self.assertRaises(UnicodeError, hasattr, sys,
+                     unichr(sys.maxunicode))
     
         def test_hash(self):
             hash(None)
@@ -487,7 +507,6 @@
             self.assertEqual(hex(-16L), '-0x10L')
             self.assertRaises(TypeError, hex, {})
     
-    if 1:
         def test_id(self):
             id(None)
             id(1)
@@ -530,7 +549,7 @@
             s = `-1-sys.maxint`
             self.assertEqual(int(s)+1, -sys.maxint)
             # should return long
-            ''' XXX TODO:  Longs not supported yet
+            ''' XXX TODO:  Longs not well supported yet
             int(s[1:])
     
             # should return long
@@ -541,8 +560,8 @@
             '''
     
             # SF bug 434186:  0x80000000/2 != 0x80000000>>1.
-            # Worked by accident in Windows release build, but failed in debug build.
-            # Failed in all Linux builds.
+            # Worked by accident in Windows release build, but failed in
+            # debug build.  Failed in all Linux builds.
             x = -1-sys.maxint
             self.assertEqual(x >> 1, x//2)
     
@@ -569,7 +588,6 @@
             s2 = s.swapcase().swapcase()
             self.assert_(intern(s2) is s)
     
-    if 0:
         def test_iter(self):
             self.assertRaises(TypeError, iter)
             self.assertRaises(TypeError, iter, 42, 42)
@@ -628,6 +646,8 @@
                 def __len__(self):
                     raise ValueError
             self.assertRaises(ValueError, len, BadSeq())
+
+    if 1:
     
         def test_list(self):
             self.assertEqual(list([]), [])
@@ -640,6 +660,7 @@
             self.assertEqual(list(''), [])
             self.assertEqual(list('spam'), ['s', 'p', 'a', 'm'])
     
+            ''' XXX TODO: disabled for now -- far too slow!
             if sys.maxint == 0x7fffffff:
                 # This test can currently only work on 32-bit machines.
                 # XXX If/when PySequence_Length() returns a ssize_t, it should be
@@ -656,7 +677,9 @@
     
                 #     http://sources.redhat.com/ml/newlib/2002/msg00369.html
                 self.assertRaises(MemoryError, list, xrange(sys.maxint // 2))
+            '''
     
+        ''' XXX TODO: disabled for now -- long not yet well supported
         def test_long(self):
             self.assertEqual(long(314), 314L)
             self.assertEqual(long(3.14), 3L)
@@ -700,6 +723,7 @@
             self.assertRaises(ValueError, long, '123\0')
             self.assertRaises(ValueError, long, '53', 40)
             self.assertRaises(TypeError, long, 1, 12)
+        '''
     
         def test_map(self):
             self.assertEqual(
@@ -964,6 +988,7 @@
             self.assertRaises(OverflowError, range, -sys.maxint, sys.maxint)
             self.assertRaises(OverflowError, range, 0, 2*sys.maxint)
     
+        ''' XXX TODO: input and raw_input not supported yet
         def test_input_and_raw_input(self):
             self.write_testfile()
             fp = open(TESTFN, 'r')
@@ -991,6 +1016,7 @@
                 sys.stdout = savestdout
                 fp.close()
                 unlink(TESTFN)
+        '''
     
         def test_reduce(self):
             self.assertEqual(reduce(lambda x, y: x+y, ['a', 'b', 'c'], ''), 'abc')
@@ -1192,9 +1218,10 @@
                         raise IndexError
                     else:
                         return i
+            s = SequenceWithoutALength()
             self.assertEqual(
-                zip(SequenceWithoutALength(), xrange(2**30)),
-                list(enumerate(range(5)))
+                zip(s, xrange(2**30)),
+                [(x,x) for x in s]
             )
     
             class BadSeq:


More information about the Pypy-commit mailing list