python_sdk_live_test.go 1.4 KB

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