Skip to content

Commit 54ea52b

Browse files
Add tests.
1 parent 6214373 commit 54ea52b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Lib/test/test_interpreters/test_api.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,41 @@ def test_call_invalid(self):
14141414
with self.assertRaises(interpreters.NotShareableError):
14151415
interp.call(func, op, 'eggs!')
14161416

1417+
def test_callable_requires_frame(self):
1418+
# There are various functions tha require a current frame.
1419+
interp = interpreters.create()
1420+
for call, expected in [
1421+
((eval, '[1, 2, 3]'),
1422+
[1, 2, 3]),
1423+
((eval, 'sum([1, 2, 3])'),
1424+
6),
1425+
((exec, '...'),
1426+
None),
1427+
]:
1428+
with self.subTest(str(call)):
1429+
res = interp.call(*call)
1430+
self.assertEqual(res, expected)
1431+
1432+
notshareable = [
1433+
globals,
1434+
locals,
1435+
vars,
1436+
]
1437+
for func, expectedtype in {
1438+
globals: dict,
1439+
locals: dict,
1440+
vars: dict,
1441+
dir: list,
1442+
}.items():
1443+
with self.subTest(str(func)):
1444+
if func in notshareable:
1445+
with self.assertRaises(interpreters.NotShareableError):
1446+
interp.call(func)
1447+
else:
1448+
res = interp.call(func)
1449+
self.assertIsInstance(res, expectedtype)
1450+
self.assertIn('__builtins__', res)
1451+
14171452
def test_call_in_thread(self):
14181453
interp = interpreters.create()
14191454

0 commit comments

Comments
 (0)