(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func 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 := ` |
| 18 | result = _input['a'] + _input['b'] |
| 19 | print(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 | |
| 41 | func TestPythonRuntime_JSONOutput(t *testing.T) { |
| 42 | runtime := NewPythonRuntime(nil) |
nothing calls this directly
no test coverage detected