Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_marshal.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 4fb6c0c169ff |
| children | 9130fe9c58bf 6768b2350c57 |
| rev | line source |
|---|---|
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
1 #!/usr/bin/env python |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
2 # -*- coding: iso-8859-1 -*- |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
3 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
4 from test import test_support |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
5 import marshal |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
6 import sys |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
7 import unittest |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
8 import os |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
9 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
10 class IntTestCase(unittest.TestCase): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
11 def test_ints(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
12 # Test the full range of Python ints. |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
13 n = sys.maxint |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
14 while n: |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
15 for expected in (-n, n): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
16 s = marshal.dumps(expected) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
17 got = marshal.loads(s) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
18 self.assertEqual(expected, got) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
19 marshal.dump(expected, file(test_support.TESTFN, "wb")) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
20 got = marshal.load(file(test_support.TESTFN, "rb")) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
21 self.assertEqual(expected, got) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
22 n = n >> 1 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
23 os.unlink(test_support.TESTFN) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
24 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
25 def test_int64(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
26 # Simulate int marshaling on a 64-bit box. This is most interesting if |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
27 # we're running the test on a 32-bit box, of course. |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
28 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
29 def to_little_endian_string(value, nbytes): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
30 bytes = [] |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
31 for i in range(nbytes): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
32 bytes.append(chr(value & 0xff)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
33 value >>= 8 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
34 return ''.join(bytes) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
35 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
36 maxint64 = (1L << 63) - 1 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
37 minint64 = -maxint64-1 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
38 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
39 for base in maxint64, minint64, -maxint64, -(minint64 >> 1): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
40 while base: |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
41 s = 'I' + to_little_endian_string(base, 8) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
42 got = marshal.loads(s) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
43 self.assertEqual(base, got) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
44 if base == -1: # a fixed-point for shifting right 1 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
45 base = 0 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
46 else: |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
47 base >>= 1 |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
48 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
49 def test_bool(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
50 for b in (True, False): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
51 new = marshal.loads(marshal.dumps(b)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
52 self.assertEqual(b, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
53 self.assertEqual(type(b), type(new)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
54 marshal.dump(b, file(test_support.TESTFN, "wb")) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
55 new = marshal.load(file(test_support.TESTFN, "rb")) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
56 self.assertEqual(b, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
57 self.assertEqual(type(b), type(new)) |
|
31389
aca1ce1b4b61
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
30038
diff
changeset
|
58 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
59 class FloatTestCase(unittest.TestCase): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
60 def test_floats(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
61 # Test a few floats |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
62 small = 1e-25 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
63 n = sys.maxint * 3.7e250 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
64 while n > small: |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
65 for expected in (-n, n): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
66 f = float(expected) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
67 s = marshal.dumps(f) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
68 got = marshal.loads(s) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
69 self.assertEqual(f, got) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
70 marshal.dump(f, file(test_support.TESTFN, "wb")) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
71 got = marshal.load(file(test_support.TESTFN, "rb")) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
72 self.assertEqual(f, got) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
73 n /= 123.4567 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
74 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
75 f = 0.0 |
| 35008 | 76 s = marshal.dumps(f, 2) |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
77 got = marshal.loads(s) |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
78 self.assertEqual(f, got) |
| 35008 | 79 # and with version <= 1 (floats marshalled differently then) |
| 80 s = marshal.dumps(f, 1) | |
|
35014
275843630522
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
35008
diff
changeset
|
81 got = marshal.loads(s) |
|
275843630522
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
35008
diff
changeset
|
82 self.assertEqual(f, got) |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
83 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
84 n = sys.maxint * 3.7e-250 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
85 while n < small: |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
86 for expected in (-n, n): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
87 f = float(expected) |
|
35014
275843630522
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
35008
diff
changeset
|
88 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
89 s = marshal.dumps(f) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
90 got = marshal.loads(s) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
91 self.assertEqual(f, got) |
|
35014
275843630522
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
35008
diff
changeset
|
92 |
| 35008 | 93 s = marshal.dumps(f, 1) |
| 94 got = marshal.loads(s) | |
| 95 self.assertEqual(f, got) | |
|
35014
275843630522
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
35008
diff
changeset
|
96 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
97 marshal.dump(f, file(test_support.TESTFN, "wb")) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
98 got = marshal.load(file(test_support.TESTFN, "rb")) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
99 self.assertEqual(f, got) |
|
35014
275843630522
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
35008
diff
changeset
|
100 |
| 35008 | 101 marshal.dump(f, file(test_support.TESTFN, "wb"), 1) |
| 102 got = marshal.load(file(test_support.TESTFN, "rb")) | |
| 103 self.assertEqual(f, got) | |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
104 n *= 123.4567 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
105 os.unlink(test_support.TESTFN) |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
106 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
107 class StringTestCase(unittest.TestCase): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
108 def test_unicode(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
109 for s in [u"", u"Andrè Previn", u"abc", u" "*10000]: |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
110 new = marshal.loads(marshal.dumps(s)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
111 self.assertEqual(s, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
112 self.assertEqual(type(s), type(new)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
113 marshal.dump(s, file(test_support.TESTFN, "wb")) |
|
35021
ea5c2280f915
Fix missing assignments of marshal.load() values. Closes #1214662.
Skip Montanaro <skip@pobox.com>
parents:
35014
diff
changeset
|
114 new = marshal.load(file(test_support.TESTFN, "rb")) |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
115 self.assertEqual(s, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
116 self.assertEqual(type(s), type(new)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
117 os.unlink(test_support.TESTFN) |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
118 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
119 def test_string(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
120 for s in ["", "Andrè Previn", "abc", " "*10000]: |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
121 new = marshal.loads(marshal.dumps(s)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
122 self.assertEqual(s, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
123 self.assertEqual(type(s), type(new)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
124 marshal.dump(s, file(test_support.TESTFN, "wb")) |
|
35021
ea5c2280f915
Fix missing assignments of marshal.load() values. Closes #1214662.
Skip Montanaro <skip@pobox.com>
parents:
35014
diff
changeset
|
125 new = marshal.load(file(test_support.TESTFN, "rb")) |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
126 self.assertEqual(s, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
127 self.assertEqual(type(s), type(new)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
128 os.unlink(test_support.TESTFN) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
129 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
130 def test_buffer(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
131 for s in ["", "Andrè Previn", "abc", " "*10000]: |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
132 b = buffer(s) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
133 new = marshal.loads(marshal.dumps(b)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
134 self.assertEqual(s, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
135 marshal.dump(b, file(test_support.TESTFN, "wb")) |
|
35021
ea5c2280f915
Fix missing assignments of marshal.load() values. Closes #1214662.
Skip Montanaro <skip@pobox.com>
parents:
35014
diff
changeset
|
136 new = marshal.load(file(test_support.TESTFN, "rb")) |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
137 self.assertEqual(s, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
138 os.unlink(test_support.TESTFN) |
|
31389
aca1ce1b4b61
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
30038
diff
changeset
|
139 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
140 class ExceptionTestCase(unittest.TestCase): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
141 def test_exceptions(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
142 new = marshal.loads(marshal.dumps(StopIteration)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
143 self.assertEqual(StopIteration, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
144 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
145 class CodeTestCase(unittest.TestCase): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
146 def test_code(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
147 co = ExceptionTestCase.test_exceptions.func_code |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
148 new = marshal.loads(marshal.dumps(co)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
149 self.assertEqual(co, new) |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
150 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
151 class ContainerTestCase(unittest.TestCase): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
152 d = {'astring': 'foo@bar.baz.spam', |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
153 'afloat': 7283.43, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
154 'anint': 2**20, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
155 'ashortlong': 2L, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
156 'alist': ['.zyx.41'], |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
157 'atuple': ('.zyx.41',)*10, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
158 'aboolean': False, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
159 'aunicode': u"Andrè Previn" |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
160 } |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
161 def test_dict(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
162 new = marshal.loads(marshal.dumps(self.d)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
163 self.assertEqual(self.d, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
164 marshal.dump(self.d, file(test_support.TESTFN, "wb")) |
|
35021
ea5c2280f915
Fix missing assignments of marshal.load() values. Closes #1214662.
Skip Montanaro <skip@pobox.com>
parents:
35014
diff
changeset
|
165 new = marshal.load(file(test_support.TESTFN, "rb")) |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
166 self.assertEqual(self.d, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
167 os.unlink(test_support.TESTFN) |
|
31389
aca1ce1b4b61
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
30038
diff
changeset
|
168 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
169 def test_list(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
170 lst = self.d.items() |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
171 new = marshal.loads(marshal.dumps(lst)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
172 self.assertEqual(lst, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
173 marshal.dump(lst, file(test_support.TESTFN, "wb")) |
|
35021
ea5c2280f915
Fix missing assignments of marshal.load() values. Closes #1214662.
Skip Montanaro <skip@pobox.com>
parents:
35014
diff
changeset
|
174 new = marshal.load(file(test_support.TESTFN, "rb")) |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
175 self.assertEqual(lst, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
176 os.unlink(test_support.TESTFN) |
|
24434
9ef82377669d
Fix SF 588452: debug build crashes on marshal.dumps([128] * 1000).
Thomas Heller <theller@ctypes.org>
parents:
24364
diff
changeset
|
177 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
178 def test_tuple(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
179 t = tuple(self.d.keys()) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
180 new = marshal.loads(marshal.dumps(t)) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
181 self.assertEqual(t, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
182 marshal.dump(t, file(test_support.TESTFN, "wb")) |
|
35021
ea5c2280f915
Fix missing assignments of marshal.load() values. Closes #1214662.
Skip Montanaro <skip@pobox.com>
parents:
35014
diff
changeset
|
183 new = marshal.load(file(test_support.TESTFN, "rb")) |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
184 self.assertEqual(t, new) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
185 os.unlink(test_support.TESTFN) |
|
31389
aca1ce1b4b61
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
30038
diff
changeset
|
186 |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
187 def test_sets(self): |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
188 for constructor in (set, frozenset): |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
189 t = constructor(self.d.keys()) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
190 new = marshal.loads(marshal.dumps(t)) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
191 self.assertEqual(t, new) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
192 self.assert_(isinstance(new, constructor)) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
193 self.assertNotEqual(id(t), id(new)) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
194 marshal.dump(t, file(test_support.TESTFN, "wb")) |
|
35021
ea5c2280f915
Fix missing assignments of marshal.load() values. Closes #1214662.
Skip Montanaro <skip@pobox.com>
parents:
35014
diff
changeset
|
195 new = marshal.load(file(test_support.TESTFN, "rb")) |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
196 self.assertEqual(t, new) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
197 os.unlink(test_support.TESTFN) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
198 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
199 class BugsTestCase(unittest.TestCase): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
200 def test_bug_5888452(self): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
201 # Simple-minded check for SF 588452: Debug build crashes |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
202 marshal.dumps([128] * 1000) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
203 |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
31389
diff
changeset
|
204 def test_patch_873224(self): |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
31389
diff
changeset
|
205 self.assertRaises(Exception, marshal.loads, '0') |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
31389
diff
changeset
|
206 self.assertRaises(Exception, marshal.loads, 'f') |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
31389
diff
changeset
|
207 self.assertRaises(Exception, marshal.loads, marshal.dumps(5L)[:-1]) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
31389
diff
changeset
|
208 |
|
34205
ea340006c1f3
Back-ported: marshal.dumps() with the new optional argument 'version' just
Armin Rigo <arigo@tunes.org>
parents:
31824
diff
changeset
|
209 def test_version_argument(self): |
|
ea340006c1f3
Back-ported: marshal.dumps() with the new optional argument 'version' just
Armin Rigo <arigo@tunes.org>
parents:
31824
diff
changeset
|
210 # Python 2.4.0 crashes for any call to marshal.dumps(x, y) |
|
ea340006c1f3
Back-ported: marshal.dumps() with the new optional argument 'version' just
Armin Rigo <arigo@tunes.org>
parents:
31824
diff
changeset
|
211 self.assertEquals(marshal.loads(marshal.dumps(5, 0)), 5) |
|
ea340006c1f3
Back-ported: marshal.dumps() with the new optional argument 'version' just
Armin Rigo <arigo@tunes.org>
parents:
31824
diff
changeset
|
212 self.assertEquals(marshal.loads(marshal.dumps(5, 1)), 5) |
|
ea340006c1f3
Back-ported: marshal.dumps() with the new optional argument 'version' just
Armin Rigo <arigo@tunes.org>
parents:
31824
diff
changeset
|
213 |
| 35071 | 214 def test_fuzz(self): |
| 215 # simple test that it's at least not *totally* trivial to | |
| 216 # crash from bad marshal data | |
| 217 for c in [chr(i) for i in range(256)]: | |
| 218 try: | |
| 219 marshal.loads(c) | |
| 220 except Exception: | |
| 221 pass | |
| 222 | |
|
41763
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
223 def test_loads_recursion(self): |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
35071
diff
changeset
|
224 s = 'c' + ('X' * 4*4) + '{' * 2**20 |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
35071
diff
changeset
|
225 self.assertRaises(ValueError, marshal.loads, s) |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
35071
diff
changeset
|
226 |
|
41763
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
227 def test_recursion_limit(self): |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
228 # Create a deeply nested structure. |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
229 head = last = [] |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
230 # The max stack depth should match the value in Python/marshal.c. |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
231 MAX_MARSHAL_STACK_DEPTH = 2000 |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
232 for i in range(MAX_MARSHAL_STACK_DEPTH - 2): |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
233 last.append([0]) |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
234 last = last[-1] |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
235 |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
236 # Verify we don't blow out the stack with dumps/load. |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
237 data = marshal.dumps(head) |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
238 new_head = marshal.loads(data) |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
239 # Don't use == to compare objects, it can exceed the recursion limit. |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
240 self.assertEqual(len(new_head), len(head)) |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
241 self.assertEqual(len(new_head[0]), len(head[0])) |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
242 self.assertEqual(len(new_head[-1]), len(head[-1])) |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
243 |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
244 last.append([0]) |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
245 self.assertRaises(ValueError, marshal.dumps, head) |
|
f43e9d1fabaa
Verify neither dumps or loads overflow the stack and segfault.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41741
diff
changeset
|
246 |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
247 def test_exact_type_match(self): |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
248 # Former bug: |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
249 # >>> class Int(int): pass |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
250 # >>> type(loads(dumps(Int()))) |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
251 # <type 'int'> |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
252 for typ in (int, long, float, complex, tuple, list, dict, set, frozenset): |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
253 # Note: str and unicode sublclasses are not tested because they get handled |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
254 # by marshal's routines for objects supporting the buffer API. |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
255 subtyp = type('subtyp', (typ,), {}) |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
256 self.assertRaises(ValueError, marshal.dumps, subtyp()) |
|
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
41763
diff
changeset
|
257 |
|
46880
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
43781
diff
changeset
|
258 # Issue #1792 introduced a change in how marshal increases the size of its |
|
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
43781
diff
changeset
|
259 # internal buffer; this test ensures that the new code is exercised. |
|
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
43781
diff
changeset
|
260 def test_large_marshal(self): |
|
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
43781
diff
changeset
|
261 size = int(1e6) |
|
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
43781
diff
changeset
|
262 testString = 'abc' * size |
|
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
43781
diff
changeset
|
263 marshal.dumps(testString) |
|
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
43781
diff
changeset
|
264 |
|
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
43781
diff
changeset
|
265 |
|
30038
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
266 def test_main(): |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
267 test_support.run_unittest(IntTestCase, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
268 FloatTestCase, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
269 StringTestCase, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
270 CodeTestCase, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
271 ContainerTestCase, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
272 ExceptionTestCase, |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
273 BugsTestCase) |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
274 |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
275 if __name__ == "__main__": |
|
0c621801409a
more extension marshal tests and conversion to unittest - was surprised to
Skip Montanaro <skip@pobox.com>
parents:
24434
diff
changeset
|
276 test_main() |
