Skip to content

Commit 35731f3

Browse files
committed
Update tests
1 parent 4b3db9e commit 35731f3

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

Lib/idlelib/idle_test/test_warning.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import warnings
1111
from test.support import captured_stderr
1212
from types import ModuleType
13+
import io
14+
from contextlib import redirect_stdout
1315

1416
from idlelib import pyshell as shell
1517
from idlelib import run
@@ -74,18 +76,13 @@ def test_shell_show(self):
7476

7577

7678
class TestDeprecatedHelp(unittest.TestCase):
77-
78-
def test_help_output(self):
79-
# Capture the help output
80-
import io
81-
from contextlib import redirect_stdout
82-
code = r"""\
79+
CODE_SIMPLE = r"""
8380
from warnings import deprecated
8481
@deprecated("Test")
8582
class A:
8683
pass
8784
"""
88-
subclass_code = r"""\
85+
CODE_SUBCLASS = r"""
8986
from warnings import deprecated
9087
@deprecated("Test")
9188
class A:
@@ -95,17 +92,28 @@ class B(A):
9592
pass
9693
b = B()
9794
"""
98-
module = ModuleType("testmodule")
99-
for kode in (code,subclass_code):
100-
exec(kode, module.__dict__)
101-
sys.modules["testmodule"] = module
102-
f = io.StringIO()
103-
with redirect_stdout(f):
104-
help(module)
105-
help_output = f.getvalue()
106-
self.assertIn("Help on module testmodule:", help_output)
95+
def setUp(self):
96+
self.module = ModuleType("testmodule")
97+
98+
def tearDown(self):
99+
if "testmodule" in sys.modules:
107100
del sys.modules["testmodule"]
108101

102+
def _get_help_output(self, code):
103+
exec(code, self.module.__dict__)
104+
sys.modules["testmodule"] = self.module
105+
106+
f = io.StringIO()
107+
with redirect_stdout(f):
108+
help(self.module)
109+
return f.getvalue()
110+
111+
def test_help_output(self):
112+
for code in (self.CODE_SIMPLE, self.CODE_SUBCLASS):
113+
with self.subTest(code=code):
114+
help_output = self._get_help_output(code)
115+
self.assertIn("Help on module testmodule:", help_output)
116+
109117

110118
if __name__ == '__main__':
111119
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)