Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_sys.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 226463445697 |
| children | 869695cba2cd |
| 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 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
3 import sys, cStringIO |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
4 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
5 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
|
6 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
7 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
|
8 import __builtin__ |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
9 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
|
10 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
|
11 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
|
12 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
13 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
|
14 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
15 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
|
16 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
|
17 del __builtin__._ |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
18 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
19 dh(None) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
20 self.assertEqual(out.getvalue(), "") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
21 self.assert_(not 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 dh(42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
23 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
|
24 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
|
25 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
26 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
|
27 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
|
28 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
29 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
|
30 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 raise ValueError |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 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
|
46 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
52 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
|
53 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
54 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
|
55 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
60 sys.stderr = savestderr |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
61 self.assert_(err.getvalue().endswith("ValueError: 42\n")) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
62 |
| 27661 | 63 # 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
|
64 # 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
|
65 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
66 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
|
67 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
|
68 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
69 # 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
|
70 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
71 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
|
72 except SystemExit, exc: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
73 self.assertEquals(exc.code, 0) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
74 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
75 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
|
76 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
77 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
|
78 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
79 # 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
|
80 # 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
|
81 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
82 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
|
83 except SystemExit, exc: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
84 self.assertEquals(exc.code, 42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
85 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
86 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
|
87 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
88 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
|
89 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
90 # 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
|
91 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
92 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
|
93 except SystemExit, exc: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
94 self.assertEquals(exc.code, 42) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
95 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
96 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
|
97 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
98 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
|
99 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
100 # 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
|
101 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
102 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
|
103 except SystemExit, exc: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
104 self.assertEquals(exc.code, "exit") |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
105 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
106 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
|
107 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
108 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
|
109 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
110 # 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
|
111 try: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
112 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
|
113 except SystemExit, exc: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
114 self.assertEquals(exc.code, (17, 23)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
115 except: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
116 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
|
117 else: |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
118 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
|
119 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 # can't check more than the type, as the user might have changed it |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
124 self.assert_(isinstance(sys.getdefaultencoding(), str)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
125 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
126 # testing sys.settrace() is done in test_trace.py |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
127 # testing sys.setprofile() is done in test_profile.py |
|
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 def test_setcheckinterval(self): |
|
27963
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
130 self.assertRaises(TypeError, sys.setcheckinterval) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
131 sys.setcheckinterval(120) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
132 sys.setcheckinterval(100) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
133 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
134 def test_recursionlimit(self): |
|
27963
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
135 self.assertRaises(TypeError, sys.getrecursionlimit, 42) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
136 oldlimit = sys.getrecursionlimit() |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
137 self.assertRaises(TypeError, sys.setrecursionlimit) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
138 self.assertRaises(ValueError, sys.setrecursionlimit, -42) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
139 sys.setrecursionlimit(10000) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
140 self.assertEqual(sys.getrecursionlimit(), 10000) |
|
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27934
diff
changeset
|
141 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
|
142 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
143 def test_getwindowsversion(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
144 if hasattr(sys, "getwindowsversion"): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
145 v = sys.getwindowsversion() |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
146 self.assert_(isinstance(v, tuple)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
147 self.assertEqual(len(v), 5) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
148 self.assert_(isinstance(v[0], int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
149 self.assert_(isinstance(v[1], int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
150 self.assert_(isinstance(v[2], int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
151 self.assert_(isinstance(v[3], int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
152 self.assert_(isinstance(v[4], str)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
153 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
154 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
|
155 if hasattr(sys, "setdlopenflags"): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
156 self.assert_(hasattr(sys, "getdlopenflags")) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
164 def test_refcount(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
165 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
|
166 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
|
167 n = None |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
168 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
|
169 del n |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
170 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
|
171 if hasattr(sys, "gettotalrefcount"): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
172 self.assert_(isinstance(sys.gettotalrefcount(), int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
173 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
174 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
|
175 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
|
176 self.assertRaises(ValueError, sys._getframe, 2000000000) |
|
27660
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
177 self.assert_( |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
178 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
|
179 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
|
180 ) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
181 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
182 def test_attributes(self): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
183 self.assert_(isinstance(sys.api_version, int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
184 self.assert_(isinstance(sys.argv, list)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
185 self.assert_(sys.byteorder in ("little", "big")) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
186 self.assert_(isinstance(sys.builtin_module_names, tuple)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
187 self.assert_(isinstance(sys.copyright, basestring)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
188 self.assert_(isinstance(sys.exec_prefix, basestring)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
189 self.assert_(isinstance(sys.executable, basestring)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
190 self.assert_(isinstance(sys.hexversion, int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
191 self.assert_(isinstance(sys.maxint, int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
192 self.assert_(isinstance(sys.maxunicode, int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
193 self.assert_(isinstance(sys.platform, basestring)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
194 self.assert_(isinstance(sys.prefix, basestring)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
195 self.assert_(isinstance(sys.version, basestring)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
196 vi = sys.version_info |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
197 self.assert_(isinstance(vi, tuple)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
198 self.assertEqual(len(vi), 5) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
199 self.assert_(isinstance(vi[0], int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
200 self.assert_(isinstance(vi[1], int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
201 self.assert_(isinstance(vi[2], int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
202 self.assert_(vi[3] in ("alpha", "beta", "candidate", "final")) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
203 self.assert_(isinstance(vi[4], int)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
204 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
205 def test_main(): |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
206 suite = unittest.TestSuite() |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
207 suite.addTest(unittest.makeSuite(SysModuleTest)) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
208 test.test_support.run_suite(suite) |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
209 |
|
6a1394660270
Add a new test script that tests various features of the sys
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
210 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
|
211 test_main() |
