[pypy-svn] r59480 - pypy/trunk/lib-python/modified-2.5.2/test

fijal at codespeak.net fijal at codespeak.net
Tue Oct 28 15:11:57 CET 2008


Author: fijal
Date: Tue Oct 28 15:11:57 2008
New Revision: 59480

Added:
   pypy/trunk/lib-python/modified-2.5.2/test/string_tests.py
      - copied, changed from r59439, pypy/trunk/lib-python/2.5.2/test/string_tests.py
   pypy/trunk/lib-python/modified-2.5.2/test/test_str.py   (contents, props changed)
Log:
Move test_str and string_tests to modified, relax some checks (ie
OverflowError vs MemoryError)


Copied: pypy/trunk/lib-python/modified-2.5.2/test/string_tests.py (from r59439, pypy/trunk/lib-python/2.5.2/test/string_tests.py)
==============================================================================
--- pypy/trunk/lib-python/2.5.2/test/string_tests.py	(original)
+++ pypy/trunk/lib-python/modified-2.5.2/test/string_tests.py	Tue Oct 28 15:11:57 2008
@@ -252,7 +252,7 @@
         self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42)
         # This test is only valid when sizeof(int) == sizeof(void*) == 4.
         if sys.maxint < (1 << 32) and struct.calcsize('P') == 4:
-            self.checkraises(OverflowError,
+            self.checkraises((MemoryError, OverflowError),
                              '\ta\n\tb', 'expandtabs', sys.maxint)
 
     def test_split(self):
@@ -936,7 +936,8 @@
         self.checkequal('abc', 'abc', '__mul__', 1)
         self.checkequal('abcabcabc', 'abc', '__mul__', 3)
         self.checkraises(TypeError, 'abc', '__mul__')
-        self.checkraises(TypeError, 'abc', '__mul__', '')
+        if test_support.check_impl_detail:
+            self.checkraises(TypeError, 'abc', '__mul__', '')
         # XXX: on a 64-bit system, this doesn't raise an overflow error,
         # but either raises a MemoryError, or succeeds (if you have 54TiB)
         #self.checkraises(OverflowError, 10000*'abc', '__mul__', 2000000000)

Added: pypy/trunk/lib-python/modified-2.5.2/test/test_str.py
==============================================================================
--- (empty file)
+++ pypy/trunk/lib-python/modified-2.5.2/test/test_str.py	Tue Oct 28 15:11:57 2008
@@ -0,0 +1,101 @@
+
+import unittest
+import struct
+import sys
+from test import test_support, string_tests
+
+
+class StrTest(
+    string_tests.CommonTest,
+    string_tests.MixinStrUnicodeUserStringTest,
+    string_tests.MixinStrUserStringTest,
+    string_tests.MixinStrUnicodeTest,
+    ):
+
+    type2test = str
+
+    # We don't need to propagate to str
+    def fixtype(self, obj):
+        return obj
+
+    def test_formatting(self):
+        string_tests.MixinStrUnicodeUserStringTest.test_formatting(self)
+        self.assertRaises(OverflowError, '%c'.__mod__, 0x1234)
+
+    def test_conversion(self):
+        # Make sure __str__() behaves properly
+        class Foo0:
+            def __unicode__(self):
+                return u"foo"
+
+        class Foo1:
+            def __str__(self):
+                return "foo"
+
+        class Foo2(object):
+            def __str__(self):
+                return "foo"
+
+        class Foo3(object):
+            def __str__(self):
+                return u"foo"
+
+        class Foo4(unicode):
+            def __str__(self):
+                return u"foo"
+
+        class Foo5(str):
+            def __str__(self):
+                return u"foo"
+
+        class Foo6(str):
+            def __str__(self):
+                return "foos"
+
+            def __unicode__(self):
+                return u"foou"
+
+        class Foo7(unicode):
+            def __str__(self):
+                return "foos"
+            def __unicode__(self):
+                return u"foou"
+
+        class Foo8(str):
+            def __new__(cls, content=""):
+                return str.__new__(cls, 2*content)
+            def __str__(self):
+                return self
+
+        class Foo9(str):
+            def __str__(self):
+                return "string"
+            def __unicode__(self):
+                return "not unicode"
+
+        self.assert_(str(Foo0()).startswith("<")) # this is different from __unicode__
+        self.assertEqual(str(Foo1()), "foo")
+        self.assertEqual(str(Foo2()), "foo")
+        self.assertEqual(str(Foo3()), "foo")
+        self.assertEqual(str(Foo4("bar")), "foo")
+        self.assertEqual(str(Foo5("bar")), "foo")
+        self.assertEqual(str(Foo6("bar")), "foos")
+        self.assertEqual(str(Foo7("bar")), "foos")
+        self.assertEqual(str(Foo8("foo")), "foofoo")
+        self.assertEqual(str(Foo9("foo")), "string")
+        self.assertEqual(unicode(Foo9("foo")), u"not unicode")
+
+    def test_expandtabs_overflows_gracefully(self):
+        # This test only affects 32-bit platforms because expandtabs can only take
+        # an int as the max value, not a 64-bit C long.  If expandtabs is changed
+        # to take a 64-bit long, this test should apply to all platforms.
+        if sys.maxint > (1 << 32) or struct.calcsize('P') != 4:
+            return
+        self.assertRaises((OverflowError, MemoryError), 't\tt\t'.expandtabs, sys.maxint)
+
+
+def test_main():
+    test_support.run_unittest(StrTest)
+
+if __name__ == "__main__":
+    test_main()



More information about the Pypy-commit mailing list