-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_cp.sh
More file actions
executable file
·140 lines (112 loc) · 4.88 KB
/
test_cp.sh
File metadata and controls
executable file
·140 lines (112 loc) · 4.88 KB
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
# -*- mode: shell-script -*-
test_dir=$(cd $(dirname $0) && pwd)
source "$test_dir/setup.sh"
setUp () {
rm -rf "$WORKON_HOME"
mkdir -p "$WORKON_HOME"
load_wrappers
rm -f "$TMPDIR/catch_output"
echo
}
tearDown() {
if type deactivate >/dev/null 2>&1
then
deactivate
fi
rm -rf "$WORKON_HOME"
}
test_new_env_activated () {
mkvirtualenv "source" >/dev/null 2>&1
RC=$?
assertEquals "0" "$RC"
(cd tests/testpackage && pip install .) >/dev/null 2>&1
cpvirtualenv "source" "destination" >/dev/null 2>&1
rmvirtualenv "source" >/dev/null 2>&1
testscript="$(which testscript.py)"
assertTrue "Environment test script not found in path" "[ $WORKON_HOME/destination/bin/testscript.py -ef $testscript ]"
testscriptcontent="$(cat $testscript)"
assertTrue "No cpvirtualenvtest in $testscriptcontent" "echo $testscriptcontent | grep cpvirtualenvtest"
assertTrue virtualenvwrapper_verify_active_environment
}
test_virtual_env_variable () {
mkvirtualenv "source" >/dev/null 2>&1
cpvirtualenv "source" "destination" >/dev/null 2>&1
assertSame "Wrong virtualenv name" "destination" $(basename "$VIRTUAL_ENV")
assertTrue "$WORKON_HOME not in $VIRTUAL_ENV" "echo $VIRTUAL_ENV | grep -q $WORKON_HOME"
}
test_virtual_env_variable_space_in_name () {
# Only test with leading and internal spaces. Directory names with trailing spaces are legal,
# and work with virtualenv on OSX, but error out on Linux.
mkvirtualenv " space source" >/dev/null 2>&1
cpvirtualenv " space source" " space destination" >/dev/null 2>&1
assertSame "Wrong virtualenv name" " space destination" "$(basename "$VIRTUAL_ENV")"
assertTrue "$WORKON_HOME not in $VIRTUAL_ENV" "echo $VIRTUAL_ENV | grep -q $WORKON_HOME"
}
fake_venv () {
###
# create a silly file to ensure copy happens
###
typeset envname="$1"
virtualenv $@
touch "$WORKON_HOME/$envname/fake_virtualenv_was_here"
}
fake_venv_clone () {
###
# create a silly file to ensure copy happens
###
typeset src_path="$1"
touch "$src_path/fake_virtualenv_clone_was_here"
virtualenv-clone $@
}
test_virtualenvwrapper_virtualenv_variable () {
eval 'virtualenvwrapper_verify_virtualenv () {
return 0
}'
VIRTUALENVWRAPPER_VIRTUALENV=fake_venv
assertSame "VIRTUALENVWRAPPER_VIRTUALENV is not set correctly" "$VIRTUALENVWRAPPER_VIRTUALENV" "fake_venv"
mkvirtualenv "source" >/dev/null 2>&1
assertTrue "Fake file not made in fake_venv" "[ -f "$VIRTUAL_ENV/fake_virtualenv_was_here" ]"
cpvirtualenv "source" "destination" >/dev/null 2>&1
unset VIRTUALENVWRAPPER_VIRTUALENV
assertTrue "VIRTUALENVWRAPPER_CLONE did not clone fake file" "[ -f $WORKON_HOME/destination/fake_virtualenv_was_here ]"
}
test_virtualenvwrapper_virtualenv_clone_variable () {
eval 'virtualenvwrapper_verify_virtualenv_clone () {
return 0
}'
VIRTUALENVWRAPPER_VIRTUALENV_CLONE=fake_venv_clone
assertSame "VIRTUALENVWRAPPER_VIRTUALENV_CLONE is not set correctly" "$VIRTUALENVWRAPPER_VIRTUALENV_CLONE" "fake_venv_clone"
mkvirtualenv "source" >/dev/null 2>&1
cpvirtualenv "source" "destination" >/dev/null 2>&1
unset VIRTUALENVWRAPPER_VIRTUALENV_CLONE
assertTrue "VIRTUALENVWRAPPER_CLONE did not clone fake file" "[ -f $WORKON_HOME/destination/fake_virtualenv_clone_was_here ]"
}
test_source_does_not_exist () {
assertSame "Please provide a valid virtualenv to copy." "$(cpvirtualenv virtualenvthatdoesntexist foo)"
}
test_hooks () {
mkvirtualenv "source" >/dev/null 2>&1
# Set the interpreter of the hook script to the simple shell
echo "#!/bin/sh" > "$WORKON_HOME/premkvirtualenv"
echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
chmod +x "$WORKON_HOME/premkvirtualenv"
echo "echo GLOBAL postmkvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postmkvirtualenv"
# Set the interpreter of the hook script to the simple shell
echo "#!/bin/sh" > "$WORKON_HOME/precpvirtualenv"
echo "echo GLOBAL precpvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/precpvirtualenv"
chmod +x "$WORKON_HOME/precpvirtualenv"
# Set the interpreter of the hook script to the simple shell
echo "#!/bin/sh" > "$WORKON_HOME/postcpvirtualenv"
echo "echo GLOBAL postcpvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postcpvirtualenv"
cpvirtualenv "source" "destination" >/dev/null 2>&1
output=$(cat "$TMPDIR/catch_output")
workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
expected="GLOBAL precpvirtualenv $workon_home_as_pwd $workon_home_as_pwd/source destination
GLOBAL premkvirtualenv $workon_home_as_pwd destination
GLOBAL postmkvirtualenv
GLOBAL postcpvirtualenv"
assertSame "$expected" "$output"
rm -f "$WORKON_HOME/premkvirtualenv"
rm -f "$WORKON_HOME/postmkvirtualenv"
}
. "$test_dir/shunit2"