(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func 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 := ` |
| 50 | import json |
| 51 | result = {"sum": _input['a'] + _input['b'], "product": _input['a'] * _input['b']} |
| 52 | print(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 | |
| 79 | func TestNodeJSRuntime_Execute(t *testing.T) { |
| 80 | runtime := NewNodeJSRuntime(nil) |
nothing calls this directly
no test coverage detected