Commits

Doug Hellmann committed 3876973

associate project before enabling the new virtualenv; fixes #122

Comments (0)

Files changed (2)

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"

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"
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.