Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_marshal.py

    r2 r391  
    130130    def test_buffer(self):
    131131        for s in ["", "Andrè Previn", "abc", " "*10000]:
    132             b = buffer(s)
     132            with test_support.check_py3k_warnings(("buffer.. not supported",
     133                                                     DeprecationWarning)):
     134                b = buffer(s)
    133135            new = marshal.loads(marshal.dumps(b))
    134136            self.assertEqual(s, new)
     
    190192            new = marshal.loads(marshal.dumps(t))
    191193            self.assertEqual(t, new)
    192             self.assert_(isinstance(new, constructor))
     194            self.assertTrue(isinstance(new, constructor))
    193195            self.assertNotEqual(id(t), id(new))
    194196            marshal.dump(t, file(test_support.TESTFN, "wb"))
     
    209211    def test_version_argument(self):
    210212        # Python 2.4.0 crashes for any call to marshal.dumps(x, y)
    211         self.assertEquals(marshal.loads(marshal.dumps(5, 0)), 5)
    212         self.assertEquals(marshal.loads(marshal.dumps(5, 1)), 5)
     213        self.assertEqual(marshal.loads(marshal.dumps(5, 0)), 5)
     214        self.assertEqual(marshal.loads(marshal.dumps(5, 1)), 5)
    213215
    214216    def test_fuzz(self):
     
    251253        #   <type 'int'>
    252254        for typ in (int, long, float, complex, tuple, list, dict, set, frozenset):
    253             # Note: str and unicode sublclasses are not tested because they get handled
     255            # Note: str and unicode subclasses are not tested because they get handled
    254256            # by marshal's routines for objects supporting the buffer API.
    255257            subtyp = type('subtyp', (typ,), {})
     
    267269        invalid_string = 'l\x02\x00\x00\x00\x00\x00\x00\x00'
    268270        self.assertRaises(ValueError, marshal.loads, invalid_string)
     271
     272LARGE_SIZE = 2**31
     273character_size = 4 if sys.maxunicode > 0xFFFF else 2
     274pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4
     275
     276@unittest.skipIf(LARGE_SIZE > sys.maxsize, "test cannot run on 32-bit systems")
     277class LargeValuesTestCase(unittest.TestCase):
     278    def check_unmarshallable(self, data):
     279        f = open(test_support.TESTFN, 'wb')
     280        self.addCleanup(test_support.unlink, test_support.TESTFN)
     281        with f:
     282            self.assertRaises(ValueError, marshal.dump, data, f)
     283
     284    @test_support.precisionbigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False)
     285    def test_string(self, size):
     286        self.check_unmarshallable('x' * size)
     287
     288    @test_support.precisionbigmemtest(size=LARGE_SIZE,
     289            memuse=character_size, dry_run=False)
     290    def test_unicode(self, size):
     291        self.check_unmarshallable(u'x' * size)
     292
     293    @test_support.precisionbigmemtest(size=LARGE_SIZE,
     294            memuse=pointer_size, dry_run=False)
     295    def test_tuple(self, size):
     296        self.check_unmarshallable((None,) * size)
     297
     298    @test_support.precisionbigmemtest(size=LARGE_SIZE,
     299            memuse=pointer_size, dry_run=False)
     300    def test_list(self, size):
     301        self.check_unmarshallable([None] * size)
     302
     303    @test_support.precisionbigmemtest(size=LARGE_SIZE,
     304            memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1),
     305            dry_run=False)
     306    def test_set(self, size):
     307        self.check_unmarshallable(set(range(size)))
     308
     309    @test_support.precisionbigmemtest(size=LARGE_SIZE,
     310            memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1),
     311            dry_run=False)
     312    def test_frozenset(self, size):
     313        self.check_unmarshallable(frozenset(range(size)))
     314
     315    @test_support.precisionbigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False)
     316    def test_bytearray(self, size):
     317        self.check_unmarshallable(bytearray(size))
    269318
    270319
     
    276325                              ContainerTestCase,
    277326                              ExceptionTestCase,
    278                               BugsTestCase)
     327                              BugsTestCase,
     328                              LargeValuesTestCase,
     329                             )
    279330
    280331if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.