Skip to content

Commit 3c2c9d3

Browse files
committed
Move the test case to here from Lib/idlelib/idle_test/test_warning.py
1 parent 8b54982 commit 3c2c9d3

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

Lib/test/test_warnings/__init__.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from contextlib import contextmanager
1+
from contextlib import contextmanager, redirect_stdout
22
import linecache
33
import os
44
import importlib
@@ -1821,6 +1821,50 @@ async def coro(self):
18211821
self.assertFalse(inspect.iscoroutinefunction(Cls.sync))
18221822
self.assertTrue(inspect.iscoroutinefunction(Cls.coro))
18231823

1824+
1825+
class TestDeprecatedHelp(unittest.TestCase):
1826+
CODE_SIMPLE = r"""
1827+
from warnings import deprecated
1828+
@deprecated("Test")
1829+
class A:
1830+
pass
1831+
a = A()
1832+
"""
1833+
CODE_SUBCLASS = r"""
1834+
from warnings import deprecated
1835+
@deprecated("Test")
1836+
class A:
1837+
def __init_subclass__(self, **kwargs):
1838+
pass
1839+
class B(A):
1840+
pass
1841+
b = B()
1842+
"""
1843+
def setUp(self):
1844+
self.module = types.ModuleType("testmodule")
1845+
1846+
def tearDown(self):
1847+
if "testmodule" in sys.modules:
1848+
del sys.modules["testmodule"]
1849+
1850+
def _get_help_output(self, code):
1851+
with self.assertWarns(DeprecationWarning) as cm:
1852+
exec(code, self.module.__dict__)
1853+
sys.modules["testmodule"] = self.module
1854+
1855+
f = StringIO()
1856+
with redirect_stdout(f):
1857+
help(self.module)
1858+
1859+
self.assertEqual(str(cm.warning), "Test")
1860+
return f.getvalue()
1861+
1862+
def test_help_output(self):
1863+
for code in (self.CODE_SIMPLE, self.CODE_SUBCLASS):
1864+
with self.subTest(code=code):
1865+
help_output = self._get_help_output(code)
1866+
self.assertIn("Help on module testmodule:", help_output)
1867+
18241868
def setUpModule():
18251869
py_warnings.onceregistry.clear()
18261870
c_warnings.onceregistry.clear()

0 commit comments

Comments
 (0)