1# -*- mode: shell-script -*- 2 3test_dir=$(dirname $0) 4source "$test_dir/setup.sh" 5 6oneTimeSetUp() { 7 rm -rf "$WORKON_HOME" 8 mkdir -p "$WORKON_HOME" 9 rm -rf "$PROJECT_HOME" 10 mkdir -p "$PROJECT_HOME" 11 source "$test_dir/../virtualenvwrapper.sh" 12} 13 14oneTimeTearDown() { 15 rm -rf "$WORKON_HOME" 16 rm -rf "$PROJECT_HOME" 17} 18 19setUp () { 20 echo 21} 22 23test_setvirtualenvproject() { 24 n=1 25 project="$WORKON_HOME/project$n" 26 mkdir "$project" 27 env="env$n" 28 ptrfile="$WORKON_HOME/$env/.project" 29 mkvirtualenv "$env" >/dev/null 2>&1 30 setvirtualenvproject "$env" "$project" >/dev/null 2>&1 31 assertTrue ".project not found" "[ -f $ptrfile ]" 32 assertEquals "$ptrfile contains wrong content" "$project" "$(cat $ptrfile)" 33} 34 35test_setvirtualenvproject_relative_path() { 36 cd "$WORKON_HOME" 37 n=2 38 project="project$n" 39 mkdir "$project" 40 env="env$n" 41 ptrfile="$WORKON_HOME/$env/.project" 42 mkvirtualenv "$env" >/dev/null 2>&1 43 setvirtualenvproject "$env" "$project" >/dev/null 2>&1 44 assertTrue ".project not found" "[ -f $ptrfile ]" 45 assertEquals \ 46 "$ptrfile contains wrong content" \ 47 "$WORKON_HOME/$project" \ 48 "$(cat $ptrfile | sed 's|^/private||')" 49} 50 51test_setvirtualenvproject_not_a_directory() { 52 cd "$WORKON_HOME" 53 n=3 54 project="project$n" 55 touch "$project" 56 env="env$n" 57 ptrfile="$WORKON_HOME/$env/.project" 58 mkvirtualenv "$env" >/dev/null 2>&1 59 setvirtualenvproject "$env" "$project" >/dev/null 2>&1 60 RC=$? 61 assertTrue "setvirtualenvproject should have failed" "[ $RC -ne 0 ]" 62} 63 64test_setvirtualenvproject_does_not_exist() { 65 n=4 66 project="project$n" 67 env="env$n" 68 ptrfile="$WORKON_HOME/$env/.project" 69 mkvirtualenv "$env" >/dev/null 2>&1 70 setvirtualenvproject "$env" "$project" >/dev/null 2>&1 71 RC=$? 72 assertTrue "setvirtualenvproject should have failed" "[ $RC -ne 0 ]" 73} 74 75test_setvirtualenvproject_relative_with_dots() { 76 cd "$WORKON_HOME" 77 n=5 78 project="project$n" 79 mkdir $project 80 mkdir $project.sibling 81 cd $project.sibling 82 # Change the reference to a sibling directory 83 project="../$project" 84 env="env$n" 85 ptrfile="$WORKON_HOME/$env/.project" 86 mkvirtualenv "$env" >/dev/null 2>&1 87 setvirtualenvproject "$env" "$project" >/dev/null 2>&1 88 assertTrue ".project not found" "[ -f $ptrfile ]" 89 assertEquals \ 90 "$ptrfile contains wrong content" \ 91 "$WORKON_HOME/project$n" \ 92 "$(cat $ptrfile | sed 's|^/private||')" 93} 94 95. "$test_dir/shunit2" 96