Back to index

python3.2  3.2.2
Public Member Functions
test.test_marshal.BugsTestCase Class Reference

List of all members.

Public Member Functions

def test_bug_5888452
def test_patch_873224
def test_version_argument
def test_fuzz
def test_loads_recursion
def test_recursion_limit
def test_exact_type_match
def test_large_marshal
def test_invalid_longs
def test_multiple_dumps_and_loads

Detailed Description

Definition at line 140 of file test_marshal.py.


Member Function Documentation

Definition at line 141 of file test_marshal.py.

00141 
00142     def test_bug_5888452(self):
00143         # Simple-minded check for SF 588452: Debug build crashes
00144         marshal.dumps([128] * 1000)

Definition at line 191 of file test_marshal.py.

00191 
00192     def test_exact_type_match(self):
00193         # Former bug:
00194         #   >>> class Int(int): pass
00195         #   >>> type(loads(dumps(Int())))
00196         #   <type 'int'>
00197         for typ in (int, float, complex, tuple, list, dict, set, frozenset):
00198             # Note: str subclasses are not tested because they get handled
00199             # by marshal's routines for objects supporting the buffer API.
00200             subtyp = type('subtyp', (typ,), {})
00201             self.assertRaises(ValueError, marshal.dumps, subtyp())

Here is the call graph for this function:

Definition at line 155 of file test_marshal.py.

00155 
00156     def test_fuzz(self):
00157         # simple test that it's at least not *totally* trivial to
00158         # crash from bad marshal data
00159         for c in [chr(i) for i in range(256)]:
00160             try:
00161                 marshal.loads(c)
00162             except Exception:
00163                 pass

Here is the call graph for this function:

Definition at line 209 of file test_marshal.py.

00209 
00210     def test_invalid_longs(self):
00211         # Issue #7019: marshal.loads shouldn't produce unnormalized PyLongs
00212         invalid_string = b'l\x02\x00\x00\x00\x00\x00\x00\x00'
00213         self.assertRaises(ValueError, marshal.loads, invalid_string)

Here is the call graph for this function:

Definition at line 204 of file test_marshal.py.

00204 
00205     def test_large_marshal(self):
00206         size = int(1e6)
00207         testString = 'abc' * size
00208         marshal.dumps(testString)

Definition at line 164 of file test_marshal.py.

00164 
00165     def test_loads_recursion(self):
00166         s = 'c' + ('X' * 4*4) + '{' * 2**20
00167         self.assertRaises(ValueError, marshal.loads, s)

Here is the call graph for this function:

Definition at line 214 of file test_marshal.py.

00214 
00215     def test_multiple_dumps_and_loads(self):
00216         # Issue 12291: marshal.load() should be callable multiple times
00217         # with interleaved data written by non-marshal code
00218         # Adapted from a patch by Engelbert Gruber.
00219         data = (1, 'abc', b'def', 1.0, (2, 'a', ['b', b'c']))
00220         for interleaved in (b'', b'0123'):
00221             ilen = len(interleaved)
00222             positions = []
00223             try:
00224                 with open(support.TESTFN, 'wb') as f:
00225                     for d in data:
00226                         marshal.dump(d, f)
00227                         if ilen:
00228                             f.write(interleaved)
00229                         positions.append(f.tell())
00230                 with open(support.TESTFN, 'rb') as f:
00231                     for i, d in enumerate(data):
00232                         self.assertEqual(d, marshal.load(f))
00233                         if ilen:
00234                             f.read(ilen)
00235                         self.assertEqual(positions[i], f.tell())
00236             finally:
00237                 support.unlink(support.TESTFN)
00238 

Here is the call graph for this function:

Definition at line 145 of file test_marshal.py.

00145 
00146     def test_patch_873224(self):
00147         self.assertRaises(Exception, marshal.loads, '0')
00148         self.assertRaises(Exception, marshal.loads, 'f')
00149         self.assertRaises(Exception, marshal.loads, marshal.dumps(2**65)[:-1])

Here is the call graph for this function:

Definition at line 168 of file test_marshal.py.

00168 
00169     def test_recursion_limit(self):
00170         # Create a deeply nested structure.
00171         head = last = []
00172         # The max stack depth should match the value in Python/marshal.c.
00173         if os.name == 'nt' and hasattr(sys, 'gettotalrefcount'):
00174             MAX_MARSHAL_STACK_DEPTH = 1500
00175         else:
00176             MAX_MARSHAL_STACK_DEPTH = 2000
00177         for i in range(MAX_MARSHAL_STACK_DEPTH - 2):
00178             last.append([0])
00179             last = last[-1]
00180 
00181         # Verify we don't blow out the stack with dumps/load.
00182         data = marshal.dumps(head)
00183         new_head = marshal.loads(data)
00184         # Don't use == to compare objects, it can exceed the recursion limit.
00185         self.assertEqual(len(new_head), len(head))
00186         self.assertEqual(len(new_head[0]), len(head[0]))
00187         self.assertEqual(len(new_head[-1]), len(head[-1]))
00188 
00189         last.append([0])
00190         self.assertRaises(ValueError, marshal.dumps, head)

Here is the call graph for this function:

Definition at line 150 of file test_marshal.py.

00150 
00151     def test_version_argument(self):
00152         # Python 2.4.0 crashes for any call to marshal.dumps(x, y)
00153         self.assertEqual(marshal.loads(marshal.dumps(5, 0)), 5)
00154         self.assertEqual(marshal.loads(marshal.dumps(5, 1)), 5)

Here is the call graph for this function:


The documentation for this class was generated from the following file: