Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3001)

Unified Diff: Lib/test/test_builtin.py

Issue 10553: Add optimize argument to builtin compile() and byte-compilation modules
Patch Set: Created 2 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/py_compile.py ('k') | Lib/test/test_compileall.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Lib/test/test_builtin.py
===================================================================
--- Lib/test/test_builtin.py (Revision 86724)
+++ Lib/test/test_builtin.py (Arbeitskopie)
@@ -6,6 +6,7 @@
import warnings
import collections
import io
+import ast
import types
import builtins
import random
@@ -268,6 +269,34 @@
self.assertRaises(TypeError, compile, chr(0), 'f', 'exec')
self.assertRaises(ValueError, compile, str('a = 1'), 'f', 'bad')
+ # test the optimize argument
+
+ codestr = '''def f():
+ """doc"""
+ try:
+ assert False
+ except AssertionError:
+ return (True, f.__doc__)
+ else:
+ return (False, f.__doc__)
+ '''
+ def f(): """doc"""
+ values = [(-1, __debug__, f.__doc__),
+ (0, True, 'doc'),
+ (1, False, 'doc'),
+ (2, False, None)]
+ for optval, debugval, docstring in values:
+ # test both direct compilation and compilation via AST
+ codeobjs = []
+ codeobjs.append(compile(codestr, "<test>", "exec", optimize=optval))
+ tree = ast.parse(codestr)
+ codeobjs.append(compile(tree, "<test>", "exec", optimize=optval))
+ for code in codeobjs:
+ ns = {}
+ exec(code, ns)
+ rv = ns['f']()
+ self.assertEqual(rv, (debugval, docstring))
+
def test_delattr(self):
sys.spam = 1
delattr(sys, 'spam')
« no previous file with comments | « Lib/py_compile.py ('k') | Lib/test/test_compileall.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7