Permalink
Browse files

Add tox based on work by Daniel Hahler @blueyed.

Pretty awesome !
  • Loading branch information...
jpic committed Apr 22, 2015
1 parent 7631398 commit 4db600cbbe9f0590e95a7e326c046309ff434519
View
@@ -1,30 +1,94 @@
sudo: false
language: python
python:
- "2.7"
- "3.3"
matrix:
exclude:
- python: "3.3"
env: DJANGO=1.4.2
allow_failures:
- env: TOXENV=py27-djangomaster
- env: TOXENV=py34-djangomaster
python:
- "3.4"
env:
- DJANGO=1.4.2
- DJANGO=1.5
- DJANGO=1.6
- DJANGO=1.7
- DJANGO=1.8
global:
- PIP_DISABLE_PIP_VERSION_CHECK=true
matrix:
- TOXENV=py27-django14
- TOXENV=py27-django15
- TOXENV=py27-django16
- TOXENV=py27-django17
- TOXENV=py27-django18
- TOXENV=py27-djangomaster
- TOXENV=py34-django15
- TOXENV=py34-django16
- TOXENV=py34-django17
- TOXENV=py34-django18
- TOXENV=py34-djangomaster
- TOXENV=checkqa-python2
- TOXENV=checkqa
install:
- pip install -q Django==$DJANGO --use-mirrors
- pip install pep8 --use-mirrors
- pip install -q -e . --use-mirrors
# Create pip wrapper script, using travis_retry (a function) and
# inject it into tox.ini.
- mkdir -p bin
- PATH=$PWD/bin:$PATH
- PIP_INSTALL=bin/travis_pip_install
- printf '#!/bin/bash -x\n' > $PIP_INSTALL
- declare -f travis_retry >> $PIP_INSTALL
- printf '\necho "=====\nUsing pip-wrapper for \"$@\"\n=====\n" >&2\n' >> $PIP_INSTALL
# Handle "pip install -e" for usedevelop from tox.
- printf '\nif [ "$1" = "-e" ]; then pip install "$@"; exit $?; fi\n' >> $PIP_INSTALL
# First try to install from wheelhouse.
- printf 'for i in "$@"; do pip install --no-index --find-links=${PIP_WHEELHOUSE} "$i"; done\n' >> $PIP_INSTALL
# Then upgrade in case of outdated wheelhouse.
- printf 'for i in "$@"; do travis_retry pip install --upgrade "$i"; done\n' >> $PIP_INSTALL
# ..and add the new/current wheels.
- printf 'pip wheel --wheel-dir=${PIP_WHEELHOUSE} --find-links=${PIP_WHEELHOUSE} "$@"\n' >> $PIP_INSTALL
- chmod +x $PIP_INSTALL
# Adjust tox.ini.
- sed -i.bak 's/^\[testenv\]/\0\ninstall_command = travis_pip_install {opts} {packages}/' tox.ini
- diff tox.ini tox.ini.bak && { echo "tox.ini was not changed."; return 1; } || true
- sed -i.bak 's/whitelist_externals =/\0\n travis_pip_install/' tox.ini
- diff tox.ini tox.ini.bak && { echo "tox.ini was not changed."; return 1; } || true
# Inject wheel dependency into tox.ini, for travis_pip_install.
- sed -i.bak -e 's/deps =.*/\0\n wheel/' tox.ini
- diff tox.ini tox.ini.bak && { echo "tox.ini was not changed."; return 1; } || true
# Conditionally inject postgres dependency and DSM setting into tox.ini.
- if [ "$USE_POSTGRES" = 1 ]; then sed -i.bak -e 's/deps =/\0\n psycopg2/' -e 's/DJANGO_SETTINGS_MODULE=test_project.settings/\0_postgres/' tox.ini && diff tox.ini tox.ini.bak && { echo "tox.ini was not changed."; return 1; } || true; fi
- cat $PIP_INSTALL
- cat tox.ini
# Create wheels (skips existing ones from the cached wheelhouse).
- export PIP_WHEELHOUSE=$PWD/wheelhouse
- travis_pip_install tox
- if [ -n "$EXTRAREQ" ]; then travis_pip_install $EXTRAREQ; fi
- pip freeze
before_script:
- "pep8 --exclude=tests,migrations --ignore=E124,E128 rules_light"
- RUN_TESTS="tox -- rules_light"
# Run tests either with or without coverage (being installed).
- command -v coveralls && RUN_TESTS="$RUN_TESTS --cov" || true
before_install:
- npm install phantomjs
- phantomjs --version
script:
- python setup.py test
- ls -l $PWD/wheelhouse > /tmp/wheelhouse.before
- $RUN_TESTS
- ls -l $PWD/wheelhouse > /tmp/wheelhouse.after
- diff /tmp/wheelhouse.before /tmp/wheelhouse.after || true
- test -d .tox/$TOXENV/log && cat .tox/$TOXENV/log/*.log || true
after_success:
- command -v coveralls && { coveralls; return $?; } || true
notifications:
irc:
channels:
irc:
channels:
- "irc.freenode.org#yourlabs"
template:
- "%{repository} (%{commit} %{author}) : %{message} %{build_url} %{compare_url}"
# Persistent cache across builds (http://docs.travis-ci.com/user/caching/).
cache:
directories:
- $PWD/wheelhouse
before_cache:
- rm -f .tox/$TOXENV/log/*.log
View
@@ -86,6 +86,14 @@ You might want to read the `tutorial
There is also a lot of documentation, from the core to the tools, including
pointers to debug, log and test your security.
Contributing
------------
Run tests with the `tox
<https://pypi.python.org/pypi/tox>`_ command. Documented patches passing all
tests have more chances getting merged in, see `community guidelines
<http://docs.yourlabs.org>`_ for details.
Resources
---------
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
import unittest
import pytest
from django.views import generic
from django.test.client import RequestFactory
@@ -11,6 +12,7 @@
from .class_decorator_classes import *
@pytest.mark.django_db
class ClassDecoratorTestCase(unittest.TestCase):
def setUp(self):
self.request = RequestFactory().get('/')
@@ -1,11 +1,13 @@
from __future__ import unicode_literals
import pytest
import unittest
from django.test.client import Client
import rules_light
@pytest.mark.django_db
class MiddlewareTestCase(unittest.TestCase):
def setUp(self):
self.client = Client()
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
import logging
import pytest
import unittest
from mock import Mock
@@ -9,6 +10,7 @@
import rules_light
@pytest.mark.django_db
class RegistryTestCase(unittest.TestCase):
def setUp(self):
self.registry = rules_light.RuleRegistry()
@@ -1,11 +1,13 @@
from __future__ import unicode_literals
import unittest
import pytest
from django.contrib.auth.models import User
import rules_light
@pytest.mark.django_db
class ShortcutsTestCase(unittest.TestCase):
def setUp(self):
self.user, c = User.objects.get_or_create(username='foo')
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
import pytest
import unittest
from django.test.client import RequestFactory
@@ -8,6 +9,7 @@
from ..views import RegistryView
@pytest.mark.django_db
class ViewsTestCase(unittest.TestCase):
def setUp(self):
"""
View
@@ -0,0 +1,7 @@
[pep8]
ignore = E124,E128
exclude = example_apps,tests,migrations
[flake8]
ignore = E124,E128
exclude = example_apps,tests,migrations,__init__.py
@@ -0,0 +1,5 @@
# Test requirements without Django, to work around https://github.com/pypa/pip/issues/2367.
mock
cssselect
pytest
pytest-django
View
31 tox.ini
@@ -0,0 +1,31 @@
# Tox.ini by @blueyed for django-autocomplete-light
[tox]
envlist = py{27,34}-django{15,16,17,18,master}, py27-django14
[testenv]
usedevelop = true
commands = py.test --strict -r fEsxXw {posargs:rules_light}
whitelist_externals =
deps =
django14: Django>=1.4,<1.5
django15: Django>=1.5,<1.6
django16: Django>=1.6,<1.7
django17: Django>=1.7,<1.8
django18: Django>=1.8,<1.9
djangostable: Django>=1.8,<1.9
djangomaster: https://github.com/django/django/archive/master.tar.gz
-rtest_project/test_requirements_without_django.txt
setenv =
DJANGO_SETTINGS_MODULE=test_project.settings
PIP_ALLOW_EXTERNAL=true
PYTHONPATH=test_project
[testenv:checkqa]
basepython = python3.4
commands = flake8 rules_light
deps = flake8
[testenv:checkqa-python2]
basepython = python2.7
commands = flake8 rules_light
deps = flake8

5 comments on commit 4db600c

@blueyed

This comment has been minimized.

Show comment
Hide comment
@blueyed

blueyed Apr 23, 2015

Member

Yeah! :)

The changes to .travis.yml should maybe get refactored / put into a script the next time this gets re-used though.. ;)

Member

blueyed replied Apr 23, 2015

Yeah! :)

The changes to .travis.yml should maybe get refactored / put into a script the next time this gets re-used though.. ;)

@jpic

This comment has been minimized.

Show comment
Hide comment
@jpic

jpic Apr 23, 2015

Member
Member

jpic replied Apr 23, 2015

@blueyed

This comment has been minimized.

Show comment
Hide comment
@blueyed

blueyed Apr 23, 2015

Member

Yes, most of it is for tox.

Member

blueyed replied Apr 23, 2015

Yes, most of it is for tox.

@jpic

This comment has been minimized.

Show comment
Hide comment
@jpic

jpic Apr 23, 2015

Member
Member

jpic replied Apr 23, 2015

@blueyed

This comment has been minimized.

Show comment
Hide comment
@blueyed

blueyed Apr 23, 2015

Member

That would be #pylib.

Most of this is working around tox not allowing to configure it, e.g. the install_command and should be fixed there / get supported from it.
The other part is making tox's config be different based on an environment (CI/TRAVIS being set).

Not too bad after all.. ;)

Member

blueyed replied Apr 23, 2015

That would be #pylib.

Most of this is working around tox not allowing to configure it, e.g. the install_command and should be fixed there / get supported from it.
The other part is making tox's config be different based on an environment (CI/TRAVIS being set).

Not too bad after all.. ;)

Please sign in to comment.