Making run_test.sh python version and directory
agnostic
Refactored some of the shell scripts to handle
being run from another directory, as well as to
not force the use of 2.6
edit: format the comments
Change-Id: Id92b9dc82743598b7c570e431cad423c8a2ee95d
diff --git a/kong/run_tests.sh b/kong/run_tests.sh
index 4010fcd..a7d7f63 100755
--- a/kong/run_tests.sh
+++ b/kong/run_tests.sh
@@ -33,8 +33,9 @@
esac
}
+base_dir=$(dirname $0)
venv=.kong-venv
-with_venv=tools/with_venv.sh
+with_venv=../tools/with_venv.sh
always_venv=0
never_venv=0
force=0
@@ -59,35 +60,38 @@
${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE || exit 1
}
NOSETESTS="env python run_tests.py $noseargs"
-
-if [ $never_venv -eq 0 ]
-then
- # Remove the virtual environment if --force used
- if [ $force -eq 1 ]; then
- echo "Cleaning virtualenv..."
- rm -rf ${venv}
- fi
- if [ -e ${venv} ]; then
- wrapper="${with_venv}"
- else
- if [ $always_venv -eq 1 ]; then
- # Automatically install the virtualenv
- use_ve='y'
- else
- echo -e "No virtual environment found...create one? (Y/n) \c"
- read use_ve
+function setup_venv {
+ if [ $never_venv -eq 0 ]
+ then
+ # Remove the virtual environment if --force used
+ if [ $force -eq 1 ]; then
+ echo "Cleaning virtualenv..."
+ rm -rf ${venv}
+ fi
+ if [ -e ${venv} ]; then
+ wrapper="${with_venv}"
+ else
+ if [ $always_venv -eq 1 ]; then
+ # Automatically install the virtualenv
+ use_ve='y'
+ else
+ echo -e "No virtual environment found...create one? (Y/n) \c"
+ read use_ve
+ fi
+ if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
+ # Install the virtualenv and run the test suite in it
+ env python ../tools/install_venv.py
+ wrapper=${with_venv}
+ fi
+ fi
fi
- if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
- # Install the virtualenv and run the test suite in it
- env python ../tools/install_venv.py
- wrapper=${with_venv}
- fi
- fi
-fi
+}
if [ $just_pep8 -eq 1 ]; then
run_pep8
exit
fi
+cd $base_dir
+setup_venv
run_tests || exit
diff --git a/run_tests.sh b/run_tests.sh
index 5ff837e..bf371a7 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -26,15 +26,15 @@
echo $test_opts
function run_tests {
+ base_dir=$(dirname $0)
for test_dir in $tests
do
- cd $test_dir
- test_cmd="./run_tests.sh ${test_opts}"
+ test_cmd="${base_dir}/${test_dir}/run_tests.sh ${test_opts}"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo $test_cmd
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
$test_cmd
- cd ..
+
done
}
diff --git a/tools/install_venv.py b/tools/install_venv.py
index d0920d4..c190886d 100644
--- a/tools/install_venv.py
+++ b/tools/install_venv.py
@@ -96,8 +96,10 @@
run_command([venv_tool, 'pip', 'install', '-E', venv, '-r', PIP_REQUIRES],
redirect_output=False)
+ python_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
+
# Tell the virtual env how to "import glance"
- pthfile = os.path.join(venv, "lib", "python2.6", "site-packages",
+ pthfile = os.path.join(venv, "lib", python_version, "site-packages",
"glance.pth")
f = open(pthfile, 'w')
f.write("%s\n" % ROOT)