|
|
@@ -3,6 +3,7 @@ package integrationtests_test
|
|
|
import (
|
|
|
"strings"
|
|
|
"testing"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/langgenius/dify-sandbox/internal/core/runner/types"
|
|
|
"github.com/langgenius/dify-sandbox/internal/service"
|
|
|
@@ -76,3 +77,33 @@ print(requests.get("https://www.bilibili.com").content)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+func TestPythonTimezone(t *testing.T) {
|
|
|
+ // Test case for time
|
|
|
+ runMultipleTestings(t, 1, func(t *testing.T) {
|
|
|
+ resp := service.RunPython3Code(`
|
|
|
+from datetime import datetime
|
|
|
+from zoneinfo import ZoneInfo
|
|
|
+
|
|
|
+print(datetime.now(ZoneInfo("Asia/Shanghai")).isoformat())
|
|
|
+ `, "", &types.RunnerOptions{
|
|
|
+ EnableNetwork: true,
|
|
|
+ })
|
|
|
+ if resp.Code != 0 {
|
|
|
+ t.Fatal(resp)
|
|
|
+ }
|
|
|
+
|
|
|
+ if resp.Data.(*service.RunCodeResponse).Stderr != "" {
|
|
|
+ t.Fatalf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr)
|
|
|
+ }
|
|
|
+
|
|
|
+ stdout := resp.Data.(*service.RunCodeResponse).Stdout
|
|
|
+ // trim \n
|
|
|
+ stdout = strings.TrimSpace(stdout)
|
|
|
+ // check if stdout match time format
|
|
|
+ _, err := time.Parse("2006-01-02T15:04:05.000000+08:00", stdout)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("unexpected output: %s, error: %v\n", stdout, err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|