From b2f19b8d349314baba640e1dd99ea833d0bc4b8f Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 26 Oct 2014 15:38:28 +0000 Subject: [PATCH] tests: Get builtin_compile to skin properly on pyboard. --- tests/basics/builtin_compile.py | 40 ++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/tests/basics/builtin_compile.py b/tests/basics/builtin_compile.py index b6f65a2fa3..ef3ff014d4 100644 --- a/tests/basics/builtin_compile.py +++ b/tests/basics/builtin_compile.py @@ -1,21 +1,29 @@ # test compile builtin -try: - compile -except NameError: - print("SKIP") - import sys - sys.exit() - -c = compile("print(x)", "file", "exec") - -try: - exec(c) -except NameError: - print("NameError") +def have_compile(): + try: + compile + return True + except NameError: + return False +# global variable for compiled code to access x = 1 -exec(c) -exec(c, {"x":2}) -exec(c, {}, {"x":3}) +def test(): + c = compile("print(x)", "file", "exec") + + try: + exec(c) + except NameError: + print("NameError") + + exec(c) + + exec(c, {"x":2}) + exec(c, {}, {"x":3}) + +if have_compile(): + test() +else: + print("SKIP")