mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
85c0b8941f
commit
543386b7f0
|
@ -328,19 +328,22 @@ class BuiltinTest(unittest.TestCase):
|
||||||
|
|
||||||
codestr = '''def f():
|
codestr = '''def f():
|
||||||
"""doc"""
|
"""doc"""
|
||||||
|
debug_enabled = False
|
||||||
|
if __debug__:
|
||||||
|
debug_enabled = True
|
||||||
try:
|
try:
|
||||||
assert False
|
assert False
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
return (True, f.__doc__)
|
return (True, f.__doc__, debug_enabled)
|
||||||
else:
|
else:
|
||||||
return (False, f.__doc__)
|
return (False, f.__doc__, debug_enabled)
|
||||||
'''
|
'''
|
||||||
def f(): """doc"""
|
def f(): """doc"""
|
||||||
values = [(-1, __debug__, f.__doc__),
|
values = [(-1, __debug__, f.__doc__, __debug__),
|
||||||
(0, True, 'doc'),
|
(0, True, 'doc', True),
|
||||||
(1, False, 'doc'),
|
(1, False, 'doc', False),
|
||||||
(2, False, None)]
|
(2, False, None, False)]
|
||||||
for optval, debugval, docstring in values:
|
for optval, assertval, docstring, debugval in values:
|
||||||
# test both direct compilation and compilation via AST
|
# test both direct compilation and compilation via AST
|
||||||
codeobjs = []
|
codeobjs = []
|
||||||
codeobjs.append(compile(codestr, "<test>", "exec", optimize=optval))
|
codeobjs.append(compile(codestr, "<test>", "exec", optimize=optval))
|
||||||
|
@ -350,7 +353,7 @@ class BuiltinTest(unittest.TestCase):
|
||||||
ns = {}
|
ns = {}
|
||||||
exec(code, ns)
|
exec(code, ns)
|
||||||
rv = ns['f']()
|
rv = ns['f']()
|
||||||
self.assertEqual(rv, (debugval, docstring))
|
self.assertEqual(rv, (assertval, docstring, debugval))
|
||||||
|
|
||||||
def test_delattr(self):
|
def test_delattr(self):
|
||||||
sys.spam = 1
|
sys.spam = 1
|
||||||
|
|
Loading…
Reference in New Issue