46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestComfyVenvHome(t *testing.T) {
|
|
root := t.TempDir()
|
|
comfy := filepath.Join(root, "ComfyUI")
|
|
outside := filepath.Join(root, "standalone-env")
|
|
inside := filepath.Join(comfy, "runtime")
|
|
for _, d := range []string{filepath.Join(comfy, ".venv"), outside, inside} {
|
|
if err := os.MkdirAll(d, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
cfg := filepath.Join(comfy, ".venv", "pyvenv.cfg")
|
|
|
|
write := func(home string) {
|
|
if err := os.WriteFile(cfg, []byte("home = "+home+"\nversion_info = 3.13.0\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
write(outside)
|
|
if got := comfyVenvHome(comfy); got != outside {
|
|
t.Fatalf("outside home: got %q, want %q", got, outside)
|
|
}
|
|
|
|
write(inside)
|
|
if got := comfyVenvHome(comfy); got != "" {
|
|
t.Fatalf("inside home: got %q, want empty", got)
|
|
}
|
|
|
|
write(filepath.Join(root, "does-not-exist"))
|
|
if got := comfyVenvHome(comfy); got != "" {
|
|
t.Fatalf("missing home: got %q, want empty", got)
|
|
}
|
|
|
|
if got := comfyVenvHome(filepath.Join(root, "no-venv")); got != "" {
|
|
t.Fatalf("no pyvenv.cfg: got %q, want empty", got)
|
|
}
|
|
}
|