root.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package testutil
  2. import (
  3. "os"
  4. "os/exec"
  5. "path/filepath"
  6. "runtime"
  7. "strings"
  8. "testing"
  9. )
  10. // HostRoot returns the host/ module directory (the directory containing go.mod).
  11. func HostRoot(t testing.TB) string {
  12. t.Helper()
  13. _, file, _, ok := runtime.Caller(0)
  14. if !ok {
  15. t.Fatal("runtime.Caller failed")
  16. }
  17. return filepath.Clean(filepath.Join(filepath.Dir(file), "..", ".."))
  18. }
  19. func ProfilePath(t testing.TB) string {
  20. t.Helper()
  21. return filepath.Join(HostRoot(t), "profiles", "prod2u-door-temp", "profile.json")
  22. }
  23. // Python returns a real CPython, never the OSS CAD Suite wrapper.
  24. func Python(t testing.TB) string {
  25. t.Helper()
  26. candidates := []string{
  27. "/opt/python-3.12/bin/python3.12",
  28. "/opt/python-3.11/bin/python3.11",
  29. "/usr/bin/python3.13",
  30. "/usr/bin/python3.12",
  31. "/usr/bin/python3.11",
  32. "python3.13",
  33. "python3.12",
  34. "python3.11",
  35. }
  36. for _, c := range candidates {
  37. if strings.HasPrefix(c, "/") {
  38. if st, err := os.Stat(c); err == nil && !st.IsDir() {
  39. return c
  40. }
  41. continue
  42. }
  43. path, err := exec.LookPath(c)
  44. if err != nil {
  45. continue
  46. }
  47. if strings.Contains(path, "/data/prod2u/") {
  48. continue
  49. }
  50. return path
  51. }
  52. t.Skip("no usable CPython (refusing OSS CAD python3 wrapper)")
  53. return ""
  54. }