-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_run_hook.sh
More file actions
executable file
·67 lines (58 loc) · 2.09 KB
/
test_run_hook.sh
File metadata and controls
executable file
·67 lines (58 loc) · 2.09 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
# -*- mode: shell-script -*-
test_dir=$(cd $(dirname $0) && pwd)
source "$test_dir/setup.sh"
oneTimeSetUp() {
rm -rf "$WORKON_HOME"
mkdir -p "$WORKON_HOME"
load_wrappers
}
oneTimeTearDown() {
rm -rf "$WORKON_HOME"
}
setUp () {
echo
rm -f "$WORKON_HOME/initialize"
rm -f "$WORKON_HOME/prermvirtualenv"
rm -f "$TMPDIR/catch_output"
}
test_virtualenvwrapper_run_hook() {
echo "echo run >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/initialize"
chmod +x "$WORKON_HOME/initialize"
virtualenvwrapper_run_hook "initialize"
output=$(cat "$TMPDIR/catch_output")
expected="run"
assertSame "$expected" "$output"
}
test_virtualenvwrapper_run_hook_alternate_dir() {
mkdir "$WORKON_HOME/hooks"
echo "echo WORKON_HOME >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/initialize"
echo "echo WORKON_HOME/hooks >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/hooks/initialize"
chmod +x "$WORKON_HOME/initialize"
chmod +x "$WORKON_HOME/hooks/initialize"
VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME/hooks"
virtualenvwrapper_run_hook "initialize"
output=$(cat "$TMPDIR/catch_output")
expected="WORKON_HOME/hooks"
assertSame "$expected" "$output"
VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME"
}
test_virtualenvwrapper_source_hook_permissions() {
echo "echo run >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/initialize"
chmod -x "$WORKON_HOME/initialize"
virtualenvwrapper_run_hook "initialize"
output=$(cat "$TMPDIR/catch_output")
expected="run"
assertSame "$expected" "$output"
}
test_virtualenvwrapper_run_hook_permissions() {
echo "#!/bin/sh" > "$WORKON_HOME/prermvirtualenv"
echo "echo run $@ >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/prermvirtualenv"
chmod 0444 "$WORKON_HOME/prermvirtualenv"
touch "$TMPDIR/catch_output"
error=$(virtualenvwrapper_run_hook "pre_rmvirtualenv" "foo" 2>&1 | grep "could not run" | cut -f2- -d'[' | cut -f1 -d:)
output=$(cat "$TMPDIR/catch_output")
expected=""
assertSame "$expected" "$output"
assertSame "Errno 13] Permission denied" "$error"
}
. "$test_dir/shunit2"