Parent directory

test_check_path.zunit

1850 bytes
 1#!/usr/bin/env zunit
 2
 3
 4@setup {
 5    export DISABLE_AUTOSWITCH_VENV="1"
 6    load "../autoswitch_virtualenv.plugin.zsh"
 7    TARGET="$(mktemp -d)"
 8}
 9
10@teardown {
11    rm -rf "$TARGET"
12}
13
14@test '_check_path - finds .venv file in base directory' {
15    touch "$TARGET/.venv"
16
17    run _check_path "$TARGET"
18
19    assert $state equals 0
20    assert "$output" same_as "$TARGET/.venv"
21}
22
23@test '_check_path - returns nothing if not found' {
24   run _check_path "$TARGET"
25
26   assert $state equals 0
27   assert "$output" is_empty
28}
29
30@test '_check_path - finds in parent directories' {
31    touch "$TARGET/Pipfile"
32    mkdir "$TARGET/foo"
33
34    run _check_path "$TARGET/foo"
35
36    assert $state equals 0
37    assert "$output" same_as "$TARGET/Pipfile"
38}
39
40@test '_check_path - finds in parent directories' {
41    touch "$TARGET/poetry.lock"
42    mkdir "$TARGET/foo"
43
44    run _check_path "$TARGET/foo"
45
46    assert $state equals 0
47    assert "$output" same_as "$TARGET/poetry.lock"
48}
49
50@test '_check_path - returns nothing with root path' {
51    run _check_path '/' ".venv"
52
53    assert $state equals 0
54    assert "$output" is_empty
55}
56
57@test '_check_path - finds .venv directory with bin/activate' {
58    mkdir -p "$TARGET/.venv/bin"
59    touch "$TARGET/.venv/bin/activate"
60
61    run _check_path "$TARGET"
62
63    assert $state equals 0
64    assert "$output" same_as "$TARGET/.venv"
65}
66
67@test '_check_path - ignores .venv directory without bin/activate' {
68    mkdir -p "$TARGET/.venv"
69
70    run _check_path "$TARGET"
71
72    assert $state equals 0
73    assert "$output" is_empty
74}
75
76@test '_check_path - finds local .venv directory instead of parent marker' {
77    touch "$TARGET/uv.lock"
78    mkdir -p "$TARGET/subdir/.venv/bin"
79    touch "$TARGET/subdir/.venv/bin/activate"
80
81    run _check_path "$TARGET/subdir"
82
83    assert $state equals 0
84    assert "$output" same_as "$TARGET/subdir/.venv"
85}