From 5babc8f562f9ba1ad3e78b5ec6906aa33d17c0a9 Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Thu, 22 Oct 2015 21:46:28 -0400 Subject: [PATCH] Add ability to test with specific Python versions --- test/README.md | 3 +++ test/Vagrantfile | 16 ++++++++++++++++ test/driver-lib.bash | 9 +++++++++ test/test | 21 +++++++++++++++++++-- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/test/README.md b/test/README.md index 824dbca..c4abddc 100644 --- a/test/README.md +++ b/test/README.md @@ -17,6 +17,9 @@ started by running `vagrant up`. The test suite can be run by running `./test`. Selected tests can be run by passing paths to the tests as arguments to `./test`. +Tests can be run with a specific Python version by running `./test --version +` - for example, `./test --version 3.4.3`. + When finished with testing, it is good to shut down the virtual machine by running `vagrant halt`. diff --git a/test/Vagrantfile b/test/Vagrantfile index 4463f99..37e2da0 100644 --- a/test/Vagrantfile +++ b/test/Vagrantfile @@ -7,4 +7,20 @@ Vagrant.configure(2) do |config| # disable default synced folder config.vm.synced_folder ".", "/vagrant", disabled: true + + # install packages + config.vm.provision "shell", inline: <<-EOS + apt-get -y update + apt-get install -y git make build-essential libssl-dev zlib1g-dev \ + libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ + libncurses5-dev + EOS + + # install pyenv + config.vm.provision "shell", privileged: false, inline: <<-EOS + rm -rf ~/.pyenv + git clone git://github.com/yyuu/pyenv.git ~/.pyenv + echo 'export PATH="$HOME/.pyenv/bin:$PATH"\neval "$(pyenv init -)"' \ + > ~/.bashrc + EOS end diff --git a/test/driver-lib.bash b/test/driver-lib.bash index f7b25ba..56a0740 100644 --- a/test/driver-lib.bash +++ b/test/driver-lib.bash @@ -65,6 +65,14 @@ rollback() { initialize() { echo "initializing." vagrant sandbox on >/dev/null 2>&1 + if ! vagrant ssh -c "pyenv local ${2}" >/dev/null 2>&1; then + wait_for_vagrant && vagrant sandbox rollback >/dev/null 2>&1 + wait_for_vagrant + if ! vagrant ssh -c "pyenv install -s ${2} && pyenv local ${2}" >/dev/null 2>&1; then + die "could not install python ${2}" + fi + vagrant sandbox commit >/dev/null 2>&1 + fi tests_run=0 tests_passed=0 tests_failed=0 @@ -89,6 +97,7 @@ run_test() { tests_run=$((tests_run + 1)) printf '[%d/%d] (%s)\n' "${tests_run}" "${tests_total}" "${1}" rollback || die "unable to rollback vm." # start with a clean slate + vagrant ssh -c "pyenv local ${2}" >/dev/null 2>&1 if vagrant ssh -c "cd /dotbot/test/tests && bash ${1}" 2>/dev/null; then pass else diff --git a/test/test b/test/test index 7f4b8f1..e22f7fb 100755 --- a/test/test +++ b/test/test @@ -9,6 +9,23 @@ start="$(date +%s)" check_prereqs || die "prerequisites unsatsfied." +# command line options +while [[ $# > 1 ]] +do + key="${1}" + case $key in + -v|--version) + VERSION="${2}" + shift && shift + ;; + *) + # unknown option + break + ;; + esac +done +VERSION="${VERSION:-2.7.9}" + declare -a tests=() if [ $# -eq 0 ]; then @@ -19,10 +36,10 @@ else tests=("$@") fi -initialize "${#tests[@]}" +initialize "${#tests[@]}" "${VERSION}" for file in "${tests[@]}"; do - run_test "$(basename "${file}")" + run_test "$(basename "${file}")" "${VERSION}" done if report; then