[Jython-checkins] jython: Update test_marshal from lib-python and add some skips.

jeff.allen jython-checkins at python.org
Sat Mar 23 04:50:15 EDT 2019


https://hg.python.org/jython/rev/dc308813c14f
changeset:   8227:dc308813c14f
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Fri Mar 22 07:41:06 2019 +0000
summary:
  Update test_marshal from lib-python and add some skips.

This is mainly so we have a test of the fix for bjo #2077. Also corrects
spelling of Andrew Preview.

files:
  Lib/test/test_marshal.py |  120 ++++++++++++++++++++++----
  1 files changed, 98 insertions(+), 22 deletions(-)


diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
-# -*- coding: iso-8859-1 -*-
+# -*- coding: utf-8 -*-
 
-from __future__ import with_statement
 from test import test_support
 import marshal
 import sys
@@ -118,7 +117,7 @@
 
 class StringTestCase(unittest.TestCase):
     def test_unicode(self):
-        for s in [u"", u"Andrè Previn", u"abc", u" "*10000]:
+        for s in [u"", u"André Previn", u"abc", u" "*10000]:
             new = marshal.loads(marshal.dumps(s))
             self.assertEqual(s, new)
             self.assertEqual(type(s), type(new))
@@ -128,7 +127,7 @@
         os.unlink(test_support.TESTFN)
 
     def test_string(self):
-        for s in ["", "Andrè Previn", "abc", " "*10000]:
+        for s in ["", "André Previn", "abc", " "*10000]:
             new = marshal.loads(marshal.dumps(s))
             self.assertEqual(s, new)
             self.assertEqual(type(s), type(new))
@@ -137,27 +136,29 @@
             self.assertEqual(type(s), type(new))
         os.unlink(test_support.TESTFN)
 
-    if not test_support.is_jython:
-        def test_buffer(self):
-            for s in ["", "Andrè Previn", "abc", " "*10000]:
+    @unittest.skipIf(test_support.is_jython, "FIXME: bjo #2744 buffer not supported")
+    def test_buffer(self):
+        for s in ["", "André Previn", "abc", " "*10000]:
+            with test_support.check_py3k_warnings(("buffer.. not supported",
+                                                     DeprecationWarning)):
                 b = buffer(s)
-                new = marshal.loads(marshal.dumps(b))
-                self.assertEqual(s, new)
-                new = roundtrip(b)
-                self.assertEqual(s, new)
-            os.unlink(test_support.TESTFN)
+            new = marshal.loads(marshal.dumps(b))
+            self.assertEqual(s, new)
+            new = roundtrip(b)
+            self.assertEqual(s, new)
+        os.unlink(test_support.TESTFN)
 
 class ExceptionTestCase(unittest.TestCase):
     def test_exceptions(self):
         new = marshal.loads(marshal.dumps(StopIteration))
         self.assertEqual(StopIteration, new)
 
+ at unittest.skipIf(test_support.is_jython, "requires PBC compilation back-end")
 class CodeTestCase(unittest.TestCase):
-    if not test_support.is_jython: # XXX - need to use the PBC compilation backend, which doesn't exist yet
-        def test_code(self):
-            co = ExceptionTestCase.test_exceptions.func_code
-            new = marshal.loads(marshal.dumps(co))
-            self.assertEqual(co, new)
+    def test_code(self):
+        co = ExceptionTestCase.test_exceptions.func_code
+        new = marshal.loads(marshal.dumps(co))
+        self.assertEqual(co, new)
 
 class ContainerTestCase(unittest.TestCase):
     d = {'astring': 'foo at bar.baz.spam',
@@ -167,7 +168,7 @@
          'alist': ['.zyx.41'],
          'atuple': ('.zyx.41',)*10,
          'aboolean': False,
-         'aunicode': u"Andrè Previn"
+         'aunicode': u"André Previn"
          }
     def test_dict(self):
         new = marshal.loads(marshal.dumps(self.d))
@@ -197,7 +198,7 @@
             t = constructor(self.d.keys())
             new = marshal.loads(marshal.dumps(t))
             self.assertEqual(t, new)
-            self.assert_(isinstance(new, constructor))
+            self.assertTrue(isinstance(new, constructor))
             self.assertNotEqual(id(t), id(new))
             new = roundtrip(t)
             self.assertEqual(t, new)
@@ -215,8 +216,8 @@
 
     def test_version_argument(self):
         # Python 2.4.0 crashes for any call to marshal.dumps(x, y)
-        self.assertEquals(marshal.loads(marshal.dumps(5, 0)), 5)
-        self.assertEquals(marshal.loads(marshal.dumps(5, 1)), 5)
+        self.assertEqual(marshal.loads(marshal.dumps(5, 0)), 5)
+        self.assertEqual(marshal.loads(marshal.dumps(5, 1)), 5)
 
     def test_fuzz(self):
         # simple test that it's at least not *totally* trivial to
@@ -251,6 +252,79 @@
         last.append([0])
         self.assertRaises(ValueError, marshal.dumps, head)
 
+    @unittest.skipIf(test_support.is_jython, "FIXME: bjo #2077 ValueError not raised")
+    def test_exact_type_match(self):
+        # Former bug:
+        #   >>> class Int(int): pass
+        #   >>> type(loads(dumps(Int())))
+        #   <type 'int'>
+        for typ in (int, long, float, complex, tuple, list, dict, set, frozenset):
+            # Note: str and unicode subclasses are not tested because they get handled
+            # by marshal's routines for objects supporting the buffer API.
+            subtyp = type('subtyp', (typ,), {})
+            self.assertRaises(ValueError, marshal.dumps, subtyp())
+
+    # Issue #1792 introduced a change in how marshal increases the size of its
+    # internal buffer; this test ensures that the new code is exercised.
+    def test_large_marshal(self):
+        size = int(1e6)
+        testString = 'abc' * size
+        marshal.dumps(testString)
+
+    @unittest.skipIf(test_support.is_jython, "FIXME: bjo #2077 ValueError not raised")
+    def test_invalid_longs(self):
+        # Issue #7019: marshal.loads shouldn't produce unnormalized PyLongs
+        invalid_string = 'l\x02\x00\x00\x00\x00\x00\x00\x00'
+        self.assertRaises(ValueError, marshal.loads, invalid_string)
+
+LARGE_SIZE = 2**31
+character_size = 4 if sys.maxunicode > 0xFFFF else 2
+pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4
+
+ at unittest.skipIf(LARGE_SIZE > sys.maxsize, "requires larger sys.maxsize")
+class LargeValuesTestCase(unittest.TestCase):
+    def check_unmarshallable(self, data):
+        f = open(test_support.TESTFN, 'wb')
+        self.addCleanup(test_support.unlink, test_support.TESTFN)
+        with f:
+            self.assertRaises(ValueError, marshal.dump, data, f)
+
+    @test_support.precisionbigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False)
+    def test_string(self, size):
+        self.check_unmarshallable('x' * size)
+
+    @test_support.precisionbigmemtest(size=LARGE_SIZE,
+            memuse=character_size, dry_run=False)
+    def test_unicode(self, size):
+        self.check_unmarshallable(u'x' * size)
+
+    @test_support.precisionbigmemtest(size=LARGE_SIZE,
+            memuse=pointer_size, dry_run=False)
+    def test_tuple(self, size):
+        self.check_unmarshallable((None,) * size)
+
+    @test_support.precisionbigmemtest(size=LARGE_SIZE,
+            memuse=pointer_size, dry_run=False)
+    def test_list(self, size):
+        self.check_unmarshallable([None] * size)
+
+    @test_support.precisionbigmemtest(size=LARGE_SIZE,
+            memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1),
+            dry_run=False)
+    def test_set(self, size):
+        self.check_unmarshallable(set(range(size)))
+
+    @test_support.precisionbigmemtest(size=LARGE_SIZE,
+            memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1),
+            dry_run=False)
+    def test_frozenset(self, size):
+        self.check_unmarshallable(frozenset(range(size)))
+
+    @test_support.precisionbigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False)
+    def test_bytearray(self, size):
+        self.check_unmarshallable(bytearray(size))
+
+
 def test_main():
     test_support.run_unittest(IntTestCase,
                               FloatTestCase,
@@ -258,7 +332,9 @@
                               CodeTestCase,
                               ContainerTestCase,
                               ExceptionTestCase,
-                              BugsTestCase)
+                              BugsTestCase,
+                              LargeValuesTestCase,
+                             )
 
 if __name__ == "__main__":
     test_main()

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


More information about the Jython-checkins mailing list