Skip to content

Commit 6cfe737

Browse files
tomlogicdpgeorge
authored andcommitted
tests/basics/builtin_exec: Test various globals/locals args to exec().
1 parent bb3bdda commit 6cfe737

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/basics/builtin_exec.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,29 @@
44
d = {}
55
exec("def bar(): return 84", d)
66
print(d["bar"]())
7+
8+
# passing None/dict as args to globals/locals
9+
foo = 11
10+
exec('print(foo)')
11+
exec('print(foo)', None)
12+
exec('print(foo)', {'foo':3}, None)
13+
exec('print(foo)', None, {'foo':3})
14+
exec('print(foo)', None, {'bar':3})
15+
exec('print(foo)', {'bar':3}, locals())
16+
17+
try:
18+
exec('print(foo)', {'bar':3}, None)
19+
except NameError:
20+
print('NameError')
21+
22+
# invalid arg passed to globals
23+
try:
24+
exec('print(1)', 'foo')
25+
except TypeError:
26+
print('TypeError')
27+
28+
# invalid arg passed to locals
29+
try:
30+
exec('print(1)', None, 123)
31+
except TypeError:
32+
print('TypeError')

0 commit comments

Comments
 (0)