From 8cf6c328fec8063897b109fa215e6653301b9525 Mon Sep 17 00:00:00 2001 From: Joris Roovers Date: Thu, 4 Aug 2016 14:53:21 +0200 Subject: Fix for python 3 test failures + run_tests.sh improvements - importlib is now only used for python 2.6 and not included for all builds. This fixes issues with python3. - run_tests.sh: --clean option: clean up the working directory (delete cache, dist, build, etc) - run_tests.sh: --install-virtualenvs and --remove-virtualenvs options to install/remove virtualenvs for other python versions. This code used to live in the Vagrantfile but has been moved to run_tests.sh so that it can be used more easily during development. --- Vagrantfile | 35 ++--------------- requirements.txt | 4 +- run_tests.sh | 114 +++++++++++++++++++++++++++++++++++++++++++++++++------ setup.py | 6 ++- 4 files changed, 113 insertions(+), 46 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index eaed7d2..357758c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,42 +4,15 @@ VAGRANTFILE_API_VERSION = "2" INSTALL_DEPS=<> /home/vagrant/.bashrc grep 'source .venv27/bin/activate' /home/vagrant/.bashrc || echo 'source .venv27/bin/activate' >> /home/vagrant/.bashrc diff --git a/requirements.txt b/requirements.txt index 12e10d3..884fb3f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,5 @@ setuptools wheel==0.24.0 Click==5.1 sh==1.11 -ordereddict==1.1 # For python 2.6 -importlib==1.0.3 # For python 2.6 \ No newline at end of file +ordereddict==1.1 +importlib==1.0.3; python_version < '2.7' \ No newline at end of file diff --git a/run_tests.sh b/run_tests.sh index 68cb834..38b2908 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -3,15 +3,18 @@ help(){ echo "Usage: $0 [OPTION]..." echo "Run gitlint's test suite(s) or some convience commands" - echo " -h, --help Show this help output" - echo " -p, --pep8 Run pep8 checks" - echo " -l, --lint Run pylint checks" - echo " -g|--git Run gitlint checks" - echo " -i|--integration Run integration tests" - echo " -a|--all Run all tests and checks (unit, integration, pep8, git)" - echo " --all-env Run all tests against all python environments" - echo " -s, --stats Show some project stats" - echo " --no-coverage Don't make a unit test coverage report" + echo " -h, --help Show this help output" + echo " -c, --clean Clean the project of temporary files" + echo " -p, --pep8 Run pep8 checks" + echo " -l, --lint Run pylint checks" + echo " -g, --git Run gitlint checks" + echo " -i, --integration Run integration tests" + echo " -a, --all Run all tests and checks (unit, integration, pep8, git)" + echo " --all-env Run all tests against all python environments" + echo " --install-virtualenvs Install virtualenvs for python 2.6, 2.7, 3.3, 3.4, 3.5" + echo " --remove-virtualenvs Remove virtualenvs for python 2.6, 2.7, 3.3, 3.4, 3.5" + echo " -s, --stats Show some project stats" + echo " --no-coverage Don't make a unit test coverage report" echo "" exit 0; } @@ -27,6 +30,11 @@ title(){ echo -e $MSG } +subtitle() { + MSG="$YELLOW$1$NO_COLOR" + echo -e $MSG +} + run_pep8_check(){ # FLAKE 8 # H307: like imports should be grouped together @@ -91,30 +99,89 @@ run_stats(){ nr_integration_tests=$(py.test qa/ --collect-only | grep TestCaseFunction | wc -l) echo " Unit Tests: ${nr_unit_tests//[[:space:]]/}" echo " Integration Tests: ${nr_integration_tests//[[:space:]]/}" + echo "*** Git ***" + echo " Number of commits: $(git rev-list --all --count)" + echo " Number of authors: $(git log --format='%aN' | sort -u | wc -l)" } clean(){ + echo -n "Cleaning the site, build, dist and all __pycache__directories..." set +e find gitlint -type d -name "__pycache__" -exec rm -rf {} \; 2> /dev/null find qa -type d -name "__pycache__" -exec rm -rf {} \; 2> /dev/null + rm -rf "site" "dist" "build" set -e + echo -e "${GREEN}DONE${NO_COLOR}" } run_all(){ - clean + subtitle "# UNIT TESTS #" run_unit_tests + subtitle "# INTEGRATION TESTS #" run_integration_tests + subtitle "# STYLE CHECKS #" run_pep8_check run_git_check } +remove_virtualenvs(){ + echo -n "Removing .venv26 .venv27 .venv33 .venv34 .venv35..." + set +e + deactivate 2> /dev/null # deactivate any active environment + set -e + rm -rf ".venv26" ".venv27" ".venv33" ".venv34" ".venv35" + echo -e "${GREEN}DONE${NO_COLOR}" +} + +install_virtualenvs(){ + echo "Installing .venv26 .venv27 .venv33 .venv34 .venv35..." + + set +e + deactivate 2> /dev/null # deactivate any active environment + set -e + + # Install the virtualenvs for different python versions + virtualenv -p /usr/bin/python2.6 .venv26 + source .venv26/bin/activate + easy_install -U pip + pip install -r requirements.txt + pip install -r test-requirements.txt + deactivate + + virtualenv -p /usr/bin/python2.7 .venv27 + source .venv27/bin/activate + easy_install -U pip + pip install -r requirements.txt + pip install -r test-requirements.txt + deactivate + + virtualenv -p /usr/bin/python3.3 .venv33 + source .venv33/bin/activate + pip3 install -r requirements.txt + pip3 install -r test-requirements.txt + deactivate + + virtualenv -p /usr/bin/python3.4 .venv34 + source .venv34/bin/activate + pip3 install -r requirements.txt + pip3 install -r test-requirements.txt + deactivate + + virtualenv -p /usr/bin/python3.5 .venv35 + source .venv35/bin/activate + pip3 install -r requirements.txt + pip3 install -r test-requirements.txt + deactivate +} + run_tests_in_all_env(){ - # Run the tests against all environments in vagrant + # Let's make sure we can recover the current virtualenv after we're done old_virtualenv="$VIRTUAL_ENV" set +e deactivate 2> /dev/null # deactivate any active environment set -e + # Run the tests against all environments in vagrant source /vagrant/.venv26/bin/activate title "### PYTHON 2.6 ($(python --version 2>&1), /vagrant/.venv26) ###" run_all @@ -140,7 +207,9 @@ run_tests_in_all_env(){ run_all deactivate - source "$old_virtualenv/bin/activate" + if [ ! -z "$old_virtualenv" ]; then + source "$old_virtualenv/bin/activate" + fi } # default behavior @@ -151,18 +220,24 @@ just_integration_tests=0 just_stats=0 just_all_env=0 just_all=0 +just_clean=0 +just_install_virtualenvs=0 +just_remove_virtualenvs=0 include_coverage=1 testargs="" while [ "$#" -gt 0 ]; do case "$1" in -h|--help) shift; help;; + -c|--clean) shift; just_clean=1;; -p|--pep8) shift; just_pep8=1;; -l|--lint) shift; just_lint=1;; -g|--git) shift; just_git=1;; -s|--stats) shift; just_stats=1;; -i|--integration) shift; just_integration_tests=1;; -a|--all) shift; just_all=1;; + --install-virtualenvs) shift; just_install_virtualenvs=1;; + --remove-virtualenvs) shift; just_remove_virtualenvs=1;; --all-env) shift; just_all_env=1;; --no-coverage)shift; include_coverage=0;; *) testargs="$1"; shift; @@ -204,5 +279,20 @@ if [ $just_all -eq 1 ]; then exit $? fi +if [ $just_clean -eq 1 ]; then + clean + exit $? +fi + +if [ $just_remove_virtualenvs -eq 1 ]; then + remove_virtualenvs + exit $? +fi + +if [ $just_install_virtualenvs -eq 1 ]; then + install_virtualenvs + exit $? +fi + run_unit_tests || exit diff --git a/setup.py b/setup.py index 67f2690..4affb69 100644 --- a/setup.py +++ b/setup.py @@ -60,8 +60,12 @@ setup( 'Click==5.1', 'sh==1.11', 'ordereddict==1.1', - 'importlib==1.0.3' ], + extras_require={ + ':python_version == "2.6"': [ + 'importlib==1.0.3', + ], + }, keywords='gitlint git lint', author='Joris Roovers', url='https://github.com/jorisroovers/gitlint', -- cgit v1.2.3