| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package testutil
- import (
- "os"
- "os/exec"
- "path/filepath"
- "runtime"
- "strings"
- "testing"
- )
- // HostRoot returns the host/ module directory (the directory containing go.mod).
- func HostRoot(t testing.TB) string {
- t.Helper()
- _, file, _, ok := runtime.Caller(0)
- if !ok {
- t.Fatal("runtime.Caller failed")
- }
- return filepath.Clean(filepath.Join(filepath.Dir(file), "..", ".."))
- }
- func ProfilePath(t testing.TB) string {
- t.Helper()
- return filepath.Join(HostRoot(t), "profiles", "prod2u-door-temp", "profile.json")
- }
- // Python returns a real CPython, never the OSS CAD Suite wrapper.
- func Python(t testing.TB) string {
- t.Helper()
- candidates := []string{
- "/opt/python-3.12/bin/python3.12",
- "/opt/python-3.11/bin/python3.11",
- "/usr/bin/python3.13",
- "/usr/bin/python3.12",
- "/usr/bin/python3.11",
- "python3.13",
- "python3.12",
- "python3.11",
- }
- for _, c := range candidates {
- if strings.HasPrefix(c, "/") {
- if st, err := os.Stat(c); err == nil && !st.IsDir() {
- return c
- }
- continue
- }
- path, err := exec.LookPath(c)
- if err != nil {
- continue
- }
- if strings.Contains(path, "/data/prod2u/") {
- continue
- }
- return path
- }
- t.Skip("no usable CPython (refusing OSS CAD python3 wrapper)")
- return ""
- }
|