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

Function TestPythonRuntime_JSONOutput

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

Source from the content-addressed store, hash-verified

39}
40
41func TestPythonRuntime_JSONOutput(t *testing.T) {
42 runtime := NewPythonRuntime(nil)
43
44 if !runtime.IsAvailable() {
45 t.Skip("Python not available")
46 }
47
48 ctx := context.Background()
49 code := `
50import json
51result = {"sum": _input['a'] + _input['b'], "product": _input['a'] * _input['b']}
52print(json.dumps(result))
53`
54 input := map[string]any{
55 "a": float64(5),
56 "b": float64(3),
57 }
58
59 result, err := runtime.Execute(ctx, code, input)
60 if err != nil {
61 t.Fatalf("Execute failed: %v", err)
62 }
63
64 if !result.Success {
65 t.Errorf("expected success, got error: %s", result.Error)
66 }
67
68 // 输出应该被解析为 JSON
69 output, ok := result.Output.(map[string]any)
70 if !ok {
71 t.Fatalf("expected map output, got %T", result.Output)
72 }
73
74 if output["sum"] != float64(8) {
75 t.Errorf("expected sum=8, got %v", output["sum"])
76 }
77}
78
79func TestNodeJSRuntime_Execute(t *testing.T) {
80 runtime := NewNodeJSRuntime(nil)

Callers

nothing calls this directly

Calls 3

IsAvailableMethod · 0.95
ExecuteMethod · 0.95
NewPythonRuntimeFunction · 0.85

Tested by

no test coverage detected