|
5 | 5 | Revise if output destination changes (http://bugs.python.org/issue18318). |
6 | 6 | Make sure warnings module is left unaltered (http://bugs.python.org/issue18081). |
7 | 7 | ''' |
8 | | -import io |
9 | | -import sys |
| 8 | +from idlelib import run |
| 9 | +from idlelib import pyshell as shell |
10 | 10 | import unittest |
11 | | -import warnings |
12 | | -from contextlib import redirect_stdout |
13 | 11 | from test.support import captured_stderr |
14 | | -from types import ModuleType |
15 | | - |
16 | | -from idlelib import pyshell as shell |
17 | | -from idlelib import run |
18 | | - |
| 12 | +import warnings |
19 | 13 |
|
20 | 14 | # Try to capture default showwarning before Idle modules are imported. |
21 | 15 | showwarning = warnings.showwarning |
@@ -75,49 +69,5 @@ def test_shell_show(self): |
75 | 69 | self.assertEqual(shellmsg.splitlines(), f.getvalue().splitlines()) |
76 | 70 |
|
77 | 71 |
|
78 | | -class TestDeprecatedHelp(unittest.TestCase): |
79 | | - CODE_SIMPLE = r""" |
80 | | -from warnings import deprecated |
81 | | -@deprecated("Test") |
82 | | -class A: |
83 | | - pass |
84 | | -a = A() |
85 | | -""" |
86 | | - CODE_SUBCLASS = r""" |
87 | | -from warnings import deprecated |
88 | | -@deprecated("Test") |
89 | | -class A: |
90 | | - def __init_subclass__(self, **kwargs): |
91 | | - pass |
92 | | -class B(A): |
93 | | - pass |
94 | | -b = B() |
95 | | -""" |
96 | | - def setUp(self): |
97 | | - self.module = ModuleType("testmodule") |
98 | | - |
99 | | - def tearDown(self): |
100 | | - if "testmodule" in sys.modules: |
101 | | - del sys.modules["testmodule"] |
102 | | - |
103 | | - def _get_help_output(self, code): |
104 | | - with self.assertWarns(DeprecationWarning) as cm: |
105 | | - exec(code, self.module.__dict__) |
106 | | - sys.modules["testmodule"] = self.module |
107 | | - |
108 | | - f = io.StringIO() |
109 | | - with redirect_stdout(f): |
110 | | - help(self.module) |
111 | | - |
112 | | - self.assertEqual(str(cm.warning), "Test") |
113 | | - return f.getvalue() |
114 | | - |
115 | | - def test_help_output(self): |
116 | | - for code in (self.CODE_SIMPLE, self.CODE_SUBCLASS): |
117 | | - with self.subTest(code=code): |
118 | | - help_output = self._get_help_output(code) |
119 | | - self.assertIn("Help on module testmodule:", help_output) |
120 | | - |
121 | | - |
122 | 72 | if __name__ == '__main__': |
123 | 73 | unittest.main(verbosity=2) |
0 commit comments