File: test_add2virtualenv.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 (154 lines) | stat: -rwxr-xr-x 5,071 bytes parent folder | download | duplicates (2)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -*- 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" >/dev/null 2>&1
}

oneTimeTearDown() {
    rm -rf "$WORKON_HOME"
}

setUp () {
    echo
}

test_add2virtualenv () {
    mkvirtualenv "pathtest" >/dev/null 2>&1
    full_path=$(pwd)
    add2virtualenv "$full_path"
    cdsitepackages
    # Check contents of path file
    path_file="./_virtualenv_path_extensions.pth"
    assertTrue "No $full_path in $(cat $path_file)" "grep -q $full_path $path_file"
    assertTrue "No path insert code in $(cat $path_file)" "grep -q sys.__egginsert $path_file"
    # Check the path we inserted is actually at the top
    expected="$full_path"
    actual=$($WORKON_HOME/pathtest/bin/python -c "import sys; sys.stdout.write(sys.path[1]+'\n')")
    assertSame "$expected" "$actual"
    # Make sure the temporary file created
    # during the edit was removed
    assertFalse "Temporary file ${path_file}.tmp still exists" "[ -f ${path_file}.tmp ]"
    cd - >/dev/null 2>&1
}

test_add2virtualenv_zsh_noclobber () {
    # See issue #137
    if [ ! -z $ZSH_VERSION ]
    then
        set -o noclobber
    elif [[ "$SHELL" =~ "bash" ]]
    then
        shopt -o -s noclobber
    else
        return 0
    fi
    mkvirtualenv "pathtest_noclobber" >/dev/null 2>&1
    full_path=$(pwd)
    add2virtualenv "$full_path"
    RC=$?
    if [ ! -z $ZSH_VERSION ]
    then
        unsetopt noclobber
    elif [[ "/$SHELL" =~ "/bash" ]]
    then
        shopt -o -u noclobber
    fi
    assertEquals "0" "$RC"
    cdsitepackages
    # Check contents of path file
    path_file="./_virtualenv_path_extensions.pth"
    assertTrue "No $full_path in $(cat $path_file)" "grep -q $full_path $path_file"
    assertTrue "No path insert code in $(cat $path_file)" "grep -q sys.__egginsert $path_file"
    # Check the path we inserted is actually at the top
    expected="$full_path"
    actual=$($WORKON_HOME/pathtest_noclobber/bin/python -c "import sys; sys.stdout.write(sys.path[1]+'\n')")
    assertSame "$expected" "$actual"
    # Make sure the temporary file created
    # during the edit was removed
    assertFalse "Temporary file ${path_file}.tmp still exists" "[ -f ${path_file}.tmp ]"
    cd - >/dev/null 2>&1
}

test_add2virtualenv_relative () {
    mkvirtualenv "pathtest_relative" >/dev/null 2>&1
    parent_dir=$(dirname $(pwd))
    base_dir=$(basename $(pwd))
    add2virtualenv "../$base_dir"
    cdsitepackages
    path_file="./_virtualenv_path_extensions.pth"
    assertTrue "No $parent_dir/$base_dir in \"`cat $path_file`\"" "grep -q \"$parent_dir/$base_dir\" $path_file"
    cd - >/dev/null 2>&1
}

test_add2virtualenv_space () {
	# see #132
    mkvirtualenv "pathtest_space" >/dev/null 2>&1
    parent_dir=$(dirname $(pwd))
	cdvirtualenv
	mkdir 'a b'
    add2virtualenv 'a b'
    cdsitepackages
    path_file="./_virtualenv_path_extensions.pth"
    assertTrue "No 'a b' in \"`cat $path_file`\"" "grep -q 'a b' $path_file"
    cd - >/dev/null 2>&1
}

test_add2virtualenv_ampersand () {
	# see #132
    mkvirtualenv "pathtest_ampersand" >/dev/null 2>&1
    parent_dir=$(dirname $(pwd))
	cdvirtualenv
	mkdir 'a & b'
    add2virtualenv 'a & b'
    cdsitepackages
    path_file="./_virtualenv_path_extensions.pth"
    assertTrue "No 'a & b' in \"`cat $path_file`\"" "grep -q 'a & b' $path_file"
    cd - >/dev/null 2>&1
}

test_add2virtualenv_delete () {
    path_file="./_virtualenv_path_extensions.pth"
    mkvirtualenv "pathtest_delete" >/dev/null 2>&1
    cdsitepackages
    # Make sure it was added
    add2virtualenv "/full/path"
    assertTrue "No /full/path in $(cat $path_file)" "grep -q /full/path $path_file"
    # Remove it and verify that change
    add2virtualenv -d "/full/path"
    assertFalse "/full/path in `cat $path_file`" "grep -q /full/path $path_file"
    cd - >/dev/null 2>&1
}

test_add2virtualenv_delete_space () {
    path_file="./_virtualenv_path_extensions.pth"
    mkvirtualenv "pathtest_delete_space" >/dev/null 2>&1
    cdsitepackages
    # Make sure it was added
    add2virtualenv "/full/path with spaces"
    assertTrue "No /full/path with spaces in $(cat $path_file)" "grep -q '/full/path with spaces' $path_file"
    # Remove it and verify that change
    add2virtualenv -d "/full/path with spaces"
    assertFalse "/full/path with spaces in `cat $path_file`" "grep -q '/full/path with spaces' $path_file"
    cd - >/dev/null 2>&1
}

test_add2virtualenv_delete_ampersand () {
    path_file="./_virtualenv_path_extensions.pth"
    mkvirtualenv "pathtest_delete_ampersand" >/dev/null 2>&1
    cdsitepackages
    # Make sure it was added
    add2virtualenv "/full/path & dir"
    assertTrue "No /full/path & dir in $(cat $path_file)" "grep -q '/full/path & dir' $path_file"
    # Remove it and verify that change
    add2virtualenv -d "/full/path & dir"
    assertFalse "/full/path & dir in `cat $path_file`" "grep -q '/full/path & dir' $path_file"
    cd - >/dev/null 2>&1
}


. "$test_dir/shunit2"