Skip to content

Commit 0de3e7a

Browse files
committed
add tests to make sure we override cd properly
Change-Id: Ifb96741a872e257d8f350d8e8b6c0bbe2b6c409c # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch pr/5 # Changes to be committed: # (use "git reset HEAD^1 <file>..." to unstage) # # modified: tests/test_cd.sh # new file: tests/test_cd_alias.sh # modified: tests/test_ls.sh # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: tox.ini #
1 parent 82d1011 commit 0de3e7a

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

tests/test_cd.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ oneTimeSetUp() {
88
mkdir -p "$WORKON_HOME"
99
unset VIRTUAL_ENV
1010
source "$test_dir/../virtualenvwrapper.sh"
11-
mkvirtualenv cd-test
11+
mkvirtualenv cd-test >/dev/null 2>&1
1212
deactivate
1313
}
1414

@@ -25,13 +25,17 @@ tearDown () {
2525
deactivate >/dev/null 2>&1
2626
}
2727

28+
cd () {
29+
fail "Should not be using override cd function"
30+
}
31+
2832
test_cdvirtual() {
2933
start_dir="$(pwd)"
3034
cdvirtualenv
3135
assertSame "$VIRTUAL_ENV" "$(pwd)"
3236
cdvirtualenv bin
3337
assertSame "$VIRTUAL_ENV/bin" "$(pwd)"
34-
cd "$start_dir"
38+
virtualenvwrapper_cd "$start_dir"
3539
}
3640

3741
test_cdsitepackages () {
@@ -40,7 +44,7 @@ test_cdsitepackages () {
4044
pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
4145
sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
4246
assertSame "$sitepackages" "$(pwd)"
43-
cd "$start_dir"
47+
virtualenvwrapper_cd "$start_dir"
4448
}
4549

4650
test_cdsitepackages_with_arg () {
@@ -50,7 +54,7 @@ test_cdsitepackages_with_arg () {
5054
mkdir -p "${sitepackage_subdir}"
5155
cdsitepackages subdir
5256
assertSame "$sitepackage_subdir" "$(pwd)"
53-
cd "$start_dir"
57+
virtualenvwrapper_cd "$start_dir"
5458
}
5559

5660
test_cdvirtualenv_no_workon_home () {
@@ -65,7 +69,7 @@ test_cdvirtualenv_no_workon_home () {
6569
test_cdsitepackages_no_workon_home () {
6670
deactivate 2>&1
6771
old_home="$WORKON_HOME"
68-
cd "$WORKON_HOME"
72+
virtualenvwrapper_cd "$WORKON_HOME"
6973
export WORKON_HOME="$WORKON_HOME/not_there"
7074
assertFalse "Was able to change to site-packages" cdsitepackages
7175
assertSame "$old_home" "$(pwd)"

tests/test_cd_alias.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- mode: shell-script -*-
2+
3+
test_dir=$(cd $(dirname $0) && pwd)
4+
source "$test_dir/setup.sh"
5+
6+
oneTimeSetUp() {
7+
rm -rf "$WORKON_HOME"
8+
mkdir -p "$WORKON_HOME"
9+
unset VIRTUAL_ENV
10+
source "$test_dir/../virtualenvwrapper.sh"
11+
mkvirtualenv cd-test >/dev/null 2>&1
12+
deactivate
13+
alias cd='fail "Should not be using override cd function"'
14+
}
15+
16+
oneTimeTearDown() {
17+
rm -rf "$WORKON_HOME"
18+
}
19+
20+
setUp () {
21+
echo
22+
workon cd-test
23+
}
24+
25+
tearDown () {
26+
deactivate >/dev/null 2>&1
27+
}
28+
29+
test_cd() {
30+
start_dir="$(pwd)"
31+
virtualenvwrapper_cd "$VIRTUAL_ENV"
32+
assertSame "$VIRTUAL_ENV" "$(pwd)"
33+
virtualenvwrapper_cd "$start_dir"
34+
}
35+
36+
. "$test_dir/shunit2"

0 commit comments

Comments
 (0)