diff --git a/kong/run_tests.sh b/kong/run_tests.sh index 4010fcd2c2..a7d7f63e54 100755 --- a/kong/run_tests.sh +++ b/kong/run_tests.sh @@ -33,8 +33,9 @@ function process_option { 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 @@ function run_pep8 { ${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 5ff837e0e2..bf371a7616 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -26,15 +26,15 @@ done 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 d0920d4642..c190886d16 100644 --- a/tools/install_venv.py +++ b/tools/install_venv.py @@ -96,8 +96,10 @@ def install_dependencies(venv=VENV): 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)