python_longchars_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package integrationtests_test
  2. import (
  3. "testing"
  4. "github.com/langgenius/dify-sandbox/internal/core/runner/types"
  5. "github.com/langgenius/dify-sandbox/internal/service"
  6. )
  7. func TestPythonLargeOutput(t *testing.T) {
  8. // Test case for base64
  9. runMultipleTestings(t, 5, func(t *testing.T) {
  10. resp := service.RunPython3Code(`# declare main function here
  11. def main() -> dict:
  12. original_strings_with_empty = ["apple", "", "cherry", "date", "", "fig", "grape", "honeydew", "kiwi", "", "mango", "nectarine", "orange", "papaya", "quince", "raspberry", "strawberry", "tangerine", "ugli fruit", "vanilla bean", "watermelon", "xigua", "yellow passionfruit", "zucchini"] * 5
  13. extended_strings = []
  14. for s in original_strings_with_empty:
  15. if s:
  16. repeat_times = 600
  17. extended_s = (s * repeat_times)[:3000]
  18. extended_strings.append(extended_s)
  19. else:
  20. extended_strings.append(s)
  21. return {
  22. "result": extended_strings,
  23. }
  24. from json import loads, dumps
  25. from base64 import b64decode
  26. # execute main function, and return the result
  27. # inputs is a dict, and it
  28. inputs = b64decode('e30=').decode('utf-8')
  29. output = main(**loads(inputs))
  30. # convert output to json and print
  31. output = dumps(output, indent=4)
  32. result = f'''<<RESULT>>
  33. {output}
  34. <<RESULT>>'''
  35. print(result)
  36. `, "", &types.RunnerOptions{
  37. EnableNetwork: true,
  38. })
  39. if resp.Code != 0 {
  40. t.Fatal(resp)
  41. }
  42. if resp.Data.(*service.RunCodeResponse).Stderr != "" {
  43. t.Fatalf("unexpected error: %s\n", resp.Data.(*service.RunCodeResponse).Stderr)
  44. }
  45. if len(resp.Data.(*service.RunCodeResponse).Stdout) != 304487 {
  46. t.Fatalf("unexpected output, expected 304487 bytes, got %d bytes\n", len(resp.Data.(*service.RunCodeResponse).Stdout))
  47. }
  48. })
  49. }