diff options
Diffstat (limited to 'Lib/test')
30 files changed, 91 insertions, 110 deletions
diff --git a/Lib/test/crashers/bogus_code_obj.py b/Lib/test/crashers/bogus_code_obj.py index 613ae51..43815c1 100644 --- a/Lib/test/crashers/bogus_code_obj.py +++ b/Lib/test/crashers/bogus_code_obj.py @@ -16,4 +16,4 @@ import types co = types.CodeType(0, 0, 0, 0, '\x04\x71\x00\x00', (), (), (), '', '', 1, '') -exec co +exec(co) diff --git a/Lib/test/output/test_cProfile b/Lib/test/output/test_cProfile index fff3568..f9483a3 100644 --- a/Lib/test/output/test_cProfile +++ b/Lib/test/output/test_cProfile @@ -1,5 +1,5 @@ test_cProfile - 126 function calls (106 primitive calls) in 1.000 CPU seconds + 127 function calls (107 primitive calls) in 1.000 CPU seconds Ordered by: standard name @@ -14,6 +14,7 @@ test_cProfile 4 0.116 0.029 0.120 0.030 test_cProfile.py:78(helper1) 2 0.000 0.000 0.140 0.070 test_cProfile.py:89(helper2_indirect) 8 0.312 0.039 0.400 0.050 test_cProfile.py:93(helper2) + 1 0.000 0.000 1.000 1.000 {exec} 12 0.000 0.000 0.012 0.001 {hasattr} 4 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} @@ -44,6 +45,7 @@ test_cProfile.py:89(helper2_indirect) -> 2 0.006 0.040 2 0.078 0.100 test_cProfile.py:93(helper2) test_cProfile.py:93(helper2) -> 8 0.064 0.080 test_cProfile.py:103(subhelper) 8 0.000 0.008 {hasattr} +{exec} -> 1 0.000 1.000 <string>:1(<module>) {hasattr} -> 12 0.012 0.012 test_cProfile.py:115(__getattr__) {method 'append' of 'list' objects} -> {method 'disable' of '_lsprof.Profiler' objects} -> @@ -55,7 +57,7 @@ test_cProfile.py:93(helper2) -> 8 0.064 0.080 Function was called by... ncalls tottime cumtime -<string>:1(<module>) <- +<string>:1(<module>) <- 1 0.000 1.000 {exec} test_cProfile.py:103(subhelper) <- 8 0.064 0.080 test_cProfile.py:93(helper2) test_cProfile.py:115(__getattr__) <- 16 0.016 0.016 test_cProfile.py:103(subhelper) 12 0.012 0.012 {hasattr} @@ -69,6 +71,7 @@ test_cProfile.py:78(helper1) <- 4 0.116 0.120 test_cProfile.py:89(helper2_indirect) <- 2 0.000 0.140 test_cProfile.py:60(helper) test_cProfile.py:93(helper2) <- 6 0.234 0.300 test_cProfile.py:60(helper) 2 0.078 0.100 test_cProfile.py:89(helper2_indirect) +{exec} <- {hasattr} <- 4 0.000 0.004 test_cProfile.py:78(helper1) 8 0.000 0.008 test_cProfile.py:93(helper2) {method 'append' of 'list' objects} <- 4 0.000 0.000 test_cProfile.py:78(helper1) diff --git a/Lib/test/output/test_grammar b/Lib/test/output/test_grammar index 4fa9cb0..8be2a1f 100644 --- a/Lib/test/output/test_grammar +++ b/Lib/test/output/test_grammar @@ -39,7 +39,6 @@ raise_stmt import_name import_from global_stmt -exec_stmt assert_stmt if_stmt while_stmt diff --git a/Lib/test/output/test_profile b/Lib/test/output/test_profile index 96bd77f..14bd9ac 100644 --- a/Lib/test/output/test_profile +++ b/Lib/test/output/test_profile @@ -1,11 +1,12 @@ test_profile - 127 function calls (107 primitive calls) in 1.000 CPU seconds + 128 function calls (108 primitive calls) in 1.000 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 4 0.000 0.000 0.000 0.000 :0(append) 4 0.000 0.000 0.000 0.000 :0(exc_info) + 1 0.000 0.000 1.000 1.000 :0(exec) 12 0.000 0.000 0.012 0.001 :0(hasattr) 8 0.000 0.000 0.000 0.000 :0(range) 1 0.000 0.000 0.000 0.000 :0(setprofile) @@ -28,13 +29,14 @@ test_profile Function called... :0(append) -> :0(exc_info) -> +:0(exec) -> <string>:1(<module>)(1) 1.000 :0(hasattr) -> test_profile.py:115(__getattr__)(12) 0.028 :0(range) -> :0(setprofile) -> <string>:1(<module>) -> test_profile.py:30(testfunc)(1) 1.000 profile:0(profiler) -> profile:0(testfunc())(1) 1.000 -profile:0(testfunc()) -> :0(setprofile)(1) 0.000 - <string>:1(<module>)(1) 1.000 +profile:0(testfunc()) -> :0(exec)(1) 1.000 + :0(setprofile)(1) 0.000 test_profile.py:103(subhelper) -> :0(range)(8) 0.000 test_profile.py:115(__getattr__)(16) 0.028 test_profile.py:115(__getattr__) -> @@ -60,11 +62,12 @@ test_profile.py:93(helper2) -> :0(hasattr)(8) 0.012 Function was called by... :0(append) <- test_profile.py:78(helper1)(4) 0.120 :0(exc_info) <- test_profile.py:78(helper1)(4) 0.120 +:0(exec) <- profile:0(testfunc())(1) 1.000 :0(hasattr) <- test_profile.py:78(helper1)(4) 0.120 test_profile.py:93(helper2)(8) 0.400 :0(range) <- test_profile.py:103(subhelper)(8) 0.080 :0(setprofile) <- profile:0(testfunc())(1) 1.000 -<string>:1(<module>) <- profile:0(testfunc())(1) 1.000 +<string>:1(<module>) <- :0(exec)(1) 1.000 profile:0(profiler) <- profile:0(testfunc()) <- profile:0(profiler)(1) 0.000 test_profile.py:103(subhelper) <- test_profile.py:93(helper2)(8) 0.400 diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py index dba9161..e4f0f44 100644 --- a/Lib/test/test___all__.py +++ b/Lib/test/test___all__.py @@ -15,7 +15,7 @@ class AllTest(unittest.TestCase): def check_all(self, modname): names = {} try: - exec "import %s" % modname in names + exec("import %s" % modname, names) except ImportError: # Silent fail here seems the best route since some modules # may not be available in all environments. @@ -23,7 +23,7 @@ class AllTest(unittest.TestCase): verify(hasattr(sys.modules[modname], "__all__"), "%s has no __all__ attribute" % modname) names = {} - exec "from %s import *" % modname in names + exec("from %s import *" % modname, names) if "__builtins__" in names: del names["__builtins__"] keys = set(names) diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 80e8d78..f1df3eb 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -50,8 +50,6 @@ exec_tests = [ "import sys", # ImportFrom "from sys import v", - # Exec - "exec 'v'", # Global "global v", # Expr @@ -169,7 +167,6 @@ exec_results = [ ('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]), ('Module', [('Import', (1, 0), [('alias', 'sys', None)])]), ('Module', [('ImportFrom', (1, 0), 'sys', [('alias', 'v', None)], 0)]), -('Module', [('Exec', (1, 0), ('Str', (1, 5), 'v'), None, None)]), ('Module', [('Global', (1, 0), ['v'])]), ('Module', [('Expr', (1, 0), ('Num', (1, 0), 1))]), ('Module', [('Pass', (1, 0))]), diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py index 719186b..ccce207 100644 --- a/Lib/test/test_binop.py +++ b/Lib/test/test_binop.py @@ -302,7 +302,7 @@ class RatTestCase(unittest.TestCase): self.assertEqual(10.0, Rat(10)) def test_future_div(self): - exec future_test + exec(future_test) # XXX Ran out of steam; TO DO: divmod, div, future division diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index d4605e1..272af86 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -395,6 +395,29 @@ class BuiltinTest(unittest.TestCase): self.assertRaises(IOError, execfile, os.curdir) self.assertRaises(IOError, execfile, "I_dont_exist") + def test_exec(self): + g = {} + exec('z = 1', g) + if '__builtins__' in g: + del g['__builtins__'] + self.assertEqual(g, {'z': 1}) + + exec(u'z = 1+1', g) + if '__builtins__' in g: + del g['__builtins__'] + self.assertEqual(g, {'z': 2}) + g = {} + l = {} + + import warnings + warnings.filterwarnings("ignore", "global statement", module="<string>") + exec('global a; a = 1; b = 2', g, l) + if '__builtins__' in g: + del g['__builtins__'] + if '__builtins__' in l: + del l['__builtins__'] + self.assertEqual((g, l), ({'a': 1}, {'b': 2})) + def test_filter(self): self.assertEqual(filter(lambda c: 'a' <= c <= 'z', 'Hello World'), 'elloorld') self.assertEqual(filter(None, [1, 'hello', [], [3], '', None, 9, 0]), [1, 'hello', [3], 9]) @@ -1172,7 +1195,7 @@ class BuiltinTest(unittest.TestCase): "max(1, 2, key=1)", # keyfunc is not callable ): try: - exec(stmt) in globals() + exec(stmt, globals()) except TypeError: pass else: @@ -1218,7 +1241,7 @@ class BuiltinTest(unittest.TestCase): "min(1, 2, key=1)", # keyfunc is not callable ): try: - exec(stmt) in globals() + exec(stmt, globals()) except TypeError: pass else: diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 795acd9..f33462a 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -136,7 +136,7 @@ def __%(method)s__(self, *args): d = {} for method in testmeths: - exec method_template % locals() in d + exec(method_template % locals(), d) for k in d: setattr(AllTests, k, d[k]) del d, k @@ -291,7 +291,7 @@ def check_exc(stmt, exception): """Raise TestFailed if executing 'stmt' does not raise 'exception' """ try: - exec stmt + exec(stmt) except exception: pass else: diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py index 5d06f2c..38a192b 100644 --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -29,8 +29,8 @@ class CodeopTests(unittest.TestCase): saved_stdout = sys.stdout sys.stdout = cStringIO.StringIO() try: - exec code in d - exec compile(str,"<input>","single") in r + exec(code, d) + exec(compile(str,"<input>","single"), r) finally: sys.stdout = saved_stdout elif symbol == 'eval': diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index a3f15bf..73ef2d4 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -19,17 +19,17 @@ class TestSpecifics(unittest.TestCase): self.assertRaises(SyntaxError, eval, 'lambda a,a=1:0') self.assertRaises(SyntaxError, eval, 'lambda a=1,a=1:0') try: - exec 'def f(a, a): pass' + exec('def f(a, a): pass') self.fail("duplicate arguments") except SyntaxError: pass try: - exec 'def f(a = 0, a = 1): pass' + exec('def f(a = 0, a = 1): pass') self.fail("duplicate keyword arguments") except SyntaxError: pass try: - exec 'def f(a): global a; a = 1' + exec('def f(a): global a; a = 1') self.fail("variable is global and local") except SyntaxError: pass @@ -39,7 +39,7 @@ class TestSpecifics(unittest.TestCase): def test_duplicate_global_local(self): try: - exec 'def f(a): global a; a = 1' + exec('def f(a): global a; a = 1') self.fail("variable is global and local") except SyntaxError: pass @@ -59,22 +59,22 @@ class TestSpecifics(unittest.TestCase): m = M() g = globals() - exec 'z = a' in g, m + exec('z = a', g, m) self.assertEqual(m.results, ('z', 12)) try: - exec 'z = b' in g, m + exec('z = b', g, m) except NameError: pass else: self.fail('Did not detect a KeyError') - exec 'z = dir()' in g, m + exec('z = dir()', g, m) self.assertEqual(m.results, ('z', list('xyz'))) - exec 'z = globals()' in g, m + exec('z = globals()', g, m) self.assertEqual(m.results, ('z', g)) - exec 'z = locals()' in g, m + exec('z = locals()', g, m) self.assertEqual(m.results, ('z', m)) try: - exec 'z = b' in m + exec('z = b', m) except TypeError: pass else: @@ -85,7 +85,7 @@ class TestSpecifics(unittest.TestCase): pass m = A() try: - exec 'z = a' in g, m + exec('z = a', g, m) except TypeError: pass else: @@ -98,11 +98,12 @@ class TestSpecifics(unittest.TestCase): return 12 return dict.__getitem__(self, key) d = D() - exec 'z = a' in g, d + exec('z = a', g, d) self.assertEqual(d['z'], 12) def test_extended_arg(self): longexpr = 'x = x or ' + '-x' * 2500 + g = {} code = ''' def f(x): %s @@ -121,8 +122,8 @@ def f(x): # EXTENDED_ARG/JUMP_ABSOLUTE here return x ''' % ((longexpr,)*10) - exec code - self.assertEqual(f(5), 0) + exec(code, g) + self.assertEqual(g['f'](5), 0) def test_complex_args(self): @@ -146,7 +147,7 @@ def f(x): def test_argument_order(self): try: - exec 'def f(a=1, (b, c)): pass' + exec('def f(a=1, (b, c)): pass') self.fail("non-default args after default") except SyntaxError: pass diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py index 81f2ea8..783a34c 100644 --- a/Lib/test/test_compiler.py +++ b/Lib/test/test_compiler.py @@ -61,7 +61,7 @@ class CompilerTest(unittest.TestCase): c = compiler.compile("try:\n 1/0\nexcept:\n e = 1\nfinally:\n f = 1", "<string>", "exec") dct = {} - exec c in dct + exec(c, dct) self.assertEquals(dct.get('e'), 1) self.assertEquals(dct.get('f'), 1) @@ -73,7 +73,7 @@ class CompilerTest(unittest.TestCase): self.assert_('__doc__' in c.co_names) c = compiler.compile('def f():\n "doc"', '<string>', 'exec') g = {} - exec c in g + exec(c, g) self.assertEquals(g['f'].__doc__, "doc") def testLineNo(self): @@ -113,7 +113,7 @@ class CompilerTest(unittest.TestCase): '<string>', 'exec') dct = {} - exec c in dct + exec(c, dct) self.assertEquals(dct.get('result'), 3) def testGenExp(self): diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 53054ad..b2e7e66 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -55,7 +55,7 @@ def testternop(a, b, c, res, expr="a[b:c]", meth="__getslice__"): def testsetop(a, b, res, stmt="a+=b", meth="__iadd__"): if verbose: print "checking", stmt dict = {'a': deepcopy(a), 'b': b} - exec stmt in dict + exec(stmt, dict) vereq(dict['a'], res) t = type(a) m = getattr(t, meth) @@ -73,7 +73,7 @@ def testsetop(a, b, res, stmt="a+=b", meth="__iadd__"): def testset2op(a, b, c, res, stmt="a[b]=c", meth="__setitem__"): if verbose: print "checking", stmt dict = {'a': deepcopy(a), 'b': b, 'c': c} - exec stmt in dict + exec(stmt, dict) vereq(dict['a'], res) t = type(a) m = getattr(t, meth) @@ -91,7 +91,7 @@ def testset2op(a, b, c, res, stmt="a[b]=c", meth="__setitem__"): def testset3op(a, b, c, d, res, stmt="a[b:c]=d", meth="__setslice__"): if verbose: print "checking", stmt dict = {'a': deepcopy(a), 'b': b, 'c': c, 'd': d} - exec stmt in dict + exec(stmt, dict) vereq(dict['a'], res) t = type(a) while meth not in t.__dict__: @@ -3943,7 +3943,7 @@ def notimplemented(): def check(expr, x, y): try: - exec expr in {'x': x, 'y': y, 'operator': operator} + exec(expr, {'x': x, 'y': y, 'operator': operator}) except TypeError: pass else: diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py index 28d7d13..aca6660 100644 --- a/Lib/test/test_descrtut.py +++ b/Lib/test/test_descrtut.py @@ -67,7 +67,7 @@ statement or the built-in function eval(): >>> print sorted(a.keys()) [1, 2] - >>> exec "x = 3; print x" in a + >>> exec("x = 3; print x", a) 3 >>> print sorted(a.keys(), key=lambda x: (str(type(x)), x)) [1, 2, '__builtins__', 'x'] diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index c31092c..f9a6a07 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -135,7 +135,7 @@ class DisTests(unittest.TestCase): def func(count): namespace = {} func = "def foo():\n " + "".join(["\n "] * count + ["spam\n"]) - exec func in namespace + exec(func, namespace) return namespace['foo'] # Test all small ranges diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 1390e15..56c2449 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -2366,8 +2366,8 @@ def old_test4(): """ ... '''>>> assert 1 < 2 ... ''' ... \""" - >>> exec test_data in m1.__dict__ - >>> exec test_data in m2.__dict__ + >>> exec(test_data, m1.__dict__) + >>> exec(test_data, m2.__dict__) >>> m1.__dict__.update({"f2": m2._f, "g2": m2.g, "h2": m2.H}) Tests that objects outside m1 are excluded: diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 0eb6b46..b5c5676 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -87,7 +87,7 @@ class ExceptionTests(unittest.TestCase): self.raise_catch(RuntimeError, "RuntimeError") self.raise_catch(SyntaxError, "SyntaxError") - try: exec '/\n' + try: exec('/\n') except SyntaxError: pass self.raise_catch(IndentationError, "IndentationError") diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py index ab33528..930c851 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -278,7 +278,7 @@ def test_func_name(): cantset(f, "__name__", 1) # test that you can access func.__name__ in restricted mode s = """def f(): pass\nf.__name__""" - exec s in {'__builtins__':{}} + exec(s, {'__builtins__':{}}) def test_func_code(): diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index ec470c4..675b988 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -153,7 +153,7 @@ def test_function(): # Tricky: f -> d -> f, code should call d.clear() after the exec to # break the cycle. d = {} - exec("def f(): pass\n") in d + exec("def f(): pass\n", d) gc.collect() del d expect(gc.collect(), 2, "function") diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py index 9856a6a..f565d23 100644 --- a/Lib/test/test_getopt.py +++ b/Lib/test/test_getopt.py @@ -10,7 +10,7 @@ def expectException(teststr, expected, failure=AssertionError): """Executes a statement passed in teststr, and raises an exception (failure) if the expected exception is *not* raised.""" try: - exec teststr + exec(teststr) except expected: pass else: diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 93dc9ec..6e9b204 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -449,42 +449,6 @@ def f(): global a, b global one, two, three, four, five, six, seven, eight, nine, ten -print 'exec_stmt' # 'exec' expr ['in' expr [',' expr]] -def f(): - z = None - del z - exec 'z=1+1\n' - if z != 2: raise TestFailed, 'exec \'z=1+1\'\\n' - del z - exec 'z=1+1' - if z != 2: raise TestFailed, 'exec \'z=1+1\'' - z = None - del z - import types - if hasattr(types, "UnicodeType"): - exec r"""if 1: - exec u'z=1+1\n' - if z != 2: raise TestFailed, 'exec u\'z=1+1\'\\n' - del z - exec u'z=1+1' - if z != 2: raise TestFailed, 'exec u\'z=1+1\'' -""" -f() -g = {} -exec 'z = 1' in g -if '__builtins__' in g: del g['__builtins__'] -if g != {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g' -g = {} -l = {} - -import warnings -warnings.filterwarnings("ignore", "global statement", module="<string>") -exec 'global a; a = 1; b = 2' in g, l -if '__builtins__' in g: del g['__builtins__'] -if '__builtins__' in l: del l['__builtins__'] -if (g, l) != ({'a':1}, {'b':2}): raise TestFailed, 'exec ... in g (%s), l (%s)' %(g,l) - - print "assert_stmt" # assert_stmt: 'assert' test [',' test] assert 1 assert 1, 1 diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index effba3c..b64c23b 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -107,7 +107,7 @@ def test_module_with_large_stack(module): sys.path.append('') # this used to crash - exec 'import ' + module + exec('import ' + module) # cleanup del sys.path[-1] diff --git a/Lib/test/test_importhooks.py b/Lib/test/test_importhooks.py index d31bcb2..5077d98 100644 --- a/Lib/test/test_importhooks.py +++ b/Lib/test/test_importhooks.py @@ -81,7 +81,7 @@ class TestImporter: mod.__loader__ = self if ispkg: mod.__path__ = self._get__path__() - exec code in mod.__dict__ + exec(code, mod.__dict__) return mod diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 1030f97..e5946e9 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -199,7 +199,7 @@ class TestRetrievingSourceCode(GetSourceBase): m = sys.modules[name] = module(name) m.__file__ = "<string>" # hopefully not a real filename... m.__loader__ = "dummy" # pretend the filename is understood by a loader - exec "def x(): pass" in m.__dict__ + exec("def x(): pass", m.__dict__) self.assertEqual(inspect.getsourcefile(m.x.func_code), '<string>') del sys.modules[name] inspect.getmodule(compile('a=10','','single')) diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py index 397ebeb..95f4b38 100644 --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -49,7 +49,7 @@ class Test_MultibyteCodec(unittest.TestCase): try: for enc in ALL_CJKENCODINGS: print >> open(TESTFN, 'w'), '# coding:', enc - exec open(TESTFN) + execfile(TESTFN) finally: os.unlink(TESTFN) diff --git a/Lib/test/test_operations.py b/Lib/test/test_operations.py index 67e77aa..8baef4c 100644 --- a/Lib/test/test_operations.py +++ b/Lib/test/test_operations.py @@ -30,7 +30,7 @@ for stmt in ['d[x2] = 2', 'd.pop(x2)', 'd.update({x2: 2})']: try: - exec stmt + exec(stmt) except RuntimeError: print "%s: caught the RuntimeError outside" % (stmt,) else: diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 8aa1657..96384cd 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -429,7 +429,7 @@ class CompileTestCase(unittest.TestCase): st = parser.suite('x = 2; y = x + 3') code = parser.compilest(st) globs = {} - exec code in globs + exec(code, globs) self.assertEquals(globs['y'], 5) def test_compile_error(self): diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index 98b7ef3..e4e592a 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -205,15 +205,6 @@ def unoptimized_clash2(): return f """) -# XXX could allow this for exec with const argument, but what's the point -check_syntax("""\ -def error(y): - exec "a = 1" - def f(x): - return x + y - return f -""") - check_syntax("""\ def f(x): def g(): @@ -230,7 +221,7 @@ def f(): # and verify a few cases that should work -exec """ +exec(""" def noproblem1(): from string import * f = lambda x:x @@ -245,7 +236,7 @@ def noproblem3(): def f(x): global y y = x -""" +""") print "12. lambdas" @@ -526,7 +517,7 @@ else: print "eval() should have failed, because code contained free vars" try: - exec g.func_code + exec(g.func_code) except TypeError: pass else: diff --git a/Lib/test/test_transformer.py b/Lib/test/test_transformer.py index 909cda5..6f1c4f9 100644 --- a/Lib/test/test_transformer.py +++ b/Lib/test/test_transformer.py @@ -24,7 +24,7 @@ class Tests(unittest.TestCase): # is correct c = compile(s, '<string>', 'single') vals = {} - exec c in vals + exec(c, vals) assert vals['a'] == 1 assert vals['b'] == 2 diff --git a/Lib/test/time_hashlib.py b/Lib/test/time_hashlib.py index 1bf707d..de25cfd 100644 --- a/Lib/test/time_hashlib.py +++ b/Lib/test/time_hashlib.py @@ -44,22 +44,22 @@ hName = sys.argv[1] # setup our creatorFunc to test the requested hash # if hName in ('_md5', '_sha'): - exec 'import '+hName - exec 'creatorFunc = '+hName+'.new' + exec('import '+hName) + exec('creatorFunc = '+hName+'.new') print "testing speed of old", hName, "legacy interface" elif hName == '_hashlib' and len(sys.argv) > 3: import _hashlib - exec 'creatorFunc = _hashlib.%s' % sys.argv[2] + exec('creatorFunc = _hashlib.%s' % sys.argv[2]) print "testing speed of _hashlib.%s" % sys.argv[2], getattr(_hashlib, sys.argv[2]) elif hName == '_hashlib' and len(sys.argv) == 3: import _hashlib - exec 'creatorFunc = lambda x=_hashlib.new : x(%r)' % sys.argv[2] + exec('creatorFunc = lambda x=_hashlib.new : x(%r)' % sys.argv[2]) print "testing speed of _hashlib.new(%r)" % sys.argv[2] elif hasattr(hashlib, hName) and callable(getattr(hashlib, hName)): creatorFunc = getattr(hashlib, hName) print "testing speed of hashlib."+hName, getattr(hashlib, hName) else: - exec "creatorFunc = lambda x=hashlib.new : x(%r)" % hName + exec("creatorFunc = lambda x=hashlib.new : x(%r)" % hName) print "testing speed of hashlib.new(%r)" % hName try: |