diff options
author | Damien George <damien.p.george@gmail.com> | 2015-04-04 22:05:30 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-04-04 22:05:30 +0100 |
commit | 9dd36404646f857c4f250537bac0d9a8ad041d25 (patch) | |
tree | c6509bcd3c7d5c2e67332110c582df2b5a5c669f /tests/basics/builtin_compile.py | |
parent | 7e758b1cf878312cab5d9d2825b36e7235ea10a3 (diff) |
tests: Add missing tests for builtins, and many other things.
Diffstat (limited to 'tests/basics/builtin_compile.py')
-rw-r--r-- | tests/basics/builtin_compile.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/basics/builtin_compile.py b/tests/basics/builtin_compile.py index ef3ff014d..32c6667d8 100644 --- a/tests/basics/builtin_compile.py +++ b/tests/basics/builtin_compile.py @@ -7,10 +7,9 @@ def have_compile(): except NameError: return False -# global variable for compiled code to access -x = 1 - def test(): + global x + c = compile("print(x)", "file", "exec") try: @@ -18,11 +17,31 @@ def test(): except NameError: print("NameError") + # global variable for compiled code to access + x = 1 + exec(c) exec(c, {"x":2}) exec(c, {}, {"x":3}) + # single/eval mode + exec(compile('print(1 + 1)', 'file', 'single')) + print(eval(compile('1 + 1', 'file', 'eval'))) + + # bad mode + try: + compile('1', 'file', '') + except ValueError: + print("ValueError") + + # exception within compiled code + try: + exec(compile('noexist', 'file', 'exec')) + except NameError: + print("NameError") + print(x) # check 'x' still exists as a global + if have_compile(): test() else: |