From b3b09c97ce0b40a282553b0366addc879a115eb4 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 22 Oct 1993 14:24:22 +0000 Subject: [PATCH] added builtin b/w compat module. changed testing of exec. --- Lib/builtin.py | 3 +++ Lib/test/test_b1.py | 10 +--------- Lib/test/test_grammar.py | 21 ++++++++++++++++++++- Lib/test/testall.out | 2 +- 4 files changed, 25 insertions(+), 11 deletions(-) create mode 100755 Lib/builtin.py diff --git a/Lib/builtin.py b/Lib/builtin.py new file mode 100755 index 00000000000..710d8253a28 --- /dev/null +++ b/Lib/builtin.py @@ -0,0 +1,3 @@ +# B/W compat hack so code that says "import builtin" won't break after +# name change from builtin to __builtin__. +from __builtin__ import * diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py index e5611e566c3..c258fd724c8 100644 --- a/Lib/test/test_b1.py +++ b/Lib/test/test_b1.py @@ -25,7 +25,7 @@ def f2(a1, a2): raise TestFailed, 'f2 called with ' + `a1, a2` def f3(a1, a2, a3): if a1 != 1 or a2 != 2 or a3 != 3: - raise TestFailed, 'f2 called with ' + `a1, a2, a3` + raise TestFailed, 'f3 called with ' + `a1, a2, a3` apply(f0, ()) apply(f1, (1,)) apply(f2, (1, 2)) @@ -81,14 +81,6 @@ print 'eval' if eval('1+1') <> 2: raise TestFailed, 'eval(\'1+1\')' if eval(' 1+1\n') <> 2: raise TestFailed, 'eval(\' 1+1\\n\')' -print 'exec' -z = 0 -exec('z=1+1\n') -if z <> 2: raise TestFailed, 'exec(\'z=1+1\'\\n)' -z = 0 -exec('z=1+1') -if z <> 2: raise TestFailed, 'exec(\'z=1+1\')' - print 'execfile' z = 0 f = open(TESTFN, 'w') diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 56fb14fc893..f07f75b2352 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -97,7 +97,7 @@ def v3(a, (b, c), *rest): pass print 'simple_stmt' x = 1; pass; del x -### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt +### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt # Tested below print 'expr_stmt' # (exprlist '=')* exprlist @@ -165,6 +165,25 @@ 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\'' +f() +g = {} +exec 'z = 1' in g +if g <> {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g' +g = {} +l = {} +exec 'global a; a = 1; b = 2' in g, l +if (g, l) <> ({'a':1}, {'b':2}): raise TestFailed, 'exec ... in g, l' + + ### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef # Tested below diff --git a/Lib/test/testall.out b/Lib/test/testall.out index a711ba2e3e7..e1ee9da7260 100644 --- a/Lib/test/testall.out +++ b/Lib/test/testall.out @@ -35,6 +35,7 @@ import_stmt [5] [6] global_stmt +exec_stmt if_stmt while_stmt for_stmt @@ -71,7 +72,6 @@ coerce dir divmod eval -exec execfile float getattr