File: test_cpvirtualenv.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 (231 lines) | stat: -rwxr-xr-x 8,523 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# -*- mode: shell-script -*-

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

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

tearDown () {
    if type deactivate >/dev/null 2>&1
    then 
        deactivate
    fi
    rm -rf "$WORKON_HOME"
}

test_no_arguments () {
    assertSame "Please provide a valid virtualenv to copy." "$(cpvirtualenv)"
}

test_venv_already_exists_in_workon () {
    mkvirtualenv "cpvenv_test" >/dev/null 2>&1
    assertSame  "cpvenv_test virtualenv already exists." "$(cpvirtualenv 'cpvenv_test')"
}

test_bad_path () {
    assertSame "Please provide a valid virtualenv to copy." "$(cpvirtualenv '~/cpvenv_test')"
}

test_copy_venv () {
    # verify venvs don't exist
    assertTrue "Virtualenv to copy already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"
    assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]"
    mkvirtualenv "cpvenv_test" >/dev/null 2>&1
    touch "$WORKON_HOME/cpvenv_test/mytestpackage"

    assertTrue "Virtualenv to copy didn't get created" "[ -d $WORKON_HOME/cpvenv_test ]"
    assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]"

    cpvirtualenv "cpvenv_test" "copied_venv" >/dev/null 2>&1

    # verify copied venv exist
    assertTrue "Copied virtualenv doesn't exist" "[ -d $WORKON_HOME/copied_venv ]"
    # verify test package exists
    assertTrue "Test package is missing" "[ -f $WORKON_HOME/copied_venv/mytestpackage ]"
}

test_copy_venv_activate () {
    # verify venvs don't exist
    assertTrue "Virtualenv to copy already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"
    assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]"
    mkvirtualenv "cpvenv_test" >/dev/null 2>&1

    assertTrue "Virtualenv to copy didn't get created" "[ -d $WORKON_HOME/cpvenv_test ]"
    assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]"

    cpvirtualenv "cpvenv_test" "copied_venv" >/dev/null 2>&1

    # verify copied venv exist
    assertTrue "Copied virtualenv doesn't exist" "[ -d $WORKON_HOME/copied_venv ]"

    assertSame "copied_venv" "$(basename $VIRTUAL_ENV)"
    assertTrue "Virtualenv not active" virtualenvwrapper_verify_active_environment
}

test_copy_venv_is_listed () {
    # verify venvs don't exist
    assertTrue "Virtualenv to copy already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"
    assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]"
    mkvirtualenv "cpvenv_test" >/dev/null 2>&1

    typeset listed=$(lsvirtualenv)
    [[ "$listed" != *copied_venv* ]]
    RC=$?
    assertTrue "Copied virtualenv found in virtualenv list" $RC 

    cpvirtualenv "cpvenv_test" "copied_venv" >/dev/null 2>&1

    listed=$(lsvirtualenv -b)
    [[ "$listed" == *copied_venv* ]]
    RC=$?
    assertTrue "Copied virtualenv not found in virtualenv list" $RC 
}

test_clone_venv () {
    typeset tmplocation=$(dirname $WORKON_HOME)

    # verify venvs don't exist
    assertTrue "Virtualenv to clone already exists" "[ ! -d $tmplocation/cpvenv_test ]"
    assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]"

    $VIRTUALENVWRAPPER_VIRTUALENV "$tmplocation/cpvenv_test" >/dev/null 2>&1
    touch "$tmplocation/cpvenv_test/mytestpackage"

    assertTrue "Virtualenv to clone didn't get created" "[ -d $tmplocation/cpvenv_test ]"
    assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]"

    cpvirtualenv "$tmplocation/cpvenv_test" "cloned_venv" >/dev/null 2>&1

    # verify cloned venv exist
    assertTrue "Cloned virtualenv doesn't exist" "[ -d $WORKON_HOME/cloned_venv ]"
    # verify test package exists
    assertTrue "Test package is missing" "[ -f $WORKON_HOME/cloned_venv/mytestpackage ]"

    rm -rf "$tmplocation/cpvenv_test"
}

test_clone_venv_activate () {
    typeset tmplocation=$(dirname $WORKON_HOME)

    # verify venvs don't exist
    assertTrue "Virtualenv to clone already exists" "[ ! -d $tmplocation/cpvenv_test ]"
    assertTrue "Virtualenv with same name as clone source already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"
    assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]"

    $VIRTUALENVWRAPPER_VIRTUALENV "$tmplocation/cpvenv_test" >/dev/null 2>&1

    assertTrue "Virtualenv to clone didn't get created" "[ -d $tmplocation/cpvenv_test ]"
    assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]"

    #cpvirtualenv "$tmplocation/cpvenv_test" "cloned_venv" >/dev/null 2>&1
    cpvirtualenv "$tmplocation/cpvenv_test" "cloned_venv" >/dev/null 2/>&1

    # verify cloned venv exist
    assertTrue "Cloned virtualenv doesn't exist" "[ -d $WORKON_HOME/cloned_venv ]"

    assertSame "cloned_venv" "$(basename $VIRTUAL_ENV)"
    assertTrue "Virtualenv not active" virtualenvwrapper_verify_active_environment

    rm -rf "$tmplocation/cpvenv_test"
}

test_clone_venv_is_listed (){
    typeset tmplocation=$(dirname $WORKON_HOME)

    # verify venvs don't exist
    assertTrue "Virtualenv to clone already exists" "[ ! -d $tmplocation/cpvenv_test ]"
    assertTrue "Virtualenv with same name as clone source already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"
    assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]"

    typeset listed=$(lsvirtualenv)
    [[ "$listed" != *cloned_venv* ]]
    RC=$?
    assertTrue "Cloned virtualenv found in virtualenv list" $RC 

    $VIRTUALENVWRAPPER_VIRTUALENV "$tmplocation/cpvenv_test" >/dev/null 2>&1
    cpvirtualenv "$tmplocation/cpvenv_test" "cloned_venv" >/dev/null 2>&1

    listed=$(lsvirtualenv -b)
    [[ "$listed" == *cloned_venv* ]]
    RC=$?
    assertTrue "Cloned virtualenv not found in virtualenv list" $RC 

    rm -rf "$tmplocation/cpvenv_test"

}

test_clone_venv_using_same_name () {
    typeset tmplocation=$(dirname $WORKON_HOME)

    # verify venvs don't exist
    assertTrue "Virtualenv to clone already exists" "[ ! -d $tmplocation/cpvenv_test ]"
    assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"

    $VIRTUALENVWRAPPER_VIRTUALENV "$tmplocation/cpvenv_test" >/dev/null 2>&1
    touch "$tmplocation/cpvenv_test/mytestpackage"

    assertTrue "Virtualenv to clone didn't get created" "[ -d $tmplocation/cpvenv_test ]"
    assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"

    typeset listed=$(lsvirtualenv)
    [[ "$listed" != *cpvenv_test* ]]
    RC=$?
    assertTrue "Cloned virtualenv found in virtualenv list" $RC 

    cpvirtualenv "$tmplocation/cpvenv_test" >/dev/null 2>&1 >/dev/null 2>&1

    # verify cloned venv exist
    assertTrue "Cloned virtualenv doesn't exist" "[ -d $WORKON_HOME/cpvenv_test ]"
    assertTrue "Test package is missing" "[ -f $WORKON_HOME/cpvenv_test/mytestpackage ]"

    listed=$(lsvirtualenv -b)
    [[ "$listed" == *cpvenv_test* ]]
    RC=$?
    assertTrue "Cloned virtualenv not found in virtualenv list" $RC 

    assertSame "cpvenv_test" "$(basename $VIRTUAL_ENV)"
    assertTrue "Virtualenv not active" virtualenvwrapper_verify_active_environment

    rm -rf "$tmplocation/cpvenv_test"
}

test_clone_venv_using_vars () {

    # verify venvs don't exist
    assertTrue "Virtualenv to clone already exists" "[ ! -d $TMPDIR/cpvenv_test ]"
    assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"

    $VIRTUALENVWRAPPER_VIRTUALENV "$TMPDIR/cpvenv_test" >/dev/null 2>&1
    touch "$TMPDIR/cpvenv_test/mytestpackage"

    assertTrue "Virtualenv to clone didn't get created" "[ -d $TMPDIR/cpvenv_test ]"
    assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"

    typeset listed=$(lsvirtualenv)
    [[ "$listed" != *cpvenv_test* ]]
    RC=$?
    assertTrue "Cloned virtualenv found in virtualenv list" $RC 

    cpvirtualenv '$TMPDIR/cpvenv_test' >/dev/null 2>&1 >/dev/null 2>&1

    # verify cloned venv exist
    assertTrue "Cloned virtualenv doesn't exist" "[ -d $WORKON_HOME/cpvenv_test ]"
    assertTrue "Test package is missing" "[ -f $WORKON_HOME/cpvenv_test/mytestpackage ]"

    listed=$(lsvirtualenv -b)
    [[ "$listed" == *cpvenv_test* ]]
    RC=$?
    assertTrue "Cloned virtualenv not found in virtualenv list" $RC 

    assertSame "cpvenv_test" "$(basename $VIRTUAL_ENV)"
    assertTrue "Virtualenv not active" virtualenvwrapper_verify_active_environment

    rm -rf "$TMPDIR/cpvenv_test"
}

source "$test_dir/shunit2"