[Jython-checkins] jython: Verify fix for http://bugs.jython.org/issue1929

jim.baker jython-checkins at python.org
Tue Feb 3 06:57:24 CET 2015


https://hg.python.org/jython/rev/bd4f7717a5d5
changeset:   7568:bd4f7717a5d5
user:        Jim Baker <jim.baker at rackspace.com>
date:        Mon Feb 02 22:55:14 2015 -0700
summary:
  Verify fix for http://bugs.jython.org/issue1929

files:
  Lib/test/test_class_jy.py |  45 ++++++++++++++++++++++++++-
  1 files changed, 44 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_class_jy.py b/Lib/test/test_class_jy.py
--- a/Lib/test/test_class_jy.py
+++ b/Lib/test/test_class_jy.py
@@ -387,6 +387,48 @@
         self.assertEqual(str(Bar), 'foo')
 
 
+class LenTestCase(unittest.TestCase):
+    """__len__ of new-style classes should raise OverflowError if length is too long"""
+
+    # Verifies fix for http://bugs.jython.org/issue1929
+
+    def test_len(self):
+        class C(object):
+            def __len__(self):
+                return 2 ** 70
+        with self.assertRaises(OverflowError) as cm:
+            len(C())
+        self.assertEqual(str(cm.exception), "long int too large to convert to int")
+
+        class D(object):
+            def __len__(self):
+                return "foo"
+        with self.assertRaises(TypeError) as cm:
+            len(D())
+        self.assertEqual(str(cm.exception), "an integer is required")
+
+    def test_len_faux_int(self):
+        class C(object):
+            def __len__(self):
+                class FauxInt(object):
+                    def __int__(self):
+                        return 2 ** 70
+                return FauxInt()
+        with self.assertRaises(OverflowError) as cm:
+            len(C())
+        self.assertEqual(str(cm.exception), "long int too large to convert to int")
+
+    def test_len_derived_int(self):
+        class C(object):
+            def __len__(self):
+                class MyInt(int):
+                    pass
+                return MyInt(2 ** 70)
+        with self.assertRaises(OverflowError) as cm:
+            len(C())
+        self.assertEqual(str(cm.exception), "long int too large to convert to int")
+
+
 def test_main():
     test_support.run_unittest(
         ClassGeneralTestCase,
@@ -396,7 +438,8 @@
         IsDescendentTestCase,
         JavaClassNamingTestCase,
         ClassDefinesDunderModule,
-        ClassMetaclassRepr)
+        ClassMetaclassRepr,
+        LenTestCase)
 
 
 if __name__ == "__main__":

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list