summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compile.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_compile.py')
-rw-r--r--Lib/test/test_compile.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index f22761f..736eff3 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -903,6 +903,28 @@ class TestSpecifics(unittest.TestCase):
self.assertIsNone(ns['with_const_expression'].__doc__)
@support.cpython_only
+ def test_docstring_interactive_mode(self):
+ srcs = [
+ """def with_docstring():
+ "docstring"
+ """,
+ """class with_docstring:
+ "docstring"
+ """,
+ ]
+
+ for opt in [0, 1, 2]:
+ for src in srcs:
+ with self.subTest(opt=opt, src=src):
+ code = compile(textwrap.dedent(src), "<test>", "single", optimize=opt)
+ ns = {}
+ exec(code, ns)
+ if opt < 2:
+ self.assertEqual(ns['with_docstring'].__doc__, "docstring")
+ else:
+ self.assertIsNone(ns['with_docstring'].__doc__)
+
+ @support.cpython_only
def test_docstring_omitted(self):
# See gh-115347
src = textwrap.dedent("""
@@ -919,12 +941,13 @@ class TestSpecifics(unittest.TestCase):
return h
""")
for opt in [-1, 0, 1, 2]:
- with self.subTest(opt=opt):
- code = compile(src, "<test>", "exec", optimize=opt)
- output = io.StringIO()
- with contextlib.redirect_stdout(output):
- dis.dis(code)
- self.assertNotIn('NOP' , output.getvalue())
+ for mode in ["exec", "single"]:
+ with self.subTest(opt=opt, mode=mode):
+ code = compile(src, "<test>", mode, optimize=opt)
+ output = io.StringIO()
+ with contextlib.redirect_stdout(output):
+ dis.dis(code)
+ self.assertNotIn('NOP', output.getvalue())
def test_dont_merge_constants(self):
# Issue #25843: compile() must not merge constants which are equal