Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_sys.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | fa95b04e67fd |
| children | 2d330f7908e7 |
| rev | line source |
|---|---|
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
1 # -*- coding: iso-8859-1 -*- |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
2 import unittest, test.test_support |
|
58817
70e115c34f97
Remove unused imports in test modules.
Georg Brandl <georg@python.org>
parents:
58713
diff
changeset
|
3 import sys, os, cStringIO |
|
47824
380aa2d161d3
Issue 3147: Fixed SizeofTest failure for LLP64 systems.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47822
diff
changeset
|
4 import struct |
|
58505
bc2b88beae45
Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents:
58472
diff
changeset
|
5 import operator |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
6 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
7 class SysModuleTest(unittest.TestCase): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
8 |
|
56873
b31fcbab0520
Fix transient refleak in test_sys.
Antoine Pitrou <solipsis@pitrou.net>
parents:
56715
diff
changeset
|
9 def tearDown(self): |
|
b31fcbab0520
Fix transient refleak in test_sys.
Antoine Pitrou <solipsis@pitrou.net>
parents:
56715
diff
changeset
|
10 test.test_support.reap_children() |
|
b31fcbab0520
Fix transient refleak in test_sys.
Antoine Pitrou <solipsis@pitrou.net>
parents:
56715
diff
changeset
|
11 |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
12 def test_original_displayhook(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
13 import __builtin__ |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
14 savestdout = sys.stdout |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
15 out = cStringIO.StringIO() |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
16 sys.stdout = out |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
17 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
18 dh = sys.__displayhook__ |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
19 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
20 self.assertRaises(TypeError, dh) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
21 if hasattr(__builtin__, "_"): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
22 del __builtin__._ |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
23 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
24 dh(None) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
25 self.assertEqual(out.getvalue(), "") |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
26 self.assertTrue(not hasattr(__builtin__, "_")) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
27 dh(42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
28 self.assertEqual(out.getvalue(), "42\n") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
29 self.assertEqual(__builtin__._, 42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
30 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
31 del sys.stdout |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
32 self.assertRaises(RuntimeError, dh, 42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
33 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
34 sys.stdout = savestdout |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
35 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
36 def test_lost_displayhook(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
37 olddisplayhook = sys.displayhook |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
38 del sys.displayhook |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
39 code = compile("42", "<string>", "single") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
40 self.assertRaises(RuntimeError, eval, code) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
41 sys.displayhook = olddisplayhook |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
42 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
43 def test_custom_displayhook(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
44 olddisplayhook = sys.displayhook |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
45 def baddisplayhook(obj): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
46 raise ValueError |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
47 sys.displayhook = baddisplayhook |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
48 code = compile("42", "<string>", "single") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
49 self.assertRaises(ValueError, eval, code) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
50 sys.displayhook = olddisplayhook |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
51 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
52 def test_original_excepthook(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
53 savestderr = sys.stderr |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
54 err = cStringIO.StringIO() |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
55 sys.stderr = err |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
56 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
57 eh = sys.__excepthook__ |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
58 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
59 self.assertRaises(TypeError, eh) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
60 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
61 raise ValueError(42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
62 except ValueError, exc: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
63 eh(*sys.exc_info()) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
64 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
65 sys.stderr = savestderr |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
66 self.assertTrue(err.getvalue().endswith("ValueError: 42\n")) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
67 |
| 27661 | 68 # FIXME: testing the code for a lost or replaced excepthook in |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
69 # Python/pythonrun.c::PyErr_PrintEx() is tricky. |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
70 |
|
28119
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
71 def test_exc_clear(self): |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
72 self.assertRaises(TypeError, sys.exc_clear, 42) |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
73 |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
74 # Verify that exc_info is present and matches exc, then clear it, and |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
75 # check that it worked. |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
76 def clear_check(exc): |
|
28120
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
77 typ, value, traceback = sys.exc_info() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
78 self.assertTrue(typ is not None) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
79 self.assertTrue(value is exc) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
80 self.assertTrue(traceback is not None) |
|
28119
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
81 |
|
59663
5b888f590fe2
#7092: silence some more py3k warnings.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59510
diff
changeset
|
82 with test.test_support.check_py3k_warnings(): |
|
63556
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61922
diff
changeset
|
83 sys.exc_clear() |
|
28119
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
84 |
|
28120
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
85 typ, value, traceback = sys.exc_info() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
86 self.assertTrue(typ is None) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
87 self.assertTrue(value is None) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
88 self.assertTrue(traceback is None) |
|
28119
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
89 |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
90 def clear(): |
|
28120
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
91 try: |
|
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
92 raise ValueError, 42 |
|
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
93 except ValueError, exc: |
|
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
94 clear_check(exc) |
|
28119
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
95 |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
96 # Raise an exception and check that it can be cleared |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
97 clear() |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
98 |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
99 # Verify that a frame currently handling an exception is |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
100 # unaffected by calling exc_clear in a nested frame. |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
101 try: |
|
28120
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
102 raise ValueError, 13 |
|
28119
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
103 except ValueError, exc: |
|
28120
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
104 typ1, value1, traceback1 = sys.exc_info() |
|
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
105 clear() |
|
d24564e7e999
Reindent the new code properly.
Guido van Rossum <guido@python.org>
parents:
28119
diff
changeset
|
106 typ2, value2, traceback2 = sys.exc_info() |
|
28119
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
107 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
108 self.assertTrue(typ1 is typ2) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
109 self.assertTrue(value1 is exc) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
110 self.assertTrue(value1 is value2) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
111 self.assertTrue(traceback1 is traceback2) |
|
28119
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
112 |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
113 # Check that an exception can be cleared outside of an except block |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
114 clear_check(exc) |
|
869695cba2cd
- New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents:
27963
diff
changeset
|
115 |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
116 def test_exit(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
117 self.assertRaises(TypeError, sys.exit, 42, 42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
118 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
119 # call without argument |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
120 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
121 sys.exit(0) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
122 except SystemExit, exc: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63267
diff
changeset
|
123 self.assertEqual(exc.code, 0) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
124 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
125 self.fail("wrong exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
126 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
127 self.fail("no exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
128 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
129 # call with tuple argument with one entry |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
130 # entry will be unpacked |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
131 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
132 sys.exit(42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
133 except SystemExit, exc: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63267
diff
changeset
|
134 self.assertEqual(exc.code, 42) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
135 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
136 self.fail("wrong exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
137 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
138 self.fail("no exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
139 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
140 # call with integer argument |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
141 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
142 sys.exit((42,)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
143 except SystemExit, exc: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63267
diff
changeset
|
144 self.assertEqual(exc.code, 42) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
145 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
146 self.fail("wrong exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
147 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
148 self.fail("no exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
149 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
150 # call with string argument |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
151 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
152 sys.exit("exit") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
153 except SystemExit, exc: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63267
diff
changeset
|
154 self.assertEqual(exc.code, "exit") |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
155 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
156 self.fail("wrong exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
157 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
158 self.fail("no exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
159 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
160 # call with tuple argument with two entries |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
161 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
162 sys.exit((17, 23)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
163 except SystemExit, exc: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63267
diff
changeset
|
164 self.assertEqual(exc.code, (17, 23)) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
165 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
166 self.fail("wrong exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
167 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
168 self.fail("no exception") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
169 |
|
34589
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
170 # test that the exit machinery handles SystemExits properly |
|
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
171 import subprocess |
|
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
172 # both unnormalized... |
|
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
173 rc = subprocess.call([sys.executable, "-c", |
|
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
174 "raise SystemExit, 46"]) |
|
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
175 self.assertEqual(rc, 46) |
|
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
176 # ... and normalized |
|
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
177 rc = subprocess.call([sys.executable, "-c", |
|
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
178 "raise SystemExit(47)"]) |
|
a899d690f264
Test that SystemExits are handled properly by the exit machinery. I
Michael W. Hudson <mwh@python.net>
parents:
29765
diff
changeset
|
179 self.assertEqual(rc, 47) |
|
34591
1ae2c3b66e57
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34589
diff
changeset
|
180 |
|
61922
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
181 def check_exit_message(code, expected, env=None): |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
182 process = subprocess.Popen([sys.executable, "-c", code], |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
183 stderr=subprocess.PIPE, env=env) |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
184 stdout, stderr = process.communicate() |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
185 self.assertEqual(process.returncode, 1) |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
186 self.assertTrue(stderr.startswith(expected), |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
187 "%s doesn't start with %s" % (repr(stderr), repr(expected))) |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
188 |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
189 # test that stderr buffer if flushed before the exit message is written |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
190 # into stderr |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
191 check_exit_message( |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
192 r'import sys; sys.stderr.write("unflushed,"); sys.exit("message")', |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
193 b"unflushed,message") |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
194 |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
195 # test that the unicode message is encoded to the stderr encoding |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
196 env = os.environ.copy() |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
197 env['PYTHONIOENCODING'] = 'latin-1' |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
198 check_exit_message( |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
199 r'import sys; sys.exit(u"h\xe9")', |
|
8dbbd90eeda8
Merged revisions 81537 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59820
diff
changeset
|
200 b"h\xe9", env=env) |
|
34591
1ae2c3b66e57
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34589
diff
changeset
|
201 |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
202 def test_getdefaultencoding(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
203 if test.test_support.have_unicode: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
204 self.assertRaises(TypeError, sys.getdefaultencoding, 42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
205 # can't check more than the type, as the user might have changed it |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
206 self.assertIsInstance(sys.getdefaultencoding(), str) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
207 |
|
63267
6d31b60372c4
Redo r83142 merge manually. QOTD: svnmerge isn't really your best friend
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
63265
diff
changeset
|
208 # testing sys.settrace() is done in test_sys_settrace.py |
|
6d31b60372c4
Redo r83142 merge manually. QOTD: svnmerge isn't really your best friend
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
63265
diff
changeset
|
209 # testing sys.setprofile() is done in test_sys_setprofile.py |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
210 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
211 def test_setcheckinterval(self): |
|
27963
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
212 self.assertRaises(TypeError, sys.setcheckinterval) |
|
29765
e9e5832d706f
New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
213 orig = sys.getcheckinterval() |
|
e9e5832d706f
New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
214 for n in 0, 100, 120, orig: # orig last to restore starting state |
|
e9e5832d706f
New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
215 sys.setcheckinterval(n) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63267
diff
changeset
|
216 self.assertEqual(sys.getcheckinterval(), n) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
217 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
218 def test_recursionlimit(self): |
|
27963
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
219 self.assertRaises(TypeError, sys.getrecursionlimit, 42) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
220 oldlimit = sys.getrecursionlimit() |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
221 self.assertRaises(TypeError, sys.setrecursionlimit) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
222 self.assertRaises(ValueError, sys.setrecursionlimit, -42) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
223 sys.setrecursionlimit(10000) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
224 self.assertEqual(sys.getrecursionlimit(), 10000) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
225 sys.setrecursionlimit(oldlimit) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
226 |
|
73880
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
227 self.assertRaises(OverflowError, sys.setrecursionlimit, 1 << 31) |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
228 try: |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
229 sys.setrecursionlimit((1 << 31) - 5) |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
230 try: |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
231 # issue13546: isinstance(e, ValueError) used to fail |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
232 # when the recursion limit is close to 1<<31 |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
233 raise ValueError() |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
234 except ValueError, e: |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
235 pass |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
236 finally: |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
237 sys.setrecursionlimit(oldlimit) |
|
57de1ad15c54
Issue #13546: Fixed an overflow issue that could crash the intepreter when
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
68256
diff
changeset
|
238 |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
239 def test_getwindowsversion(self): |
|
58517
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
240 # Raise SkipTest if sys doesn't have getwindowsversion attribute |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
241 test.test_support.get_attribute(sys, "getwindowsversion") |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
242 v = sys.getwindowsversion() |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
243 self.assertEqual(len(v), 5) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
244 self.assertIsInstance(v[0], int) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
245 self.assertIsInstance(v[1], int) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
246 self.assertIsInstance(v[2], int) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
247 self.assertIsInstance(v[3], int) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
248 self.assertIsInstance(v[4], str) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
249 self.assertRaises(IndexError, operator.getitem, v, 5) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
250 self.assertIsInstance(v.major, int) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
251 self.assertIsInstance(v.minor, int) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
252 self.assertIsInstance(v.build, int) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
253 self.assertIsInstance(v.platform, int) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
254 self.assertIsInstance(v.service_pack, str) |
|
58526
f6f9ee83ecbf
Added named (but not numbered) attributes to sys.getwindowsversion() test.
Eric Smith <eric@trueblade.com>
parents:
58517
diff
changeset
|
255 self.assertIsInstance(v.service_pack_minor, int) |
|
f6f9ee83ecbf
Added named (but not numbered) attributes to sys.getwindowsversion() test.
Eric Smith <eric@trueblade.com>
parents:
58517
diff
changeset
|
256 self.assertIsInstance(v.service_pack_major, int) |
|
f6f9ee83ecbf
Added named (but not numbered) attributes to sys.getwindowsversion() test.
Eric Smith <eric@trueblade.com>
parents:
58517
diff
changeset
|
257 self.assertIsInstance(v.suite_mask, int) |
|
f6f9ee83ecbf
Added named (but not numbered) attributes to sys.getwindowsversion() test.
Eric Smith <eric@trueblade.com>
parents:
58517
diff
changeset
|
258 self.assertIsInstance(v.product_type, int) |
|
58517
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
259 self.assertEqual(v[0], v.major) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
260 self.assertEqual(v[1], v.minor) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
261 self.assertEqual(v[2], v.build) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
262 self.assertEqual(v[3], v.platform) |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
263 self.assertEqual(v[4], v.service_pack) |
|
58505
bc2b88beae45
Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
Eric Smith <eric@trueblade.com>
parents:
58472
diff
changeset
|
264 |
|
58517
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
265 # This is how platform.py calls it. Make sure tuple |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
266 # still has 5 elements |
|
6726aeb867b9
Switch to test_support.get_attribute.
Eric Smith <eric@trueblade.com>
parents:
58513
diff
changeset
|
267 maj, min, buildno, plat, csd = sys.getwindowsversion() |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
268 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
269 def test_dlopenflags(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
270 if hasattr(sys, "setdlopenflags"): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
271 self.assertTrue(hasattr(sys, "getdlopenflags")) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
272 self.assertRaises(TypeError, sys.getdlopenflags, 42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
273 oldflags = sys.getdlopenflags() |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
274 self.assertRaises(TypeError, sys.setdlopenflags) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
275 sys.setdlopenflags(oldflags+1) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
276 self.assertEqual(sys.getdlopenflags(), oldflags+1) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
277 sys.setdlopenflags(oldflags) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
278 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
279 def test_refcount(self): |
|
52900
4acbbb3e65e2
Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47957
diff
changeset
|
280 # n here must be a global in order for this test to pass while |
|
4acbbb3e65e2
Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47957
diff
changeset
|
281 # tracing with a python function. Tracing calls PyFrame_FastToLocals |
|
4acbbb3e65e2
Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47957
diff
changeset
|
282 # which will add a copy of any locals to the frame object, causing |
|
4acbbb3e65e2
Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47957
diff
changeset
|
283 # the reference count to increase by 2 instead of 1. |
|
4acbbb3e65e2
Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47957
diff
changeset
|
284 global n |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
285 self.assertRaises(TypeError, sys.getrefcount) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
286 c = sys.getrefcount(None) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
287 n = None |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
288 self.assertEqual(sys.getrefcount(None), c+1) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
289 del n |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
290 self.assertEqual(sys.getrefcount(None), c) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
291 if hasattr(sys, "gettotalrefcount"): |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
292 self.assertIsInstance(sys.gettotalrefcount(), int) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
293 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
294 def test_getframe(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
295 self.assertRaises(TypeError, sys._getframe, 42, 42) |
|
27934
f67ab6b66454
Fix SF bug #688424, 64-bit test problems
Neal Norwitz <nnorwitz@gmail.com>
parents:
27661
diff
changeset
|
296 self.assertRaises(ValueError, sys._getframe, 2000000000) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
297 self.assertTrue( |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
298 SysModuleTest.test_getframe.im_func.func_code \ |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
299 is sys._getframe().f_code |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
300 ) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
301 |
|
39056
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
302 # sys._current_frames() is a CPython-only gimmick. |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
303 def test_current_frames(self): |
|
39118
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
304 have_threads = True |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
305 try: |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
306 import thread |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
307 except ImportError: |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
308 have_threads = False |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
309 |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
310 if have_threads: |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
311 self.current_frames_with_threads() |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
312 else: |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
313 self.current_frames_without_threads() |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
314 |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
315 # Test sys._current_frames() in a WITH_THREADS build. |
|
56873
b31fcbab0520
Fix transient refleak in test_sys.
Antoine Pitrou <solipsis@pitrou.net>
parents:
56715
diff
changeset
|
316 @test.test_support.reap_threads |
|
39118
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
317 def current_frames_with_threads(self): |
|
39056
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
318 import threading, thread |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
319 import traceback |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
320 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
321 # Spawn a thread that blocks at a known place. Then the main |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
322 # thread does sys._current_frames(), and verifies that the frames |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
323 # returned make sense. |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
324 entered_g = threading.Event() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
325 leave_g = threading.Event() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
326 thread_info = [] # the thread's id |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
327 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
328 def f123(): |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
329 g456() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
330 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
331 def g456(): |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
332 thread_info.append(thread.get_ident()) |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
333 entered_g.set() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
334 leave_g.wait() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
335 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
336 t = threading.Thread(target=f123) |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
337 t.start() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
338 entered_g.wait() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
339 |
|
39169
99aa84224f18
current_frames_with_threads(): There's actually no way
Tim Peters <tim.peters@gmail.com>
parents:
39118
diff
changeset
|
340 # At this point, t has finished its entered_g.set(), although it's |
|
99aa84224f18
current_frames_with_threads(): There's actually no way
Tim Peters <tim.peters@gmail.com>
parents:
39118
diff
changeset
|
341 # impossible to guess whether it's still on that line or has moved on |
|
99aa84224f18
current_frames_with_threads(): There's actually no way
Tim Peters <tim.peters@gmail.com>
parents:
39118
diff
changeset
|
342 # to its leave_g.wait(). |
|
39056
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
343 self.assertEqual(len(thread_info), 1) |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
344 thread_id = thread_info[0] |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
345 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
346 d = sys._current_frames() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
347 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
348 main_id = thread.get_ident() |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
349 self.assertIn(main_id, d) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
350 self.assertIn(thread_id, d) |
|
39056
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
351 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
352 # Verify that the captured main-thread frame is _this_ frame. |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
353 frame = d.pop(main_id) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
354 self.assertTrue(frame is sys._getframe()) |
|
39056
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
355 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
356 # Verify that the captured thread frame is blocked in g456, called |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
357 # from f123. This is a litte tricky, since various bits of |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
358 # threading.py are also in the thread's call stack. |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
359 frame = d.pop(thread_id) |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
360 stack = traceback.extract_stack(frame) |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
361 for i, (filename, lineno, funcname, sourceline) in enumerate(stack): |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
362 if funcname == "f123": |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
363 break |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
364 else: |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
365 self.fail("didn't find f123() on thread's call stack") |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
366 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
367 self.assertEqual(sourceline, "g456()") |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
368 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
369 # And the next record must be for g456(). |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
370 filename, lineno, funcname, sourceline = stack[i+1] |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
371 self.assertEqual(funcname, "g456") |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
372 self.assertIn(sourceline, ["leave_g.wait()", "entered_g.set()"]) |
|
39056
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
373 |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
374 # Reap the spawned thread. |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
375 leave_g.set() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
376 t.join() |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
37424
diff
changeset
|
377 |
|
39118
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
378 # Test sys._current_frames() when thread support doesn't exist. |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
379 def current_frames_without_threads(self): |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
380 # Not much happens here: there is only one thread, with artificial |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
381 # "thread id" 0. |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
382 d = sys._current_frames() |
|
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
383 self.assertEqual(len(d), 1) |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
384 self.assertIn(0, d) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
385 self.assertTrue(d[0] is sys._getframe()) |
|
39118
85b23965ec4c
SF bug 1524317: configure --without-threads fails to build
Tim Peters <tim.peters@gmail.com>
parents:
39056
diff
changeset
|
386 |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
387 def test_attributes(self): |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
388 self.assertIsInstance(sys.api_version, int) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
389 self.assertIsInstance(sys.argv, list) |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
390 self.assertIn(sys.byteorder, ("little", "big")) |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
391 self.assertIsInstance(sys.builtin_module_names, tuple) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
392 self.assertIsInstance(sys.copyright, basestring) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
393 self.assertIsInstance(sys.exec_prefix, basestring) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
394 self.assertIsInstance(sys.executable, basestring) |
| 44085 | 395 self.assertEqual(len(sys.float_info), 11) |
|
44670
d66e5837aa57
Now that I've learnt about structseq objects I felt like converting sys.float_info to a structseq. It's
Christian Heimes <christian@cheimes.de>
parents:
44669
diff
changeset
|
396 self.assertEqual(sys.float_info.radix, 2) |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
51641
diff
changeset
|
397 self.assertEqual(len(sys.long_info), 2) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
398 self.assertTrue(sys.long_info.bits_per_digit % 5 == 0) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
399 self.assertTrue(sys.long_info.sizeof_digit >= 1) |
|
52739
7fa0f81d607e
sys.long_info attributes should be ints, not longs
Mark Dickinson <dickinsm@gmail.com>
parents:
52629
diff
changeset
|
400 self.assertEqual(type(sys.long_info.bits_per_digit), int) |
|
7fa0f81d607e
sys.long_info attributes should be ints, not longs
Mark Dickinson <dickinsm@gmail.com>
parents:
52629
diff
changeset
|
401 self.assertEqual(type(sys.long_info.sizeof_digit), int) |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
402 self.assertIsInstance(sys.hexversion, int) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
403 self.assertIsInstance(sys.maxint, int) |
|
35309
5fe9ceeca111
Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents:
34591
diff
changeset
|
404 if test.test_support.have_unicode: |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
405 self.assertIsInstance(sys.maxunicode, int) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
406 self.assertIsInstance(sys.platform, basestring) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
407 self.assertIsInstance(sys.prefix, basestring) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
408 self.assertIsInstance(sys.version, basestring) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
409 vi = sys.version_info |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
410 self.assertIsInstance(vi[:], tuple) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
411 self.assertEqual(len(vi), 5) |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
412 self.assertIsInstance(vi[0], int) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
413 self.assertIsInstance(vi[1], int) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
414 self.assertIsInstance(vi[2], int) |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
415 self.assertIn(vi[3], ("alpha", "beta", "candidate", "final")) |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
416 self.assertIsInstance(vi[4], int) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
417 self.assertIsInstance(vi.major, int) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
418 self.assertIsInstance(vi.minor, int) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
419 self.assertIsInstance(vi.micro, int) |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
420 self.assertIn(vi.releaselevel, ("alpha", "beta", "candidate", "final")) |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58460
diff
changeset
|
421 self.assertIsInstance(vi.serial, int) |
|
51365
e239e977bb32
Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents:
50036
diff
changeset
|
422 self.assertEqual(vi[0], vi.major) |
|
e239e977bb32
Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents:
50036
diff
changeset
|
423 self.assertEqual(vi[1], vi.minor) |
|
e239e977bb32
Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents:
50036
diff
changeset
|
424 self.assertEqual(vi[2], vi.micro) |
|
e239e977bb32
Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents:
50036
diff
changeset
|
425 self.assertEqual(vi[3], vi.releaselevel) |
|
e239e977bb32
Implement issue #4285, convert sys.version_info to a named
Eric Smith <eric@trueblade.com>
parents:
50036
diff
changeset
|
426 self.assertEqual(vi[4], vi.serial) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
427 self.assertTrue(vi > (1,0,0)) |
|
56715
aacee9749d15
Issue #7117 (backport py3k float repr) continued:
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
428 self.assertIsInstance(sys.float_repr_style, str) |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
429 self.assertIn(sys.float_repr_style, ('short', 'legacy')) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
430 |
|
37424
3eea65bb896e
Add test case for #43581.
Martin v. Löwis <martin@v.loewis.de>
parents:
35309
diff
changeset
|
431 def test_43581(self): |
|
3eea65bb896e
Add test case for #43581.
Martin v. Löwis <martin@v.loewis.de>
parents:
35309
diff
changeset
|
432 # Can't use sys.stdout, as this is a cStringIO object when |
|
3eea65bb896e
Add test case for #43581.
Martin v. Löwis <martin@v.loewis.de>
parents:
35309
diff
changeset
|
433 # the test runs under regrtest. |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
434 self.assertTrue(sys.__stdout__.encoding == sys.__stderr__.encoding) |
|
37424
3eea65bb896e
Add test case for #43581.
Martin v. Löwis <martin@v.loewis.de>
parents:
35309
diff
changeset
|
435 |
|
44669
9b6d348cec87
Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents:
44085
diff
changeset
|
436 def test_sys_flags(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
437 self.assertTrue(sys.flags) |
|
44669
9b6d348cec87
Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents:
44085
diff
changeset
|
438 attrs = ("debug", "py3k_warning", "division_warning", "division_new", |
|
9b6d348cec87
Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents:
44085
diff
changeset
|
439 "inspect", "interactive", "optimize", "dont_write_bytecode", |
| 44678 | 440 "no_site", "ignore_environment", "tabcheck", "verbose", |
|
75100
6b7704fe1be1
- Issue #13703: oCERT-2011-003: add -R command-line option and PYTHONHASHSEED
Barry Warsaw <barry@python.org>
parents:
63556
diff
changeset
|
441 "unicode", "bytes_warning", "hash_randomization") |
|
44669
9b6d348cec87
Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents:
44085
diff
changeset
|
442 for attr in attrs: |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
443 self.assertTrue(hasattr(sys.flags, attr), attr) |
|
44669
9b6d348cec87
Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents:
44085
diff
changeset
|
444 self.assertEqual(type(getattr(sys.flags, attr)), int, attr) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52739
diff
changeset
|
445 self.assertTrue(repr(sys.flags)) |
|
44669
9b6d348cec87
Applied patch #1816: sys.flags patch
Christian Heimes <christian@cheimes.de>
parents:
44085
diff
changeset
|
446 |
| 45143 | 447 def test_clear_type_cache(self): |
| 448 sys._clear_type_cache() | |
| 449 | |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
450 def test_ioencoding(self): |
|
58817
70e115c34f97
Remove unused imports in test modules.
Georg Brandl <georg@python.org>
parents:
58713
diff
changeset
|
451 import subprocess |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
452 env = dict(os.environ) |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
453 |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
454 # Test character: cent sign, encoded as 0x4A (ASCII J) in CP424, |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
455 # not representable in ASCII. |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
456 |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
457 env["PYTHONIOENCODING"] = "cp424" |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
458 p = subprocess.Popen([sys.executable, "-c", 'print unichr(0xa2)'], |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
459 stdout = subprocess.PIPE, env=env) |
|
56873
b31fcbab0520
Fix transient refleak in test_sys.
Antoine Pitrou <solipsis@pitrou.net>
parents:
56715
diff
changeset
|
460 out = p.communicate()[0].strip() |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
461 self.assertEqual(out, unichr(0xa2).encode("cp424")) |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
462 |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
463 env["PYTHONIOENCODING"] = "ascii:replace" |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
464 p = subprocess.Popen([sys.executable, "-c", 'print unichr(0xa2)'], |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
465 stdout = subprocess.PIPE, env=env) |
|
56873
b31fcbab0520
Fix transient refleak in test_sys.
Antoine Pitrou <solipsis@pitrou.net>
parents:
56715
diff
changeset
|
466 out = p.communicate()[0].strip() |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
467 self.assertEqual(out, '?') |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
468 |
|
58627
75bb2f1691c0
Merged revisions 77892 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
52900
diff
changeset
|
469 def test_call_tracing(self): |
|
75bb2f1691c0
Merged revisions 77892 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
52900
diff
changeset
|
470 self.assertEqual(sys.call_tracing(str, (2,)), "2") |
|
75bb2f1691c0
Merged revisions 77892 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
52900
diff
changeset
|
471 self.assertRaises(TypeError, sys.call_tracing, str, 2) |
|
75bb2f1691c0
Merged revisions 77892 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
52900
diff
changeset
|
472 |
|
59820
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
473 def test_executable(self): |
|
74728
c351536e804a
Document absoluteness of sys.executable
Petri Lehtinen <petri@digip.org>
parents:
73880
diff
changeset
|
474 # sys.executable should be absolute |
|
c351536e804a
Document absoluteness of sys.executable
Petri Lehtinen <petri@digip.org>
parents:
73880
diff
changeset
|
475 self.assertEqual(os.path.abspath(sys.executable), sys.executable) |
|
c351536e804a
Document absoluteness of sys.executable
Petri Lehtinen <petri@digip.org>
parents:
73880
diff
changeset
|
476 |
|
59820
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
477 # Issue #7774: Ensure that sys.executable is an empty string if argv[0] |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
478 # has been set to an non existent program name and Python is unable to |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
479 # retrieve the real program name |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
480 import subprocess |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
481 # For a normal installation, it should work without 'cwd' |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
482 # argument. For test runs in the build directory, see #7774. |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
483 python_dir = os.path.dirname(os.path.realpath(sys.executable)) |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
484 p = subprocess.Popen( |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
485 ["nonexistent", "-c", 'import sys; print repr(sys.executable)'], |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
486 executable=sys.executable, stdout=subprocess.PIPE, cwd=python_dir) |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
487 executable = p.communicate()[0].strip() |
|
12e2075dbbe0
Merged revisions 78835-78837,78870 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58714
diff
changeset
|
488 p.wait() |
|
59509
e5367d67a7f8
Fix test_executable introduce in previous commit (r78835): Windows is able to
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59508
diff
changeset
|
489 self.assertIn(executable, ["''", repr(sys.executable)]) |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
46759
diff
changeset
|
490 |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
491 class SizeofTest(unittest.TestCase): |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
492 |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
493 def setUp(self): |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
494 self.P = struct.calcsize('P') |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
51641
diff
changeset
|
495 self.longdigit = sys.long_info.sizeof_digit |
|
47925
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
496 import _testcapi |
|
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
497 self.gc_headsize = _testcapi.SIZEOF_PYGC_HEAD |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
498 self.file = open(test.test_support.TESTFN, 'wb') |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
499 |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
500 def tearDown(self): |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
501 self.file.close() |
|
47421
a65f095b27f3
Some style nits. Also clarify in the docstrings what __sizeof__ does.
Georg Brandl <georg@python.org>
parents:
47419
diff
changeset
|
502 test.test_support.unlink(test.test_support.TESTFN) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
503 |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
504 check_sizeof = test.test_support.check_sizeof |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
505 |
|
47925
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
506 def test_gc_head_size(self): |
|
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
507 # Check that the gc header size is added to objects tracked by the gc. |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
508 size = test.test_support.calcobjsize |
|
47925
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
509 gc_header_size = self.gc_headsize |
|
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
510 # bool objects are not gc tracked |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
511 self.assertEqual(sys.getsizeof(True), size('l')) |
|
47925
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
512 # but lists are |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
513 self.assertEqual(sys.getsizeof([]), size('P PP') + gc_header_size) |
|
47925
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
514 |
|
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
515 def test_default(self): |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
516 size = test.test_support.calcobjsize |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
517 self.assertEqual(sys.getsizeof(True, -1), size('l')) |
|
47925
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47922
diff
changeset
|
518 |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
519 def test_objecttypes(self): |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
520 # check all types defined in Objects/ |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
521 size = test.test_support.calcobjsize |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
522 vsize = test.test_support.calcvobjsize |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
523 check = self.check_sizeof |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
524 # bool |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
525 check(True, size('l')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
526 # buffer |
|
59663
5b888f590fe2
#7092: silence some more py3k warnings.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59510
diff
changeset
|
527 with test.test_support.check_py3k_warnings(): |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
528 check(buffer(''), size('2P2Pil')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
529 # builtin_function_or_method |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
530 check(len, size('3P')) |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
531 # bytearray |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
532 samples = ['', 'u'*100000] |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
533 for sample in samples: |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
534 x = bytearray(sample) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
535 check(x, vsize('iPP') + x.__alloc__()) |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
536 # bytearray_iterator |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
537 check(iter(bytearray()), size('PP')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
538 # cell |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
539 def get_cell(): |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
540 x = 42 |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
541 def inner(): |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
542 return x |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
543 return inner |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
544 check(get_cell().func_closure[0], size('P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
545 # classobj (old-style class) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
546 class class_oldstyle(): |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
547 def method(): |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
548 pass |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
549 check(class_oldstyle, size('7P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
550 # instance (old-style class) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
551 check(class_oldstyle(), size('3P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
552 # instancemethod (old-style class) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
553 check(class_oldstyle().method, size('4P')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
554 # complex |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
555 check(complex(0,1), size('2d')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
556 # code |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
557 check(get_cell().func_code, size('4i8Pi3P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
558 # BaseException |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
559 check(BaseException(), size('3P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
560 # UnicodeEncodeError |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
561 check(UnicodeEncodeError("", u"", 0, 0, ""), size('5P2PP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
562 # UnicodeDecodeError |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
563 check(UnicodeDecodeError("", "", 0, 0, ""), size('5P2PP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
564 # UnicodeTranslateError |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
565 check(UnicodeTranslateError(u"", 0, 1, ""), size('5P2PP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
566 # method_descriptor (descriptor object) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
567 check(str.lower, size('2PP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
568 # classmethod_descriptor (descriptor object) |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
569 # XXX |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
570 # member_descriptor (descriptor object) |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
571 import datetime |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
572 check(datetime.timedelta.days, size('2PP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
573 # getset_descriptor (descriptor object) |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
574 import __builtin__ |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
575 check(__builtin__.file.closed, size('2PP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
576 # wrapper_descriptor (descriptor object) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
577 check(int.__add__, size('2P2P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
578 # dictproxy |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
579 class C(object): pass |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
580 check(C.__dict__, size('P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
581 # method-wrapper (descriptor object) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
582 check({}.__iter__, size('2P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
583 # dict |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
584 check({}, size('3P2P' + 8*'P2P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
585 x = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8} |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
586 check(x, size('3P2P' + 8*'P2P') + 16*struct.calcsize('P2P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
587 # dictionary-keyiterator |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
588 check({}.iterkeys(), size('P2PPP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
589 # dictionary-valueiterator |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
590 check({}.itervalues(), size('P2PPP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
591 # dictionary-itemiterator |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
592 check({}.iteritems(), size('P2PPP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
593 # ellipses |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
594 check(Ellipsis, size('')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
595 # EncodingMap |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
596 import codecs, encodings.iso8859_3 |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
597 x = codecs.charmap_build(encodings.iso8859_3.decoding_table) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
598 check(x, size('32B2iB')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
599 # enumerate |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
600 check(enumerate([]), size('l3P')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
601 # file |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
602 check(self.file, size('4P2i4P3i3P3i')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
603 # float |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
604 check(float(0), size('d')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
605 # sys.floatinfo |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
606 check(sys.float_info, vsize('') + self.P * len(sys.float_info)) |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
607 # frame |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
608 import inspect |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
609 CO_MAXBLOCKS = 20 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
610 x = inspect.currentframe() |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
611 ncells = len(x.f_code.co_cellvars) |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
612 nfrees = len(x.f_code.co_freevars) |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
613 extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\ |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
614 ncells + nfrees - 1 |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
615 check(x, vsize('12P3i' + CO_MAXBLOCKS*'3i' + 'P' + extras*'P')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
616 # function |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
617 def func(): pass |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
618 check(func, size('9P')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
619 class c(): |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
620 @staticmethod |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
621 def foo(): |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
622 pass |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
623 @classmethod |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
624 def bar(cls): |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
625 pass |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
626 # staticmethod |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
627 check(foo, size('P')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
628 # classmethod |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
629 check(bar, size('P')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
630 # generator |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
631 def get_gen(): yield 1 |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
632 check(get_gen(), size('Pi2P')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
633 # integer |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
634 check(1, size('l')) |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
635 check(100, size('l')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
636 # iterator |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
637 check(iter('abc'), size('lP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
638 # callable-iterator |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
639 import re |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
640 check(re.finditer('',''), size('2P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
641 # list |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
642 samples = [[], [1,2,3], ['1', '2', '3']] |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
643 for sample in samples: |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
644 check(sample, vsize('PP') + len(sample)*self.P) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
645 # sortwrapper (list) |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
646 # XXX |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
647 # cmpwrapper (list) |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
648 # XXX |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
649 # listiterator (list) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
650 check(iter([]), size('lP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
651 # listreverseiterator (list) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
652 check(reversed([]), size('lP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
653 # long |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
654 check(0L, vsize('')) |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
655 check(1L, vsize('') + self.longdigit) |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
656 check(-1L, vsize('') + self.longdigit) |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
51641
diff
changeset
|
657 PyLong_BASE = 2**sys.long_info.bits_per_digit |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
658 check(long(PyLong_BASE), vsize('') + 2*self.longdigit) |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
659 check(long(PyLong_BASE**2-1), vsize('') + 2*self.longdigit) |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
660 check(long(PyLong_BASE**2), vsize('') + 3*self.longdigit) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
661 # module |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
662 check(unittest, size('P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
663 # None |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
664 check(None, size('')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
665 # object |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
666 check(object(), size('')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
667 # property (descriptor object) |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
668 class C(object): |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
669 def getx(self): return self.__x |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
670 def setx(self, value): self.__x = value |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
671 def delx(self): del self.__x |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
672 x = property(getx, setx, delx, "") |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
673 check(x, size('4Pi')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
674 # PyCObject |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
59694
diff
changeset
|
675 # PyCapsule |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
676 # XXX |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
677 # rangeiterator |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
678 check(iter(xrange(1)), size('4l')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
679 # reverse |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
680 check(reversed(''), size('PP')) |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
681 # set |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
682 # frozenset |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
683 PySet_MINSIZE = 8 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
684 samples = [[], range(10), range(50)] |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
685 s = size('3P2P' + PySet_MINSIZE*'lP' + 'lP') |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
686 for sample in samples: |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
687 minused = len(sample) |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
688 if minused == 0: tmp = 1 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
689 # the computation of minused is actually a bit more complicated |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
690 # but this suffices for the sizeof test |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
691 minused = minused*2 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
692 newsize = PySet_MINSIZE |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
693 while newsize <= minused: |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
694 newsize = newsize << 1 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
695 if newsize <= 8: |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
696 check(set(sample), s) |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
697 check(frozenset(sample), s) |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
698 else: |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
699 check(set(sample), s + newsize*struct.calcsize('lP')) |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
700 check(frozenset(sample), s + newsize*struct.calcsize('lP')) |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47918
diff
changeset
|
701 # setiterator |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
702 check(iter(set()), size('P3P')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
703 # slice |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
704 check(slice(1), size('3P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
705 # str |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
706 vh = test.test_support._vheader |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
707 check('', struct.calcsize(vh + 'lic')) |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
708 check('abc', struct.calcsize(vh + 'lic') + 3) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
709 # super |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
710 check(super(int), size('3P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
711 # tuple |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
712 check((), vsize('')) |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
713 check((1,2,3), vsize('') + 3*self.P) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
714 # tupleiterator |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
715 check(iter(()), size('lP')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
716 # type |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
717 # (PyTypeObject + PyNumberMethods + PyMappingMethods + |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
718 # PySequenceMethods + PyBufferProcs) |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
719 s = vsize('P2P15Pl4PP9PP11PI') + struct.calcsize('41P 10P 3P 6P') |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
720 class newstyleclass(object): |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
721 pass |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
722 check(newstyleclass, s) |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
723 # builtin type |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
724 check(int, s) |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
725 # NotImplementedType |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
726 import types |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
727 check(types.NotImplementedType, s) |
|
47543
296ab1038b7f
Issue 3048: Fixed sys.getsizeof for unicode objects.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47423
diff
changeset
|
728 # unicode |
|
47743
b8c9a3543381
Issue 3048: Fixed sys.sizeof test fails with wide unicode.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47682
diff
changeset
|
729 usize = len(u'\0'.encode('unicode-internal')) |
|
47543
296ab1038b7f
Issue 3048: Fixed sys.getsizeof for unicode objects.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47423
diff
changeset
|
730 samples = [u'', u'1'*100] |
|
296ab1038b7f
Issue 3048: Fixed sys.getsizeof for unicode objects.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47423
diff
changeset
|
731 # we need to test for both sizes, because we don't know if the string |
|
296ab1038b7f
Issue 3048: Fixed sys.getsizeof for unicode objects.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47423
diff
changeset
|
732 # has been cached |
|
296ab1038b7f
Issue 3048: Fixed sys.getsizeof for unicode objects.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47423
diff
changeset
|
733 for s in samples: |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
734 check(s, size('PPlP') + usize * (len(s) + 1)) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
735 # weakref |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
736 import weakref |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
737 check(weakref.ref(int), size('2Pl2P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
738 # weakproxy |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
739 # XXX |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
740 # weakcallableproxy |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
741 check(weakref.proxy(int), size('2Pl2P')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
742 # xrange |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
743 check(xrange(1), size('3l')) |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
744 check(xrange(66000), size('3l')) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
745 |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
746 def test_pythontypes(self): |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
747 # check all types defined in Python/ |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
748 size = test.test_support.calcobjsize |
|
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
749 vsize = test.test_support.calcvobjsize |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
750 check = self.check_sizeof |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
751 # _ast.AST |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
752 import _ast |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
753 check(_ast.AST(), size('')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
754 # imp.NullImporter |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
755 import imp |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
756 check(imp.NullImporter(self.file.name), size('')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
757 try: |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
758 raise TypeError |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
759 except TypeError: |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
760 tb = sys.exc_info()[2] |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
761 # traceback |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
762 if tb != None: |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
763 check(tb, size('2P2i')) |
|
47918
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
764 # symtable entry |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
765 # XXX |
|
68c7964d2534
Fixed Issue3122 and extended sys.getsizeof tests for built-in types.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47900
diff
changeset
|
766 # sys.flags |
|
78317
fa95b04e67fd
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Martin v. Löwis <martin@v.loewis.de>
parents:
75102
diff
changeset
|
767 check(sys.flags, vsize('') + self.P * len(sys.flags)) |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
768 |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
769 |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
770 def test_main(): |
|
47419
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
771 test_classes = (SysModuleTest, SizeofTest) |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
772 |
|
88bd07c0a847
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47413
diff
changeset
|
773 test.test_support.run_unittest(*test_classes) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
774 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
775 if __name__ == "__main__": |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
776 test_main() |
