python_sdk_live_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package tests
  2. import (
  3. "os"
  4. "os/exec"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "hth/internal/testutil"
  9. )
  10. func pythonWithPytest(t *testing.T) string {
  11. t.Helper()
  12. cands := []string{
  13. "/usr/bin/python3",
  14. filepath.Join(testutil.HostRoot(t), ".venv-sdk", "bin", "python"),
  15. "/opt/python-3.12/bin/python3.12",
  16. "python3.12",
  17. "python3.11",
  18. "/usr/local/bin/python3.11",
  19. "python3.13",
  20. "python3",
  21. }
  22. for _, py := range cands {
  23. if filepath.IsAbs(py) {
  24. if _, err := os.Stat(py); err != nil {
  25. continue
  26. }
  27. } else if _, err := exec.LookPath(py); err != nil {
  28. continue
  29. }
  30. if err := exec.Command(py, "-c", "import pytest, grpc").Run(); err == nil {
  31. return py
  32. }
  33. }
  34. t.Skip("pytest+grpcio not available")
  35. return ""
  36. }
  37. func TestPythonSDKLiveUDS(t *testing.T) {
  38. py := pythonWithPytest(t)
  39. _, obs, ctl := startMockApp(t)
  40. cmd := exec.Command(py, "-m", "pytest", "-q",
  41. filepath.Join(testutil.HostRoot(t), "sdk", "python", "tests", "test_live_uds.py"))
  42. cmd.Dir = filepath.Join(testutil.HostRoot(t), "sdk", "python")
  43. cmd.Env = append(os.Environ(),
  44. "HTH_OBSERVE_SOCK="+obs,
  45. "HTH_CONTROL_SOCK="+ctl,
  46. "PYTHONPATH="+filepath.Join(testutil.HostRoot(t), "sdk", "python"),
  47. )
  48. cmd.Stdout = os.Stdout
  49. cmd.Stderr = os.Stderr
  50. done := make(chan error, 1)
  51. go func() { done <- cmd.Run() }()
  52. select {
  53. case err := <-done:
  54. if err != nil {
  55. t.Fatal(err)
  56. }
  57. case <-time.After(30 * time.Second):
  58. _ = cmd.Process.Kill()
  59. t.Fatal("python live test timeout")
  60. }
  61. }