Commits

Doug Hellmann  committed 3a195c6

associate project before enabling the new virtualenv; fixes #122

  • Participants
  • Parent commits 80cf4cd

Comments (0)

Files changed (2)

File tests/test_mkvirtualenv_associate.sh

 setUp () {
     echo
     rm -f "$test_dir/catch_output"
+    echo "#!/bin/sh" > "$WORKON_HOME/preactivate"
+    echo "#!/bin/sh" > "$WORKON_HOME/postactivate"
 }
 
 test_associate() {
     assertEquals "$ptrfile contains wrong content" "$project" "$(cat $ptrfile)"
 }
 
+test_preactivate() {
+    project="/dev/null"
+    env="env2"
+    ptrfile="$WORKON_HOME/$env/.project"
+	cat - >"$WORKON_HOME/preactivate" <<EOF
+#!/bin/sh
+if [ -f "$ptrfile" ]
+then
+    echo exists >> "$test_dir/catch_output"
+else
+    echo noexists >> "$test_dir/catch_output"
+fi
+EOF
+    chmod +x "$WORKON_HOME/preactivate"
+    mkvirtualenv -a "$project" "$env" >/dev/null 2>&1
+	assertSame "preactivate did not find file" "exists" "$(cat $test_dir/catch_output)"
+}
+
+test_postactivate() {
+    project="/dev/null"
+    env="env3"
+    ptrfile="$WORKON_HOME/$env/.project"
+cat - >"$WORKON_HOME/postactivate" <<EOF
+#!/bin/sh
+if [ -f "$ptrfile" ]
+then
+    echo exists >> "$test_dir/catch_output"
+else
+    echo noexists >> "$test_dir/catch_output"
+fi
+EOF
+    chmod +x "$WORKON_HOME/postactivate"
+    mkvirtualenv -a "$project" "$env" >/dev/null 2>&1
+	assertSame "postactivate did not find file" "exists" "$(cat $test_dir/catch_output)"
+}
+
 . "$test_dir/shunit2"

File virtualenvwrapper.sh

     # the environment won't exist.  Use that to tell whether
     # we should switch to the environment and run the hook.
     [ ! -d "$WORKON_HOME/$envname" ] && return 0
+
+	# If they gave us a project directory, set it up now
+	# so the activate hooks can find it.
+    if [ ! -z "$project" ]
+    then
+        setvirtualenvproject "$WORKON_HOME/$envname" "$project"
+    fi
+
     # Now activate the new environment
     workon "$envname"
 
         pip install $a
     done
 
-    if [ ! -z "$project" ]
-    then
-        setvirtualenvproject "" "$project"
-    fi
-
     virtualenvwrapper_run_hook "post_mkvirtualenv"
 }