Content-Length: 2642 | pFad | http://github.com/python/cpython/pull/136478.diff
thub.com
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 57e5f29b015637..8b6cfec44fdeb4 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -583,18 +583,19 @@ def test_compile_ast(self):
with open(fname, encoding='utf-8') as f:
fcontents = f.read()
sample_code = [
- ['', 'x = 5'],
- ['', """if True:\n pass\n"""],
- ['', """for n in [1, 2, 3]:\n print(n)\n"""],
- ['', """def foo():\n pass\nfoo()\n"""],
- [fname, fcontents],
+ [2, '', 'x = 5'],
+ [2, '', """if True:\n pass\n"""],
+ [1, '', """for n in [1, 2, 3]:\n print(n)\n"""],
+ [1, '', """def foo():\n pass\nfoo()\n"""],
+ [0, fname, fcontents],
]
- for fname, code in sample_code:
- co1 = compile(code, '%s1' % fname, 'exec')
- ast = compile(code, '%s2' % fname, 'exec', _ast.PyCF_ONLY_AST)
+ for optval, fname, code in sample_code:
+ co1 = compile(code, '%s1' % fname, 'exec', optimize=optval)
+ ast = compile(code, '%s2' % fname, 'exec', _ast.PyCF_ONLY_AST,
+ optimize=optval)
self.assertTrue(type(ast) == _ast.Module)
- co2 = compile(ast, '%s3' % fname, 'exec')
+ co2 = compile(ast, '%s3' % fname, 'exec', optimize=optval)
self.assertEqual(co1, co2)
# the code object's filename comes from the second compilation step
self.assertEqual(co2.co_filename, '%s3' % fname)
@@ -823,8 +824,10 @@ def f():
else:
return "unused"
- self.assertEqual(f.__code__.co_consts,
- (f.__doc__, "used"))
+ if f.__doc__ is None:
+ self.assertEqual(f.__code__.co_consts, (True, "used"))
+ else:
+ self.assertEqual(f.__code__.co_consts, (f.__doc__, "used"))
@support.cpython_only
def test_remove_unused_consts_no_docstring(self):
@@ -869,7 +872,11 @@ def test_strip_unused_None(self):
def f1():
"docstring"
return 42
- self.assertEqual(f1.__code__.co_consts, (f1.__doc__,))
+
+ if f1.__doc__ is None:
+ self.assertEqual(f1.__code__.co_consts, (42,))
+ else:
+ self.assertEqual(f1.__code__.co_consts, (f1.__doc__,))
# This is a regression test for a CPython specific peephole optimizer
# implementation bug present in a few releases. It's assertion verifies
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/python/cpython/pull/136478.diff
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy