From b0bea13bc92b96b2f7daf5fd243b960ae9de8cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 24 Apr 2017 15:25:45 +0200 Subject: [PATCH] misc: use tox to run tests in jenkins (#10284) --- jenkins.sh | 23 +++-------------------- pylint.sh | 16 ++++++++++++++++ setup.py | 2 +- tests/test_wcs.py | 5 ++--- tox.ini | 31 +++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 24 deletions(-) create mode 100755 pylint.sh create mode 100644 tox.ini diff --git a/jenkins.sh b/jenkins.sh index 7bf4928b..a920c4ee 100755 --- a/jenkins.sh +++ b/jenkins.sh @@ -2,29 +2,12 @@ set -e +rm -f pylint.out rm -f coverage.xml rm -f test_results.xml test -d wcs || git clone http://git.entrouvert.org/wcs.git (cd wcs && git pull) -export PIP_USE_WHEEL=no -(pip freeze | grep -q Quixote) || pip install quixote -(pip freeze | grep -q scgi) || pip install scgi -pip install --upgrade 'pip<8' -pip install --upgrade 'pylint<1.8' pylint-django -pip install --upgrade -r requirements.txt -pip install --upgrade pytest pytest-django pytest-cov WebTest django-webtest 'setuptools<34' -pip install --upgrade 'django>=1.8, <1.9' -pip install --no-deps --upgrade 'git+http://repos.entrouvert.org/cmsplugin-blurp.git/#egg=django-cmsplugin-blurp' # use blurp from git/master for now -pip install --upgrade XStatic-ChartNew.js -pip install --upgrade mock - -WCSCTL=$(pwd)/wcs/wcsctl.py \ - DJANGO_SETTINGS_MODULE=combo.settings \ - COMBO_SETTINGS_FILE=tests/settings.py \ - py.test --junitxml=test_results.xml --cov-report xml --cov=combo/ --cov-config .coveragerc tests/ - -test -f pylint.out && cp pylint.out pylint.out.prev -(pylint -f parseable --rcfile /var/lib/jenkins/pylint.django.rc combo | tee pylint.out) || /bin/true -test -f pylint.out.prev && (diff pylint.out.prev pylint.out | grep '^[><]' | grep .py) || /bin/true +pip install --upgrade tox +tox -rv diff --git a/pylint.sh b/pylint.sh new file mode 100755 index 00000000..babdf183 --- /dev/null +++ b/pylint.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e -x +env +if [ -f /var/lib/jenkins/pylint.django.rc ]; then + PYLINT_RC=/var/lib/jenkins/pylint.django.rc +elif [ -f pylint.django.rc ]; then + PYLINT_RC=pylint.django.rc +else + echo No pylint RC found + exit 0 +fi + +test -f pylint.out && cp pylint.out pylint.out.prev +pylint -f parseable --rcfile ${PYLINT_RC} "$@" | tee pylint.out || /bin/true +test -f pylint.out.prev && (diff pylint.out.prev pylint.out | grep '^[><]' | grep .py) || /bin/true diff --git a/setup.py b/setup.py index 7fe59c7c..953e90ee 100644 --- a/setup.py +++ b/setup.py @@ -103,7 +103,7 @@ setup( 'Programming Language :: Python', 'Programming Language :: Python :: 2', ], - install_requires=['django>=1.8, <1.9', + install_requires=['django>=1.8, <1.12', 'django-ckeditor<4.5.3', 'gadjo', 'feedparser', diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 969a4be4..934c7e1b 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -26,7 +26,6 @@ wcsctl_present = pytest.mark.skipif('WCSCTL' not in os.environ, reason='WCSCTL not defined in environment') WCSCTL = os.environ.get('WCSCTL') -WCS_MANAGE = os.path.join(os.path.dirname(WCSCTL), 'manage.py') if WCSCTL else None WCS_SCRIPTS = { 'setup-auth': """ @@ -183,10 +182,10 @@ ALLOWED_HOSTS = ['127.0.0.1', '127.0.0.2'] WCS_PID = os.fork() if not WCS_PID: - os.chdir(os.path.dirname(WCS_MANAGE)) + os.chdir(os.path.dirname(WCSCTL)) os.environ['DJANGO_SETTINGS_MODULE'] = 'wcs.settings' os.environ['WCS_SETTINGS_FILE'] = os.path.join(WCS_DIR, 'local_settings.py') - os.execvp('python', ['python', WCS_MANAGE, 'runserver', '--noreload', '0.0.0.0:8999']) + os.execvp('python', ['python', 'manage.py', 'runserver', '--noreload', '0.0.0.0:8999']) sys.exit(0) time.sleep(5) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..8ec7924f --- /dev/null +++ b/tox.ini @@ -0,0 +1,31 @@ +[tox] +envlist = coverage-{django18,django111}-pylint +toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/combo/ + +[testenv] +usedevelop = + coverage: True + nocoverage: False +setenv = + WCSCTL=wcs/wcsctl.py + DJANGO_SETTINGS_MODULE=combo.settings + COMBO_SETTINGS_FILE=tests/settings.py + coverage: COVERAGE=--junitxml=test_results.xml --cov-report xml --cov=combo/ +deps = + django18: django>=1.8,<1.9 + django111: django>=1.11,<1.12 + pytest-cov + pytest-django + pytest + pytest-capturelog + WebTest + mock + httmock + pylint<1.8 + pylint-django + django-webtest + quixote + vobject +commands = + py.test {env:COVERAGE:} {posargs:tests/} + pylint: ./pylint.sh combo/