Skip to content

Commit 1dc888e

Browse files
committed
Add tests for exec/eval functions in py_event_loop_pool
1 parent 8d31bce commit 1dc888e

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

test/py_event_loop_pool_SUITE.erl

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
test_concurrent_tasks/1,
2828

2929
%% Ordering test
30-
test_tasks_execute_in_order/1
30+
test_tasks_execute_in_order/1,
31+
32+
%% Exec/Eval tests
33+
test_exec_basic/1,
34+
test_eval_basic/1,
35+
test_exec_eval_namespace/1,
36+
test_exec_define_function/1
3137
]).
3238

3339
all() ->
@@ -40,7 +46,11 @@ all() ->
4046
test_run_blocking,
4147
test_spawn_task,
4248
test_concurrent_tasks,
43-
test_tasks_execute_in_order
49+
test_tasks_execute_in_order,
50+
test_exec_basic,
51+
test_eval_basic,
52+
test_exec_eval_namespace,
53+
test_exec_define_function
4454
].
4555

4656
init_per_suite(Config) ->
@@ -161,3 +171,37 @@ test_tasks_execute_in_order(_Config) ->
161171
%% Results should be in submission order
162172
[{ok, 1.0}, {ok, 2.0}, {ok, 3.0}, {ok, 4.0}, {ok, 5.0}] = Results,
163173
ok.
174+
175+
%% ============================================================================
176+
%% Exec/Eval Tests
177+
%% ============================================================================
178+
179+
test_exec_basic(_Config) ->
180+
%% Basic exec should succeed
181+
ok = py_event_loop_pool:exec(<<"x = 42">>),
182+
ok.
183+
184+
test_eval_basic(_Config) ->
185+
%% Basic eval of Python expression
186+
{ok, 6} = py_event_loop_pool:eval(<<"2 + 4">>),
187+
{ok, 10} = py_event_loop_pool:eval(<<"5 * 2">>),
188+
ok.
189+
190+
test_exec_eval_namespace(_Config) ->
191+
%% Variables defined in exec should be available in eval
192+
ok = py_event_loop_pool:exec(<<"pool_test_var = 100">>),
193+
{ok, 100} = py_event_loop_pool:eval(<<"pool_test_var">>),
194+
{ok, 200} = py_event_loop_pool:eval(<<"pool_test_var * 2">>),
195+
ok.
196+
197+
test_exec_define_function(_Config) ->
198+
%% Define a function via exec and call it via create_task
199+
ok = py_event_loop_pool:exec(<<"
200+
def pool_test_multiply(a, b):
201+
return a * b
202+
">>),
203+
204+
%% Call the function via create_task
205+
Ref = py_event_loop_pool:create_task('__main__', pool_test_multiply, [7, 6]),
206+
{ok, 42} = py_event_loop_pool:await(Ref, 5000),
207+
ok.

0 commit comments

Comments
 (0)