-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcaddysnake_test.go
75 lines (62 loc) · 1.99 KB
/
caddysnake_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package caddysnake
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestFindSitePackagesInVenv(t *testing.T) {
// Set up a temporary directory for the virtual environment simulation
tempDir := t.TempDir()
venvLibPath := filepath.Join(tempDir, "lib", "python3.12", "site-packages")
// Create the directory structure
err := os.MkdirAll(venvLibPath, 0755)
if err != nil {
t.Fatalf("failed to create test directory structure: %v", err)
}
// Test the function
result, err := findSitePackagesInVenv(tempDir)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// Verify the result
expectedPath := venvLibPath
if result != expectedPath {
t.Errorf("expected %s, got %s", expectedPath, result)
}
// Clean up is handled automatically by t.TempDir()
}
func TestFindSitePackagesInVenv_NoPythonDirectory(t *testing.T) {
// Set up a temporary directory for the virtual environment simulation
tempDir := t.TempDir()
// Test the function
_, err := findSitePackagesInVenv(tempDir)
if err == nil {
t.Fatalf("expected an error, but got none")
}
// Verify the error message
expectedError := "unable to find a python3.* directory in the venv"
if err.Error() != expectedError {
t.Errorf("expected error %q, got %q", expectedError, err.Error())
}
}
func TestFindSitePackagesInVenv_NoSitePackages(t *testing.T) {
// Set up a temporary directory for the virtual environment simulation
tempDir := t.TempDir()
libPath := filepath.Join(tempDir, "lib", "python3.12")
// Create the lib/python3.12 directory, but omit site-packages
err := os.MkdirAll(libPath, 0755)
if err != nil {
t.Fatalf("failed to create test directory structure: %v", err)
}
// Test the function
_, err = findSitePackagesInVenv(tempDir)
if err == nil {
t.Fatalf("expected an error, but got none")
}
// Verify the error message
expectedError := "site-packages directory does not exist"
if !strings.HasPrefix(err.Error(), expectedError) {
t.Errorf("expected error %q, got %q", expectedError, err.Error())
}
}