The runtests.sh script is responsible for ...
* Satisfying test dependencies by creating a virtualenv
* Running all applicable tests using py.test
---
Makefile | 6 +-
tests/dependencies.txt | 2 +
tests/factory/run.sh | 5 --
tests/runtests.sh | 87 ++++++++++++++++++++++++++++++++
tests/tdl/run.sh | 128 ------------------------------------------------
5 files changed, 92 insertions(+), 136 deletions(-)
create mode 100644 tests/dependencies.txt
delete mode 100755 tests/factory/run.sh
create mode 100755 tests/runtests.sh
delete mode 100755 tests/tdl/run.sh
diff --git a/Makefile b/Makefile
index 0957518..d228378 100644
--- a/Makefile
+++ b/Makefile
@@ -28,11 +28,11 @@ man2html:
@groff -mandoc man/oz-cleanup-cache.1 -T html > man/oz-cleanup-cache.html
unittests:
- @cd tests/tdl ; ./run.sh
- @cd tests/factory ; ./run.sh
+ @bash tests/runtests.sh
+# @cd tests/factory ; ./run.sh
pylint:
pylint --rcfile=pylint.conf oz oz-install oz-customize oz-cleanup-cache
oz-generate-icicle
clean:
- rm -rf MANIFEST build dist usr *~ oz.spec *.pyc oz/*~ oz/*.pyc examples/*~ oz/auto/*~
man/*~ docs/*~ man/*.html tests/tdl/*~ tests/factory/*~
+ rm -rf MANIFEST build dist usr *~ oz.spec *.pyc oz/*~ oz/*.pyc examples/*~ oz/auto/*~
man/*~ docs/*~ man/*.html tests/tdl/*~ tests/factory/*~ tests/test_results.xml
tests/test_env
diff --git a/tests/dependencies.txt b/tests/dependencies.txt
new file mode 100644
index 0000000..7f0a740
--- /dev/null
+++ b/tests/dependencies.txt
@@ -0,0 +1,2 @@
+pytest>=2.0.1
+libxml2dom
diff --git a/tests/factory/run.sh b/tests/factory/run.sh
deleted file mode 100755
index 0e00333..0000000
--- a/tests/factory/run.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-export PYTHONPATH=../..:$PYTHONPATH
-
-python test_factory.py
diff --git a/tests/runtests.sh b/tests/runtests.sh
new file mode 100755
index 0000000..961d9d4
--- /dev/null
+++ b/tests/runtests.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+# Test driver responsible for satisfying test dependencies using virtualenv,
+# and running available tests
+
+# Used for the name of the virtualenv
+ENV_PATH='tests/test_env'
+
+# pip-python's requirements
+REQ_FILE='tests/dependencies.txt'
+
+# this is to make sure that pip-python isn't going to touch anything but the
+# virtualenv
+PIP_REQUIRE_VIRTUALENV=1
+
+# this keeps track of the python version since virtualenv will use the system
+# python version by default
+PYTHON_SITELIB=$(python -c "from distutils.sysconfig import get_python_lib; print
get_python_lib(prefix='')")
+
+# Additional py.test command arguments
+PYTEST_ARGS="--junitxml=tests/test_results.xml --ignore=${ENV_PATH}"
+
+# Display basic usage
+usage()
+{
+ cat << EOF
+ usage: $0
+ This script prepares a virtualenv for running the tests (if it doesn't
+ already exist) and runs unit tests in that virtualenv.
+
+ OPTIONS:
+ -h Show this message
+ -v Enable Verbosity
+EOF
+ exit 1
+}
+
+# Creates and prepares a virtualenv
+create_env()
+{
+ echo "Virtualenv ($ENV_PATH) does not already exist."
+ echo "Creating virtualenv ... "
+ virtualenv $ENV_PATH
+
+ echo "Installing packages (into $ENV_PATH) required for tests ... "
+ pip-python -E $ENV_PATH install -r $REQ_FILE
+
+ echo "Adding oz to virtualenv site-packages ... "
+ pushd "$ENV_PATH/$PYTHON_SITELIB"
+ ln -sf ../../../../../oz
+ popd
+
+ echo "Virtualenv created and prepared."
+}
+
+# Process arguments
+while getopts "hv" OPTION
+do
+ case ${OPTION} in
+ v ) PYTEST_ARGS="${PYTEST_ARGS} --verbose" ;;
+ \?|h ) usage ;;
+ * ) usage ;;
+ esac
+done
+
+# check for virtualenv
+if [ ! -e $ENV_PATH ]; then
+ create_env
+else
+ echo "Virtualenv ($ENV_PATH) detected."
+fi
+
+# Activate the virtualenv
+source "$ENV_PATH/bin/activate"
+
+# Run the tests
+py.test ${PYTEST_ARGS} tests
+
+TEST_RESULT=$?
+
+# Deactivate the virtualenv
+deactivate
+
+if [ $TEST_RESULT -ne 0 ]; then
+ exit 1
+else
+ exit 0
+fi
diff --git a/tests/tdl/run.sh b/tests/tdl/run.sh
deleted file mode 100755
index f44ce5c..0000000
--- a/tests/tdl/run.sh
+++ /dev/null
@@ -1,128 +0,0 @@
-#!/bin/bash
-
-export PYTHONPATH=../..:$PYTHONPATH
-
-if [ -z "$DEBUG" ]; then
- DEBUG=0
-fi
-
-SUCCESS=0
-FAIL=0
-
-success() {
- echo "OK"
- SUCCESS=$(( $SUCCESS + 1 ))
-}
-
-failure() {
- echo "FAIL"
- FAIL=$(( $FAIL + 1 ))
-}
-
-schema_test() {
- schema="$1"
- expectsuccess="$2"
-
- echo -n "Testing Schema $schema..."
-
- if [ ! -r "$1" ]; then
- echo "FAIL: File not found"
- FAIL=$(( $FAIL + 1 ))
- return
- fi
- if [ $DEBUG -eq 0 ]; then
- xmllint --noout --relaxng ../../docs/tdl.rng "$schema" >& /dev/null
- else
- xmllint --relaxng ../../docs/tdl.rng "$schema"
- fi
-
- RET=$?
-
- if [ $RET -eq 0 -a "$expectsuccess" = "true" ] || [ $RET -ne 0 -a
"$expectsuccess" != "true" ]; then
- success
- else
- failure
- fi
-}
-
-python_test() {
- parse="$1"
- expectsuccess="$2"
-
- echo -n "Testing Parsing $1..."
- if [ ! -r "$1" ]; then
- echo "FAIL: File not found"
- FAIL=$(( $FAIL + 1 ))
- return
- fi
-
- if [ $DEBUG -eq 0 ]; then
- python test_tdl.py "$1" >& /dev/null
- else
- python test_tdl.py "$1"
- fi
-
- RET=$?
-
- if [ $RET -eq 0 -a "$expectsuccess" = "true" ] || [ $RET -ne 0 -a
"$expectsuccess" != "true" ]; then
- success
- else
- failure
- fi
-}
-
-expect_success() {
- schema_test "$1" "true"
- python_test "$1" "true"
-}
-
-expect_fail() {
- schema_test "$1" "false"
- python_test "$1" "false"
-}
-
-expect_success test-01-simple-iso.tdl
-expect_success test-02-simple-url.tdl
-expect_fail test-03-empty-template.tdl
-expect_fail test-04-no-os.tdl
-expect_fail test-05-no-name.tdl
-expect_success test-06-simple-iso-description.tdl
-expect_success test-07-packages-no-package.tdl
-expect_success test-08-repositories-no-repository.tdl
-expect_fail test-09-os-invalid-arch.tdl
-expect_fail test-10-os-invalid-install-type.tdl
-expect_success test-11-description-packages-repositories.tdl
-expect_fail test-12-os-no-name.tdl
-expect_fail test-13-os-no-version.tdl
-expect_fail test-14-os-no-arch.tdl
-expect_fail test-15-os-no-install.tdl
-expect_success test-16-signed-repository.tdl
-expect_fail test-17-repo-invalid-signed.tdl
-expect_success test-18-rootpw.tdl
-expect_success test-19-key.tdl
-expect_fail test-20-multiple-install.tdl
-expect_fail test-21-missing-install-type.tdl
-expect_success test-22-md5sum.tdl
-expect_success test-23-sha1sum.tdl
-expect_success test-24-sha256sum.tdl
-expect_fail test-25-md5sum-and-sha1sum.tdl
-expect_fail test-26-md5sum-and-sha256sum.tdl
-expect_fail test-27-sha1sum-and-sha256sum.tdl
-expect_fail test-28-package-no-name.tdl
-expect_success test-29-files.tdl
-expect_fail test-30-file-no-name.tdl
-expect_success test-31-file-raw-type.tdl
-expect_success test-32-file-base64-type.tdl
-expect_fail test-33-file-invalid-type.tdl
-expect_fail test-34-file-invalid-base64.tdl
-expect_fail test-35-repository-no-name.tdl
-expect_fail test-36-repository-no-url.tdl
-expect_success test-37-command.tdl
-expect_fail test-38-command-no-name.tdl
-expect_success test-39-command-raw-type.tdl
-expect_success test-40-command-base64-type.tdl
-expect_fail test-41-command-bogus-base64.tdl
-expect_fail test-42-command-bogus-type.tdl
-
-echo "SUCCESS: $SUCCESS, FAIL: $FAIL"
-exit $FAIL
--
1.7.6