Commits

Doug Hellmann  committed c26d9eb

fix tests; clean up contributed changes

  • Participants
  • Parent commits eec22a4

Comments (0)

Files changed (7)

+2010-05-09  Doug Hellmann  <dhellmann@racemi.com>
+
+	* virtualenvwrapper.sh: Tweak path normalization code so double
+	slashes are also removed from WORKON_HOME. Use typeset for local
+	variables.
+	(virtualenvwrapper_tempfile): Add -t option to mktemp so the new
+	files are always created in the user's temporary directory.
+	(virtualenvwrapper_run_hook): Add the hook name to the temporary
+	file name.
+
+	* tests/test_tempfile.sh: Remove obsolete test.  Fix assertions
+	for remaining test.
+
+	* tests/test_mkvirtualenv.sh (test_hooks): Use pwd to convert
+	WORKON_HOME to the expected value.
+
+	* tests/test.sh (test_python_interpreter_set_incorrectly): Rework
+	grep-based assertion to actually pass.
+
+	* Makefile (test-bash test-ksh test-sh): Remove wildcard build
+	rule so test-quick target works.
+
 2010-05-02  Doug Hellmann  <dhellmann@racemi.com>
 
 	* virtualenvwrapper.sh (virtualenvwrapper_run_hook): Instead of
 	@echo "installwebsite - deploy web version of docs"
 	@echo "develop        - install development version"
 	@echo "test           - run the test suite"
+	@echo "test-quick     - run the test suite for bash and one version of Python"
 
 
 .PHONY: sdist
 develop:
 	python setup.py develop
 
-test-%:
+test-bash test-ksh test-sh:
 	TEST_SHELL=$(subst test-,,$@) $(MAKE) test-loop
 
 test-zsh:
 			&& virtualenv -p $$py_bin --no-site-packages virtualenvwrapper-test-env) \
 			|| exit 1 ; \
 		$$TMPDIR/virtualenvwrapper-test-env/bin/python setup.py install || exit 1 ; \
-		for test_script in $(wildcard tests/test*.sh) ; do \
+		for test_script in tests/test*.sh ; do \
 			echo ; \
 	 		echo '********************************************************************************' ; \
 			echo "Running $$test_script with $(TEST_SHELL) under Python $(basename $$py_bin)" ; \
+			echo ; \
 			VIRTUALENVWRAPPER_PYTHON=$$TMPDIR/virtualenvwrapper-test-env/bin/python SHUNIT_PARENT=$$test_script $(TEST_SHELL) $$test_script || exit 1 ; \
 			echo ; \
 		done \
 	done
 
-test-quick: test-26
+test-quick:: test-26
 
 test-24:
 	PYTHON_BINARIES=$(PYTHON24) $(MAKE) test-bash

File tests/test.sh

     return_to="$(pwd)"
     cd "$WORKON_HOME"
     mkvirtualenv --no-site-packages no_wrappers
-    output=`VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV/bin/python $SHELL $return_to/virtualenvwrapper.sh 2>&1`
-    assertTrue "Unexpected message: $output" "echo \"$output\" | grep 'Could not find Python module virtualenvwrapper.hook_loader'"
+    expected="ImportError: No module named virtualenvwrapper.hook_loader"
+    output=$(VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV/bin/python $SHELL $return_to/virtualenvwrapper.sh 2>&1)
+    echo "$output" | grep "$expected" 2>&1
+    found=$?
+    assertTrue "Expected \"$expected\", got: \"$output\"" "[ $found -eq 0 ]"
     assertFalse "Failed to detect invalid Python location" "VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV/bin/python $SHELL $return_to/virtualenvwrapper.sh >/dev/null 2>&1"
     cd "$return_to"
     deactivate

File tests/test_cp.sh

     cpvirtualenv "source" "destination"
 
     output=$(cat "$test_dir/catch_output")
+    workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
 
-    expected="GLOBAL precpvirtualenv $WORKON_HOME source destination
-GLOBAL premkvirtualenv $WORKON_HOME destination
+    expected="GLOBAL precpvirtualenv $workon_home_as_pwd source destination
+GLOBAL premkvirtualenv $workon_home_as_pwd destination
 GLOBAL postmkvirtualenv
 GLOBAL postcpvirtualenv"
 

File tests/test_mkvirtualenv.sh

     echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
     mkvirtualenv "env3"
     output=$(cat "$test_dir/catch_output")
-    expected="GLOBAL premkvirtualenv $WORKON_HOME env3
+    workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
+    expected="GLOBAL premkvirtualenv $workon_home_as_pwd env3
 GLOBAL postmkvirtualenv"
     assertSame "$expected" "$output"
     rm -f "$WORKON_HOME/premkvirtualenv"

File tests/test_tempfile.sh

 test_tempfile () {
     filename=$(virtualenvwrapper_tempfile hook)
     rm -f $filename
-    assertSame "$TMPDIR" "$(dirname $filename)/"
-    assertTrue "echo $filename | grep virtualenvwrapper"
-}
-
-test_no_python () {
-    old=$VIRTUALENVWRAPPER_PYTHON
-    VIRTUALENVWRAPPER_PYTHON=false
-    filename=$(virtualenvwrapper_tempfile hook)
-    VIRTUALENVWRAPPER_PYTHON=$old
-    rm -f $filename
     assertSame "TMPDIR and path not the same for $filename." "$TMPDIR" "$(dirname $filename)/"
-    assertTrue "virtualenvwrapper and pid not in filename." "echo $filename | grep virtualenvwrapper.$$"
+    assertTrue "virtualenvwrapper-hook not in filename." "echo $filename | grep virtualenvwrapper-hook"
 }
 
 . "$test_dir/shunit2"

File virtualenvwrapper.sh

 # path might contain stuff to expand.
 # (it might be possible to do this in shell, but I don't know a
 # cross-shell-safe way of doing it -wolever)
-if echo "$WORKON_HOME" | grep -e "[$~]" > /dev/null
+if echo "$WORKON_HOME" | egrep -e "([$~]|//)" >/dev/null
 then
     # This will normalize the path by:
-    # - Expanding variables (eg, $foo)
-    # - Converting ~s to complete paths (eg, ~/ to /home/brian/ and ~arthur to /home/arthur)
+    # - Removing extra slashes (e.g., when TMPDIR ends in a slash)
+    # - Expanding variables (e.g., $foo)
+    # - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur)
     WORKON_HOME=$("$VIRTUALENVWRAPPER_PYTHON" -c "import os; print os.path.expandvars(os.path.expanduser(\"$WORKON_HOME\"))")
     export WORKON_HOME
 fi
 virtualenvwrapper_verify_workon_home () {
     if [ ! -d "$WORKON_HOME" ]
     then
-        [ "$1" != "-q" ] && echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist.  Create it or set WORKON_HOME to an existing directory." >&2
+        [ "$1" != "-q" ] && echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist.  Create it or set WORKON_HOME to an existing directory." 1>&2
         return 1
     fi
     return 0
 # Expects 1 argument, the suffix for the new file.
 virtualenvwrapper_tempfile () {
     # Note: the 'X's must come last
-    mktemp "virtualenvwrapper-$1-XXXXXX"
+    mktemp -t "virtualenvwrapper-$1-XXXXXX"
 }
 
 # Run the hooks
 virtualenvwrapper_run_hook () {
-    hook_script="$(virtualenvwrapper_tempfile hook)"
+    typeset hook_script="$(virtualenvwrapper_tempfile ${1}-hook)"
     "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script "$hook_script" "$@"
     result=$?
     
     then
         source "$hook_script"
     fi
-    rm -f "$hook_script" &> /dev/null
+    rm -f "$hook_script" >/dev/null 2>&1
     return $result
 }
 
     virtualenvwrapper_run_hook "initialize"
     if [ $? -ne 0 ]
     then
-        echo "virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH set properly." 1>&2
+        echo "virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is set properly." 1>&2
         return 1
     fi
 }
 
 # Verify that virtualenv is installed and visible
 virtualenvwrapper_verify_virtualenv () {
-    venv=$(which virtualenv | grep -v "not found")
+    typeset venv=$(which virtualenv | grep -v "not found")
     if [ "$venv" = "" ]
     then
         echo "ERROR: virtualenvwrapper could not find virtualenv in your path" >&2
 cdsitepackages () {
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
-    site_packages="`virtualenvwrapper_get_site_packages_dir`"
+    typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
     cd "$site_packages"/$1
 }
 
 lssitepackages () {
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
-    site_packages="`virtualenvwrapper_get_site_packages_dir`"
+    typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
     ls $@ $site_packages
     
     path_file="$site_packages/virtualenv_path_extensions.pth"
     fi
     if echo "$WORKON_HOME" | grep -e "/$" > /dev/null
     then
-        env_home="$WORKON_HOME"
+        typset env_home="$WORKON_HOME"
     else
-        env_home="$WORKON_HOME/"
+        typeset env_home="$WORKON_HOME/"
     fi
-    source_env="$env_home$env_name"
-    target_env="$env_home$new_env"
+    typeset source_env="$env_home$env_name"
+    typeset target_env="$env_home$new_env"
     
     if [ ! -e "$source_env" ]
     then
 
     cp -r "$source_env" "$target_env"
     for script in $( ls $target_env/bin/* )
-      do
+    do
         newscript="$script-new"
         sed "s|$source_env|$target_env|g" < "$script" > "$newscript"
         mv "$newscript" "$script"
         chmod a+x "$script"
-      done
+    done
 
     virtualenv "$target_env" --relocatable
     sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/bin/activate" > "$target_env/bin/activate"