MCPcopy Create free account
hub / github.com/astercloud/aster / TestPythonRuntime_Execute

Function TestPythonRuntime_Execute

pkg/tools/bridge/runtime_test.go:9–39  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestPythonRuntime_Execute(t *testing.T) {
10 runtime := NewPythonRuntime(nil)
11
12 if !runtime.IsAvailable() {
13 t.Skip("Python not available")
14 }
15
16 ctx := context.Background()
17 code := `
18result = _input['a'] + _input['b']
19print(result)
20`
21 input := map[string]any{
22 "a": 10,
23 "b": 20,
24 }
25
26 result, err := runtime.Execute(ctx, code, input)
27 if err != nil {
28 t.Fatalf("Execute failed: %v", err)
29 }
30
31 if !result.Success {
32 t.Errorf("expected success, got error: %s", result.Error)
33 }
34
35 // 输出应该是 30
36 if result.Output != "30" {
37 t.Errorf("expected output '30', got %v", result.Output)
38 }
39}
40
41func TestPythonRuntime_JSONOutput(t *testing.T) {
42 runtime := NewPythonRuntime(nil)

Callers

nothing calls this directly

Calls 3

IsAvailableMethod · 0.95
ExecuteMethod · 0.95
NewPythonRuntimeFunction · 0.85

Tested by

no test coverage detected