Skip to content

updates to make CI jobs pass #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions docs/source/command_ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -465,36 +465,6 @@ for the environment.

*Based on a contribution from James Bennett and Jannis Leidel.*

.. _command-toggleglobalsitepackages:

toggleglobalsitepackages
------------------------

Controls whether the active virtualenv will access the packages in the
global Python ``site-packages`` directory.

Syntax::

toggleglobalsitepackages [-q]

Outputs the new state of the virtualenv. Use the ``-q`` switch to turn off all
output.

::

$ mkvirtualenv env1
New python executable in env1/bin/python
Installing setuptools.............................................
..................................................................
..................................................................
done.
(env1)$ toggleglobalsitepackages
Disabled global site-packages
(env1)$ toggleglobalsitepackages
Enabled global site-packages
(env1)$ toggleglobalsitepackages -q
(env1)$

============================
Project Directory Management
============================
Expand Down
17 changes: 12 additions & 5 deletions docs/source/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,29 @@ The test suite for virtualenvwrapper uses shunit2_ and tox_. The
shunit2 source is included in the ``tests`` directory, but tox must be
installed separately (``pip install tox``).

To run the tests under bash, zsh, and ksh for Python 2.7 through 3.6,
run ``tox`` from the top level directory of the hg repository.
To run the tests under bash and zsh for the default Python,
run ``tox`` from the top level directory of the hg repository::

$ tox

To run individual test scripts, use a command like::

$ tox tests/test_cd.sh
$ tox -- tests/test_cd.sh

To run tests under a single version of Python, specify the appropriate
environment when running tox::

$ tox -e py27
$ tox -e py311

Combine the two modes to run specific tests with a single version of
Python::

$ tox -e py27 tests/test_cd.sh
$ tox -e py311 -- tests/test_cd.sh

To stop the test suite as soon as any test fails, use the `fast` tox
target::

$ tox -e fast

Add new tests by modifying an existing file or creating new script in
the ``tests`` directory.
Expand Down
17 changes: 13 additions & 4 deletions tests/run_tests
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- mode: shell-script -*-
#set -x

envdir="$1"
envdir="$(cd $1 && pwd)"
shift
scripts="$*"
if [ -z "$scripts" ]
Expand All @@ -14,6 +14,9 @@ then
fi
fi

# Override FAIL_FAST to true to exit as soon as any test fails
FAIL_FAST=${FAIL_FAST:-false}

# Force the tox virtualenv to be active.
#
# Since this script runs from within a separate shell created by tox,
Expand All @@ -33,7 +36,7 @@ export HOOK_VERBOSE_OPTION

# Force virtualenvwrapper to use the python interpreter in the
# tox-created virtualenv.
VIRTUALENVWRAPPER_PYTHON="$envdir/bin/python"
VIRTUALENVWRAPPER_PYTHON="$envdir/bin/python3"
export VIRTUALENVWRAPPER_PYTHON

# Clear any user settings for the hook directory or log directory
Expand All @@ -44,6 +47,7 @@ unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS

# Run the test scripts with a little formatting around them to make it
# easier to find where each script output starts.
RC=0
for test_script in $scripts
do

Expand All @@ -66,9 +70,14 @@ do
echo
SHUNIT_PARENT="$test_script"
export SHUNIT_PARENT
$SHELL $test_shell_opts $test_script || exit 1
if ! $SHELL $test_shell_opts $test_script; then
RC=1
if $FAIL_FAST; then
exit $RC
fi
fi
echo

done

exit 0
exit $RC
5 changes: 0 additions & 5 deletions tests/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,3 @@ export WORKON_HOME=$(mktemp -d -t "WORKON_HOME.XXXX.$$")
export PROJECT_HOME=$(mktemp -d -t "PROJECT_HOME.XXXX.$$")

#unset HOOK_VERBOSE_OPTION

# tox no longer exports these variables by default, so set them
# ourselves to ensure the tests that rely on the values work
export USER=$(id -u -n)
export HOME=$(id -P | cut -f9 -d:)
40 changes: 0 additions & 40 deletions tests/test_cp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ test_virtualenvwrapper_virtualenv_clone_variable () {
assertTrue "VIRTUALENVWRAPPER_CLONE did not clone fake file" "[ -f $WORKON_HOME/destination/fake_virtualenv_clone_was_here ]"
}

test_source_relocatable () {
mkvirtualenv "source" >/dev/null 2>&1
(cd tests/testpackage && python setup.py install) >/dev/null 2>&1
assertTrue "virtualenv --relocatable \"$WORKON_HOME/source\""
cpvirtualenv "source" "destination" >/dev/null 2>&1
testscript="$(which testscript.py)"
assertTrue "Environment test script not the same as copy" "[ $WORKON_HOME/destination/bin/testscript.py -ef $testscript ]"
assertTrue virtualenvwrapper_verify_active_environment
assertSame "Wrong virtualenv name" "destination" $(basename "$VIRTUAL_ENV")
}

test_source_does_not_exist () {
assertSame "Please provide a valid virtualenv to copy." "$(cpvirtualenv virtualenvthatdoesntexist foo)"
}
Expand Down Expand Up @@ -148,33 +137,4 @@ GLOBAL postcpvirtualenv"
rm -f "$WORKON_HOME/postmkvirtualenv"
}

test_no_site_packages () {
# See issue #102
mkvirtualenv "source" --no-site-packages >/dev/null 2>&1
cpvirtualenv "source" "destination" >/dev/null 2>&1
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
assertTrue "$ngsp_file does not exist in copied env" "[ -f \"$ngsp_file\" ]"
}

test_no_site_packages_default_args () {
# See issue #102
VIRTUALENVWRAPPER_VIRTUALENV_ARGS="--no-site-packages"
# With the argument, verify that they are not copied.
mkvirtualenv "source" >/dev/null 2>&1
cpvirtualenv "source" "destination" >/dev/null 2>&1
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS
}

test_no_site_packages_default_behavior () {
# See issue #102
# virtualenv 1.7 changed to make --no-site-packages the default
mkvirtualenv "source" >/dev/null 2>&1
cpvirtualenv "source" "destination" >/dev/null 2>&1
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
assertTrue "$ngsp_file does not exist in copied env" "[ -f \"$ngsp_file\" ]"
}

. "$test_dir/shunit2"

4 changes: 0 additions & 4 deletions tests/test_lazy_loaded.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ test_lssitepackages_defined_normal() {
function_defined_normal lssitepackages
}

test_toggleglobalsitepackages_defined_normal() {
function_defined_normal toggleglobalsitepackages
}

test_cpvirtualenv_defined_normal() {
function_defined_normal cpvirtualenv
}
Expand Down
10 changes: 5 additions & 5 deletions tests/test_ls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ test_get_site_packages_dir () {

test_lssitepackages () {
mkvirtualenv "lssitepackagestest" >/dev/null 2>&1
contents="$(lssitepackages)"
assertTrue "did not find easy_install in site-packages" "echo $contents | grep -q easy_install"
contents="$(lssitepackages)"
assertTrue "did not find pip in site-packages: ${contents}" "echo $contents | grep -q pip"
deactivate
}

test_lssitepackages_space_in_name () {
# Only test with leading and internal spaces. Directory names with trailing spaces are legal,
# and work with virtualenv on OSX, but error out on Linux.
mkvirtualenv " space lssitepackagestest" >/dev/null 2>&1
contents="$(lssitepackages)"
assertTrue "did not find easy_install in site-packages" "echo $contents | grep -q easy_install"
contents="$(lssitepackages)"
assertTrue "did not find pip in site-packages: ${contents}" "echo $contents | grep -q pip"
deactivate
}

Expand All @@ -46,7 +46,7 @@ test_lssitepackages_add2virtualenv () {
parent_dir=$(dirname $(pwd))
base_dir=$(basename $(pwd))
add2virtualenv "../$base_dir"
contents="$(lssitepackages)"
contents="$(lssitepackages)"
actual=$(echo $contents | grep $base_dir)
expected=$(echo $contents)
assertSame "$expected" "$actual"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_mktmpenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ test_mktmpenv_no_cd() {
}

test_mktmpenv_virtualenv_args() {
mktmpenv --no-site-packages >/dev/null 2>&1
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
mktmpenv --without-pip >/dev/null 2>&1
contents="$(lssitepackages)"
assertFalse "found pip in site-packages: ${contents}" "echo $contents | grep -q pip"
}

test_deactivate() {
Expand Down
29 changes: 7 additions & 22 deletions tests/test_mkvirtualenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,6 @@ test_no_workon_home () {
WORKON_HOME="$old_home"
}

test_mkvirtualenv_sitepackages () {
# This part of the test is not reliable because
# creating a new virtualenv from inside the
# tox virtualenv inherits the setting from there.
# # Without the option, verify that site-packages are copied.
# mkvirtualenv "with_sp" >/dev/null 2>&1
# ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
# assertFalse "$ngsp_file exists" "[ -f \"$ngsp_file\" ]"
# rmvirtualenv "env3"

# With the argument, verify that they are not copied.
mkvirtualenv --no-site-packages "without_sp" >/dev/null 2>&1
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
rmvirtualenv "env4" >/dev/null 2>&1
}

test_mkvirtualenv_hooks_system_site_packages () {
# See issue #189

Expand All @@ -143,12 +126,14 @@ GLOBAL postmkvirtualenv"

test_mkvirtualenv_args () {
# See issue #102
VIRTUALENVWRAPPER_VIRTUALENV_ARGS="--no-site-packages"
VIRTUALENVWRAPPER_VIRTUALENV_ARGS="--without-pip"
# With the argument, verify that they are not copied.
mkvirtualenv "without_sp2" >/dev/null 2>&1
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
rmvirtualenv "env4" >/dev/null 2>&1
mkvirtualenv "without_pip" >/dev/null 2>&1
local RC=$?
assertTrue "mkvirtualenv failed" "[ $RC -eq 0 ]"
contents="$(lssitepackages)"
assertFalse "found pip in site-packages: ${contents}" "echo $contents | grep -q pip"
rmvirtualenv "without_pip" >/dev/null 2>&1
unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_run_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test_virtualenvwrapper_run_hook_permissions() {
echo "echo run $@ >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/prermvirtualenv"
chmod 0444 "$WORKON_HOME/prermvirtualenv"
touch "$TMPDIR/catch_output"
error=$(virtualenvwrapper_run_hook "pre_rmvirtualenv" "foo" 2>&1 | grep "could not run" | cut -f2- -d'[')
error=$(virtualenvwrapper_run_hook "pre_rmvirtualenv" "foo" 2>&1 | grep "could not run" | cut -f2- -d'[' | cut -f1 -d:)
output=$(cat "$TMPDIR/catch_output")
expected=""
assertSame "$expected" "$output"
Expand Down
15 changes: 15 additions & 0 deletions tests/test_tempfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ setUp () {
}

test_tempfile () {
if [ "$(uname)" = "Darwin" ]; then
# macOS doesn't seem to allow controlling where mktemp creates
# the output files
return 0
fi
filename=$(virtualenvwrapper_tempfile hook)
assertTrue "Filename is empty" "[ ! -z \"$filename\" ]"
assertTrue "File doesn't exist" "[ -f \"$filename\" ]"
Expand Down Expand Up @@ -52,6 +57,11 @@ test_bad_mktemp() {
}

test_no_such_tmpdir () {
if [ "$(uname)" = "Darwin" ]; then
# macOS doesn't seem to allow controlling where mktemp creates
# the output files
return 0
fi
old_tmpdir="$TMPDIR"
export TMPDIR="$TMPDIR/does-not-exist"
virtualenvwrapper_run_hook "initialize" >/dev/null 2>&1
Expand All @@ -61,6 +71,11 @@ test_no_such_tmpdir () {
}

test_tmpdir_not_writable () {
if [ "$(uname)" = "Darwin" ]; then
# macOS doesn't seem to allow controlling where mktemp creates
# the output files
return 0
fi
old_tmpdir="$TMPDIR"
export TMPDIR="$TMPDIR/cannot-write"
mkdir "$TMPDIR"
Expand Down
43 changes: 0 additions & 43 deletions tests/test_toggleglobalsitepackages.sh

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_wipeenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ test_wipeenv_pip_e () {
mkvirtualenv "wipetest" >/dev/null 2>&1
(cd tests/testpackage && pip install -e .) >/dev/null 2>&1
before="$(pip freeze)"
assertTrue "testpackage not installed" "pip freeze | grep testpackage"
assertTrue "testpackage not installed: $before" "pip freeze | grep testpackage"
wipeenv >/dev/null 2>&1
after="$(pip freeze)"
assertFalse "testpackage still installed" "pip freeze | grep testpackage"
assertFalse "testpackage still installed: $after" "pip freeze | grep testpackage"
}

# test_wipeenv_pip_e_url () {
Expand Down
Loading