From 618084634566d4e35f34baaae171d2f750410d0f Mon Sep 17 00:00:00 2001 From: Johannes Hoppe Date: Wed, 28 Dec 2016 19:43:59 +0100 Subject: [PATCH] Update test suite - Add tox - Add python 3.6 - Drop python 3.4 - Add chrome and gecko driver - Switch tests from memcache to redis --- .travis.yml | 59 +++++++++++--------- django_select2/conf.py | 2 + requirements_dev.in => requirements-dev.in | 6 +- requirements_dev.txt => requirements-dev.txt | 15 +++-- setup.cfg | 8 ++- tests/conftest.py | 18 +++--- tests/testapp/settings.py | 9 ++- tox.ini | 34 +++++++++++ 8 files changed, 105 insertions(+), 46 deletions(-) rename requirements_dev.in => requirements-dev.in (71%) rename requirements_dev.txt => requirements-dev.txt (68%) create mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml index 89217e9..6d5ed91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,48 +1,57 @@ language: python sudo: false +dist: trusty cache: - apt - pip services: -- memcached -python: -- '2.7' -- '3.4' -- '3.5' +- redis addons: - apt: + firefox: latest + apt: + sources: + - google-chrome packages: + - google-chrome-stable - python3-enchant - - python2-enchant + - python-enchant - graphviz +python: + - "2.7" + - "3.5" + - "3.6" env: global: - DISPLAY=:99.0 matrix: - - DJANGO="Django<1.9,>=1.8" - - DJANGO="Django<1.10,>=1.9" - - DJANGO="Django<1.11,>=1.10" - - DJANGO="https://github.com/django/django/archive/master.tar.gz#egg=django" + - TOXENV=qa + - TOXENV=docs + - DJANGO=18 + - DJANGO=19 + - DJANGO=110 + - DJANGO=master matrix: fast_finish: true allow_failures: - - env: DJANGO="https://github.com/django/django/archive/master.tar.gz#egg=django" + - env: DJANGO=master install: -- pip install --upgrade pip -- pip install -r requirements_dev.txt -- if [[ $TRAVIS_PYTHON_VERSION == 2* ]] || [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then - pip install python-memcached; fi -- if [[ $TRAVIS_PYTHON_VERSION == 3* ]] || [[ $TRAVIS_PYTHON_VERSION == pypy3 ]]; - then pip install python3-memcached; fi -- pip install $DJANGO -- pip install coveralls +- pip install --upgrade pip tox +- pip install -U coveralls - sh -e /etc/init.d/xvfb start +before_script: +- mkdir bin +- curl -O https://chromedriver.storage.googleapis.com/2.27/chromedriver_linux64.zip +- unzip chromedriver_linux64.zip -d bin +- curl -Lo geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz +- tar xzf geckodriver.tar.gz -C bin +- PATH=$PATH:$PWD/bin script: -- isort --check-only --recursive --diff . -- flake8 --jobs=2 . -- pep257 --explain --source --count django_select2 -- "(cd docs; make spelling)" -- coverage run --source=django_select2 -m py.test +- | + if [[ -z $DJANGO ]]; then + tox -e $TOXENV + else + tox -e py$(echo $TRAVIS_PYTHON_VERSION | sed -e 's/\.//g')-dj$DJANGO + fi after_success: - coveralls deploy: diff --git a/django_select2/conf.py b/django_select2/conf.py index d17ef41..cfa4e45 100644 --- a/django_select2/conf.py +++ b/django_select2/conf.py @@ -75,4 +75,6 @@ class Select2Conf(AppConf): """ class Meta: + """Prefix for all Django-Select2 settings.""" + prefix = 'SELECT2' diff --git a/requirements_dev.in b/requirements-dev.in similarity index 71% rename from requirements_dev.in rename to requirements-dev.in index 8cc821d..7ed7126 100644 --- a/requirements_dev.in +++ b/requirements-dev.in @@ -1,12 +1,14 @@ +coverage django-appconf flake8 pep8-naming mccabe isort -pep257 +pydocstyle pytest pytest-django selenium sphinx sphinxcontrib-spelling -pyenchant \ No newline at end of file +pyenchant +django-redis \ No newline at end of file diff --git a/requirements_dev.txt b/requirements-dev.txt similarity index 68% rename from requirements_dev.txt rename to requirements-dev.txt index 696eabb..8829812 100644 --- a/requirements_dev.txt +++ b/requirements-dev.txt @@ -1,28 +1,31 @@ # # This file is autogenerated by pip-compile -# Make changes in requirements_dev.in, then run this to update: +# To update, run: # -# pip-compile requirements_dev.in +# pip-compile --output-file requirements-dev.txt requirements-dev.in # alabaster==0.7.7 # via sphinx babel==2.2.0 # via sphinx +coverage==4.3 django-appconf==1.0.1 +django-redis==4.6.0 docutils==0.12 # via sphinx flake8==2.5.2 isort==4.2.2 -Jinja2==2.8 -MarkupSafe==0.23 +jinja2==2.8 # via sphinx +markupsafe==0.23 # via jinja2 mccabe==0.4.0 -pep257==0.7.0 +pydocstyle==1.1.1 pep8-naming==0.3.3 pep8==1.7.0 # via flake8 py==1.4.31 # via pytest pyenchant==1.6.6 pyflakes==1.0.0 # via flake8 -Pygments==2.1 +pygments==2.1 # via sphinx pytest-django==2.9.1 pytest==2.8.7 pytz==2015.7 # via babel +redis==2.10.5 # via django-redis selenium==2.50.1 six==1.10.0 # via django-appconf, sphinx, sphinxcontrib-spelling snowballstemmer==1.2.1 # via sphinx diff --git a/setup.cfg b/setup.cfg index 427052d..9c8befd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [pytest] -norecursedirs = env +norecursedirs = env docs addopts = --tb=short -rxs DJANGO_SETTINGS_MODULE=tests.testapp.settings @@ -8,15 +8,17 @@ max-line-length = 120 max-complexity = 10 statistics = true show-source = true -exclude = docs,runtests.py,setup.py,env +exclude = docs,runtests.py,setup.py,.tox,env [pep257] +match = (?!setup).*.py +match-dir = (?!tests|env|docs|\.).* [isort] atomic = true multi_line_output = 5 line_length = 79 -skip = manage.py,docs +skip = manage.py,docs,.tox,env known_first_party = django_select2, tests known_third_party = django combine_as_imports = true diff --git a/tests/conftest.py b/tests/conftest.py index fb85f9b..3b3008e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,14 +4,16 @@ from __future__ import absolute_import, print_function, unicode_literals import os import random import string +from time import sleep import pytest +from django.utils.encoding import force_text from selenium import webdriver from selenium.common.exceptions import WebDriverException browsers = { - # 'firefox': webdriver.Firefox, - # 'chrome': webdriver.Chrome, + 'chrome': webdriver.Chrome, + 'firefox': webdriver.Firefox, 'phantomjs': webdriver.PhantomJS, } @@ -23,8 +25,7 @@ def random_string(n): ) -@pytest.fixture(scope='session', - params=browsers.keys()) +@pytest.yield_fixture(scope='session', params=sorted(browsers.keys())) def driver(request): if 'DISPLAY' not in os.environ: pytest.skip('Test requires display server (export DISPLAY)') @@ -32,11 +33,14 @@ def driver(request): try: b = browsers[request.param]() except WebDriverException as e: - pytest.skip(e) + pytest.skip(force_text(e)) else: b.set_window_size(1200, 800) - request.addfinalizer(lambda *args: b.quit()) - return b + yield b + if request.param == 'chrome': + # chrome needs a couple of seconds before it can be quit + sleep(5) + b.quit() @pytest.fixture diff --git a/tests/testapp/settings.py b/tests/testapp/settings.py index 167c243..f3be9ac 100644 --- a/tests/testapp/settings.py +++ b/tests/testapp/settings.py @@ -47,8 +47,11 @@ USE_L10N = True if os.environ.get('TRAVIS'): CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', - 'LOCATION': 'localhost:11211', + "default": { + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": "redis://127.0.0.1:6379/1", + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient", + } } } diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..4983d80 --- /dev/null +++ b/tox.ini @@ -0,0 +1,34 @@ +[tox] +envlist = py{27,35,36}-dj{18,19,110,master},qa,docs +[testenv] +setenv= + DISPLAY=:99.0 + PYTHONPATH = {toxinidir} +deps= + -rrequirements-dev.txt + dj18: https://github.com/django/django/archive/stable/1.8.x.tar.gz#egg=django + dj19: https://github.com/django/django/archive/stable/1.9.x.tar.gz#egg=django + dj110: https://github.com/django/django/archive/stable/1.10.x.tar.gz#egg=django + djmaster: https://github.com/django/django/archive/master.tar.gz#egg=django +commands= + coverage run --source=s3file -m 'pytest' \ + --basetemp={envtmpdir} \ + --ignore=.tox \ + {posargs} + +[testenv:qa] +changedir={toxinidir} +deps= + -rrequirements-dev.txt +commands= + isort --check-only --recursive --diff {posargs} + flake8 --jobs=2 {posargs} + pydocstyle --verbose --explain --source --count {posargs} + +[testenv:docs] +whitelist_externals=make +changedir={toxinidir}/docs +deps= + -rrequirements-dev.txt + https://github.com/django/django/archive/stable/1.10.x.tar.gz#egg=django +commands=make spelling