summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authordiana <diana.joan.clarke@gmail.com>2017-10-03 16:46:56 (GMT)
committerMariatta <Mariatta@users.noreply.github.com>2017-10-03 16:46:56 (GMT)
commit543386b7f077d210ea0722079d68beb6c066730a (patch)
tree31d5bdeb02e8ac9c243d646832f3e0a3687b27f5 /Lib
parent85c0b8941f0c8ef3ed787c9d504712c6ad3eb5d3 (diff)
downloadcpython-543386b7f077d210ea0722079d68beb6c066730a.zip
cpython-543386b7f077d210ea0722079d68beb6c066730a.tar.gz
cpython-543386b7f077d210ea0722079d68beb6c066730a.tar.bz2
bpo-31657: Add test coverage for the __debug__ case (GH-3450)
Update the compile tests for optimization levels to also check that __debug__ blocks are included or excluded based on the optimization level. Patch by Diana Clarke.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_builtin.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 9d949b7..87dcda7 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -328,19 +328,22 @@ class BuiltinTest(unittest.TestCase):
codestr = '''def f():
"""doc"""
+ debug_enabled = False
+ if __debug__:
+ debug_enabled = True
try:
assert False
except AssertionError:
- return (True, f.__doc__)
+ return (True, f.__doc__, debug_enabled)
else:
- return (False, f.__doc__)
+ return (False, f.__doc__, debug_enabled)
'''
def f(): """doc"""
- values = [(-1, __debug__, f.__doc__),
- (0, True, 'doc'),
- (1, False, 'doc'),
- (2, False, None)]
- for optval, debugval, docstring in values:
+ values = [(-1, __debug__, f.__doc__, __debug__),
+ (0, True, 'doc', True),
+ (1, False, 'doc', False),
+ (2, False, None, False)]
+ for optval, assertval, docstring, debugval in values:
# test both direct compilation and compilation via AST
codeobjs = []
codeobjs.append(compile(codestr, "<test>", "exec", optimize=optval))
@@ -350,7 +353,7 @@ class BuiltinTest(unittest.TestCase):
ns = {}
exec(code, ns)
rv = ns['f']()
- self.assertEqual(rv, (debugval, docstring))
+ self.assertEqual(rv, (assertval, docstring, debugval))
def test_delattr(self):
sys.spam = 1