Skip to content

Commit a771021

Browse files
PYTHON-1960 Use a virtualenv to run encryption tests (#508)
1 parent c8be79f commit a771021

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

.evergreen/run-tests.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -o errexit # Exit the script with error if any of the commands fail
33

44
# Supported/used environment variables:
@@ -47,6 +47,9 @@ if [ "$SSL" != "nossl" ]; then
4747
export CA_PEM="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
4848
fi
4949

50+
# For createvirtualenv.
51+
. .evergreen/utils.sh
52+
5053
if [ -z "$PYTHON_BINARY" ]; then
5154
VIRTUALENV=$(command -v virtualenv) || true
5255
if [ -z "$VIRTUALENV" ]; then
@@ -109,6 +112,7 @@ if [ -n "$TEST_PYOPENSSL" ]; then
109112
. pyopenssltest/bin/activate
110113
fi
111114
trap "deactivate; rm -rf pyopenssltest" EXIT HUP
115+
PYTHON=python
112116

113117
IS_PYTHON_2=$(python -c "import sys; sys.stdout.write('1' if sys.version_info < (3,) else '0')")
114118
if [ $IS_PYTHON_2 = "1" ]; then
@@ -125,6 +129,14 @@ if [ -n "$TEST_PYOPENSSL" ]; then
125129
fi
126130

127131
if [ -n "$TEST_ENCRYPTION" ]; then
132+
createvirtualenv $PYTHON venv-encryption
133+
trap "deactivate; rm -rf venv-encryption" EXIT HUP
134+
PYTHON=python
135+
136+
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
137+
$PYTHON -m pip install -U setuptools
138+
fi
139+
128140
if [ -z "$LIBMONGOCRYPT_URL" ]; then
129141
echo "Cannot test client side encryption without LIBMONGOCRYPT_URL!"
130142
exit 1
@@ -152,13 +164,13 @@ if [ -n "$TEST_ENCRYPTION" ]; then
152164
exit 1
153165
fi
154166

155-
git clone --branch master git@github.com:mongodb/libmongocrypt.git libmongocrypt_git
156-
$PYTHON -m pip install --upgrade ./libmongocrypt_git/bindings/python
157-
# TODO: use a virtualenv
158-
trap "$PYTHON -m pip uninstall -y pymongocrypt" EXIT HUP
159-
$PYTHON -c "import pymongocrypt; print('pymongocrypt version: '+pymongocrypt.__version__)"
160-
$PYTHON -c "import pymongocrypt; print('libmongocrypt version: '+pymongocrypt.libmongocrypt_version())"
161-
# PATH is set by PREPARE_SHELL.
167+
# TODO: Test with 'pip install pymongocrypt'
168+
git clone --branch master https://github.com/mongodb/libmongocrypt.git libmongocrypt_git
169+
python -m pip install --upgrade ./libmongocrypt_git/bindings/python
170+
python -c "import pymongocrypt; print('pymongocrypt version: '+pymongocrypt.__version__)"
171+
python -c "import pymongocrypt; print('libmongocrypt version: '+pymongocrypt.libmongocrypt_version())"
172+
# PATH is updated by PREPARE_SHELL for access to mongocryptd.
173+
162174
fi
163175

164176
PYTHON_IMPL=$($PYTHON -c "import platform, sys; sys.stdout.write(platform.python_implementation())")

.evergreen/utils.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# createvirtualenv /path/to/python /output/path/for/venv
55
# * param1: Python binary to use for the virtualenv
66
# * param2: Path to the virtualenv to create
7-
function createvirtualenv {
7+
createvirtualenv () {
88
PYTHON=$1
99
VENVPATH=$2
1010
if $PYTHON -m virtualenv --version; then
@@ -28,7 +28,7 @@ function createvirtualenv {
2828
# * param1: Python binary to test
2929
# * param2: Path to the wheel or egg file to install
3030
# * param3 (optional): If set to a non-empty string, don't create a virtualenv. Used in manylinux containers.
31-
function testinstall {
31+
testinstall () {
3232
PYTHON=$1
3333
RELEASE=$2
3434
NO_VIRTUALENV=$3

0 commit comments

Comments
 (0)