File: test_mkvirtualenv_associate.sh

package info (click to toggle)
virtualenvwrapper 4.8.4-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 796 kB
  • sloc: sh: 3,369; python: 595; makefile: 185
file content (133 lines) | stat: -rwxr-xr-x 3,486 bytes parent folder | download
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- mode: shell-script -*-

test_dir=$(cd $(dirname $0) && pwd)
source "$test_dir/setup.sh"

oneTimeSetUp() {
    rm -rf "$WORKON_HOME"
    mkdir -p "$WORKON_HOME"
    source "$test_dir/../virtualenvwrapper.sh"
}

oneTimeTearDown() {
    rm -rf "$WORKON_HOME"
    rm -f "$test_dir/requirements.txt"
}

setUp () {
    echo
    echo "#!/bin/sh" > "$WORKON_HOME/preactivate"
    echo "#!/bin/sh" > "$WORKON_HOME/postactivate"
    rm -f "$TMPDIR/catch_output"
    cd "$WORKON_HOME"
}

test_associate() {
    n=1
    project="$WORKON_HOME/project$n"
    mkdir "$project"
    env="env$n"
    ptrfile="$WORKON_HOME/$env/.project"
    mkvirtualenv -a "$project" "$env" >/dev/null 2>&1
    assertTrue ".project not found" "[ -f $ptrfile ]"
    assertEquals "$ptrfile contains wrong content" "$project" "$(cat $ptrfile)"
}

test_associate_relative_path() {
    n=2
    project="project$n"
    mkdir "$project"
    env="env$n"
    ptrfile="$WORKON_HOME/$env/.project"
    mkvirtualenv -a "$project" "$env" >/dev/null 2>&1
    assertTrue ".project not found" "[ -f $ptrfile ]"
    assertEquals \
        "$ptrfile contains wrong content" \
        "$WORKON_HOME/$project" \
        "$(cat $ptrfile | sed 's|^/private||')"
}

test_associate_not_a_directory() {
    n=3
    project="project$n"
    touch "$project"
    env="env$n"
    ptrfile="$WORKON_HOME/$env/.project"
    mkvirtualenv -a "$project" "$env" >/dev/null 2>&1
    RC=$?
    assertTrue "mkvirtualenv should have failed" "[ $RC -ne 0 ]"
}

test_associate_does_not_exist() {
    n=4
    project="project$n"
    env="env$n"
    ptrfile="$WORKON_HOME/$env/.project"
    mkvirtualenv -a "$project" "$env" >/dev/null 2>&1
    RC=$?
    assertTrue "mkvirtualenv should have failed" "[ $RC -ne 0 ]"
}

test_preactivate() {
    n=5
    project="project$n"
    mkdir "$project"
    env="env$n"
    ptrfile="$WORKON_HOME/$env/.project"
	cat - >"$WORKON_HOME/preactivate" <<EOF
#!/bin/sh
if [ -f "$ptrfile" ]
then
    echo exists >> "$TMPDIR/catch_output"
else
    echo noexists >> "$TMPDIR/catch_output"
fi
EOF
    chmod +x "$WORKON_HOME/preactivate"
    mkvirtualenv -a "$project" "$env" >/dev/null 2>&1
	assertSame "preactivate did not find file" "exists" "$(cat $TMPDIR/catch_output)"
}

test_postactivate() {
    n=6
    project="project$n"
    mkdir "$project"
    env="env$n"
    ptrfile="$WORKON_HOME/$env/.project"
cat - >"$WORKON_HOME/postactivate" <<EOF
#!/bin/sh
if [ -f "$ptrfile" ]
then
    echo exists >> "$TMPDIR/catch_output"
else
    echo noexists >> "$TMPDIR/catch_output"
fi
EOF
    chmod +x "$WORKON_HOME/postactivate"
    mkvirtualenv -a "$project" "$env" >/dev/null 2>&1
	assertSame "postactivate did not find file" "exists" "$(cat $TMPDIR/catch_output)"
}

test_associate_relative_with_dots() {
    cd "$WORKON_HOME"
    n=7
    project="project$n"
    mkdir $project
    mkdir $project.sibling
    cd $project.sibling
    # Change the reference to a sibling directory
    project="../$project"
    env="env$n"
    ptrfile="$WORKON_HOME/$env/.project"
    mkvirtualenv -a "$project" "$env" >/dev/null 2>&1
    assertTrue ".project not found" "[ -f $ptrfile ]"
    # Sometimes OS X prepends /private on the front of the temporary
    # directory, but the directory is the same as without it, so strip
    # it if we see the value in the project file.
    assertEquals \
        "$ptrfile contains wrong content" \
        "$WORKON_HOME/project$n" \
        "$(cat $ptrfile | sed 's|^/private||')"
}

. "$test_dir/shunit2"