add django 1.8 tests

This commit is contained in:
Thomas Grainger
2015-09-21 11:26:34 +01:00
parent d6114b676d
commit f0305d2b93
10 changed files with 126 additions and 213 deletions

View File

@@ -1,22 +1,29 @@
language: python language: python
python: python: 3.4
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "pypy"
env: env:
- DJANGO_VERSION=master - TOX_ENV=py27-django15
- DJANGO_VERSION=1.7.x - TOX_ENV=py27-django16
- DJANGO_VERSION=1.6.x - TOX_ENV=py27-django17
- DJANGO_VERSION=1.5.x - TOX_ENV=py27-django18
- TOX_ENV=py27-djangomaster
- TOX_ENV=py33-django15
- TOX_ENV=py33-django16
- TOX_ENV=py33-django17
- TOX_ENV=py33-django18
- TOX_ENV=py33-djangomaster
- TOX_ENV=py34-django15
- TOX_ENV=py34-django16
- TOX_ENV=py34-django17
- TOX_ENV=py34-django18
- TOX_ENV=py34-djangomaster
- TOX_ENV=py26-django15
- TOX_ENV=py26-django16
- TOX_ENV=lint
- TOX_ENV=docs
install: install:
- pip install tox - pip install tox
script: script:
- tox -e "$TRAVIS_PYTHON_VERSION-$DJANGO_VERSION" - tox -e $TOX_ENV
matrix: cache:
exclude: directories:
- python: "2.6" - $HOME/.cache/pip
env: DJANGO_VERSION=master
- python: "2.6"
env: DJANGO_VERSION=1.7.x

View File

@@ -2,7 +2,7 @@
from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
from django.utils.translation.trans_real import ( from django.utils.translation.trans_real import (
inline_re, block_re, endblock_re, plural_re, constant_re) inline_re, block_re, endblock_re, plural_re, constant_re)
from django.utils.encoding import smart_unicode from django.utils.encoding import smart_text as smart_unicode
def extract_django(fileobj, keywords, comment_tags, options): def extract_django(fileobj, keywords, comment_tags, options):

View File

@@ -1,4 +1,4 @@
#-*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
from distutils.dist import Distribution from distutils.dist import Distribution
from optparse import make_option from optparse import make_option
@@ -14,16 +14,20 @@ class Command(LabelCommand):
option_list = LabelCommand.option_list + ( option_list = LabelCommand.option_list + (
make_option( make_option(
'--locale', '-l', '--locale', '-l', default=None, dest='locale', action='append',
default=None, dest='locale', action='append', help=(
help='Creates or updates the message files for the given locale(s)' 'Creates or updates the message files for the given locale(s)'
' (e.g pt_BR). Can be used multiple times.'), ' (e.g pt_BR). Can be used multiple times.'
make_option('--domain', '-d', ),
default='django', dest='domain', ),
help='The domain of the message files (default: "django").'), make_option(
make_option('--mapping-file', '-F', '--domain', '-d', default='django', dest='domain',
default=None, dest='mapping_file', help='The domain of the message files (default: "django").',
help='Mapping file') ),
make_option(
'--mapping-file', '-F', default=None, dest='mapping_file',
help='Mapping file',
)
) )
def handle_label(self, command, **options): def handle_label(self, command, **options):

View File

@@ -101,7 +101,7 @@ pygments_style = 'sphinx'
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
html_theme = 'default' html_theme = 'alabaster'
# Theme options are theme-specific and customize the look and feel of a theme # Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the # further. For a list of options available for each theme, see the
@@ -130,7 +130,6 @@ html_theme = 'default'
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Add any extra paths that contain custom files (such as robots.txt or # Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied # .htaccess) here, relative to this directory. These files are copied

View File

@@ -1,18 +1,2 @@
[pytest]
addopts=-vs --pep8 --flakes
timeout=5
norecursedirs=.tox
pep8ignore =
*.py E128
docs/conf.py ALL
tests/*.py ALL
flakes-ignore =
docs/conf.py ALL
tests/*.py ALL
[flake8]
ignore = E128
exclude = .tox,.git,docs/conf.py,tests/*.py
[wheel] [wheel]
universal = 1 universal = 1

View File

@@ -4,7 +4,6 @@ import os
import sys import sys
import codecs import codecs
from setuptools import setup, find_packages from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
def read(*parts): def read(*parts):
@@ -13,43 +12,12 @@ def read(*parts):
return fp.read() return fp.read()
test_requires = [
'coverage',
'pytest',
'pytest-cov>=1.4',
'pytest-flakes',
'pytest-pep8',
'python-coveralls',
]
install_requires = [ install_requires = [
'Django>=1.4,<1.7', 'Django>=1.4,<1.9',
'Babel>=1.3', 'Babel>=1.3',
] ]
dev_requires = [
'flake8>=2.0',
'invoke',
'twine'
]
class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)
setup( setup(
name='django-babel', name='django-babel',
description='Utilities for using Babel in Django', description='Utilities for using Babel in Django',
@@ -58,17 +26,14 @@ setup(
license='BSD', license='BSD',
author='Christopher Grebs', author='Christopher Grebs',
author_email='cg@webshox.org', author_email='cg@webshox.org',
url='http://github.com/graingert/django-babel/', maintainer='Thomas Grainger',
maintainer_email='django-babel@graingert.co.uk',
url='https://github.com/graingert/django-babel/',
packages=find_packages(exclude=('tests',)), packages=find_packages(exclude=('tests',)),
tests_require=test_requires, install_requires=[
install_requires=install_requires, 'Django>=1.4,<1.8',
cmdclass={'test': PyTest}, 'Babel>=1.3',
extras_require={ ],
'docs': ['sphinx'],
'tox': ['tox'],
'tests': test_requires,
'dev': dev_requires,
},
classifiers=[ classifiers=[
'Development Status :: 4 - Beta', 'Development Status :: 4 - Beta',
'Environment :: Web Environment', 'Environment :: Web Environment',

View File

@@ -1,13 +0,0 @@
import invoke
@invoke.task
def release(version):
"""`version`` should be a string like '0.4' or '1.0'."""
invoke.run('git tag -s {0}'.format(version))
invoke.run('git push --tags')
invoke.run('python setup.py sdist')
invoke.run('python setup.py bdist_wheel')
invoke.run('twine upload -s dist/django*babel{0}* '.format(version))

View File

View File

@@ -1,7 +1,8 @@
#-*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unittest import unittest
import pytest import pytest
from babel.messages import extract from babel.messages import extract
from babel._compat import BytesIO from babel._compat import BytesIO
@@ -35,7 +36,11 @@ class ExtractDjangoTestCase(unittest.TestCase):
self.assertEqual([(1, None, u'%(anton)s', [])], messages) self.assertEqual([(1, None, u'%(anton)s', [])], messages)
def test_extract_filter_with_filter(self): def test_extract_filter_with_filter(self):
buf = BytesIO(b'{% blocktrans with berta=anton|lower %}{{ berta }}{% endblocktrans %}') test_tmpl = (
b'{% blocktrans with berta=anton|lower %}'
b'{{ berta }}{% endblocktrans %}'
)
buf = BytesIO(test_tmpl)
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([(1, None, u'%(berta)s', [])], messages) self.assertEqual([(1, None, u'%(berta)s', [])], messages)
@@ -45,42 +50,69 @@ class ExtractDjangoTestCase(unittest.TestCase):
self.assertEqual([(1, None, u'xxx%(anton)sxxx', [])], messages) self.assertEqual([(1, None, u'xxx%(anton)sxxx', [])], messages)
def test_extract_unicode(self): def test_extract_unicode(self):
buf = BytesIO(b'{% trans "@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ" %}') buf = BytesIO(u'{% trans "@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ" %}'.encode('utf8'))
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([(1, None, u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ', [])], messages) self.assertEqual([(1, None, u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ', [])], messages)
def test_extract_unicode_blocktrans(self): def test_extract_unicode_blocktrans(self):
buf = BytesIO(b'{% blocktrans %}@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ{% endblocktrans %}') test_tmpl = u'{% blocktrans %}@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ{% endblocktrans %}'
buf = BytesIO(test_tmpl.encode('utf8'))
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([(1, None, u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ', [])], messages) self.assertEqual([(1, None, u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ', [])], messages)
# TODO: Yet expected to not extract the comments. # TODO: Yet expected to not extract the comments.
def test_extract_ignored_comment(self): def test_extract_ignored_comment(self):
buf = BytesIO(b'{# ignored comment #1 #}{% trans "Translatable literal #9a" %}') buf = BytesIO(
b'{# ignored comment #1 #}{% trans "Translatable literal #9a" %}',
)
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([(1, None, u'Translatable literal #9a', [])], messages) self.assertEqual(
[(1, None, u'Translatable literal #9a', [])], messages
)
def test_extract_ignored_comment2(self): def test_extract_ignored_comment2(self):
buf = BytesIO(b'{# Translators: ignored i18n comment #1 #}{% trans "Translatable literal #9a" %}') test_tmpl = (
b'{# Translators: ignored i18n comment #1 #}'
b'{% trans "Translatable literal #9a" %}'
)
buf = BytesIO(test_tmpl)
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([(1, None, u'Translatable literal #9a', [])], messages) self.assertEqual(
[(1, None, u'Translatable literal #9a', [])], messages
)
def test_extract_valid_comment(self): def test_extract_valid_comment(self):
buf = BytesIO(b'{# ignored comment #6 #}{% trans "Translatable literal #9h" %}{# Translators: valid i18n comment #7 #}') test_tmpl = (
b'{# ignored comment #6 #}'
b'{% trans "Translatable literal #9h" %}'
b'{# Translators: valid i18n comment #7 #}'
)
buf = BytesIO(test_tmpl)
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([(1, None, u'Translatable literal #9h', [])], messages) self.assertEqual(
[(1, None, u'Translatable literal #9h', [])], messages
)
def test_extract_singular_form(self): def test_extract_singular_form(self):
buf = BytesIO(b'{% blocktrans count counter=number %}singular{% plural %}{{ counter }} plural{% endblocktrans %}') test_tmpl = (
b'{% blocktrans count counter=number %}'
b'singular{% plural %}{{ counter }} plural'
b'{% endblocktrans %}'
)
buf = BytesIO(test_tmpl)
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([(1, 'ngettext', (u'singular', u'%(counter)s plural'), [])], messages) self.assertEqual(
[(1, 'ngettext', (u'singular', u'%(counter)s plural'), [])],
messages
)
def test_trans_blocks_must_not_include_other_block_tags(self): def test_trans_blocks_must_not_include_other_block_tags(self):
buf = BytesIO(b'{% blocktrans %}{% other_tag %}{% endblocktrans %}') buf = BytesIO(b'{% blocktrans %}{% other_tag %}{% endblocktrans %}')
gen = extract_django(buf, default_keys, [], {}) gen = extract_django(buf, default_keys, [], {})
pytest.raises(SyntaxError, gen.next) with pytest.raises(SyntaxError):
next(gen)
def test_extract_var(self): def test_extract_var_other(self):
buf = BytesIO(b'{{ book }}') buf = BytesIO(b'{{ book }}')
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([], messages) self.assertEqual([], messages)
@@ -100,7 +132,7 @@ class ExtractDjangoTestCase(unittest.TestCase):
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([(1, None, u"'constant'", [])], messages) self.assertEqual([(1, None, u"'constant'", [])], messages)
def test_extract_constant_single_quotes(self): def test_extract_constant_double_quotes(self):
buf = BytesIO(b'{{ _("constant") }}') buf = BytesIO(b'{{ _("constant") }}')
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual([(1, None, u'"constant"', [])], messages) self.assertEqual([(1, None, u'"constant"', [])], messages)
@@ -111,8 +143,12 @@ class ExtractDjangoTestCase(unittest.TestCase):
self.assertEqual([(1, None, u'"constant"', [])], messages) self.assertEqual([(1, None, u'"constant"', [])], messages)
def test_extract_constant_in_block(self): def test_extract_constant_in_block(self):
buf = BytesIO(b'{% blocktrans foo=_("constant") %}{{ foo }}{% endblocktrans %}') test_tmpl = (
b'{% blocktrans foo=_("constant") %}{{ foo }}{% endblocktrans %}'
)
buf = BytesIO(test_tmpl)
messages = list(extract_django(buf, default_keys, [], {})) messages = list(extract_django(buf, default_keys, [], {}))
self.assertEqual( self.assertEqual(
[(1, None, u'"constant"', []), (1, None, u'%(foo)s', [])], [(1, None, u'"constant"', []), (1, None, u'%(foo)s', [])],
messages) messages,
)

115
tox.ini
View File

@@ -1,95 +1,26 @@
[tox]
envlist = {py27,py33,py34}-django{15,16,17,18,master}, py26-django{15,16}, lint, docs
[testenv] [testenv]
skipsdist = True deps =
usedevelop = True coverage
pytest
pytest-cov
python-coveralls
django15: Django>=1.5,<1.6
django16: Django>=1.6,<1.7
django17: Django>=1.7,<1.8
django18: Django>=1.8,<1.9
djangomaster: https://github.com/django/django/archive/master.tar.gz#egg=Django
commands = py.test {posargs}
[testenv:docs]
deps = sphinx
commands = commands =
pip install -e {toxinidir} sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/_build/html
pip install -e {toxinidir}[tests] sphinx-build -W -b linkcheck docs {envtmpdir}/_build/html
deps15 = [testenv:lint]
https://github.com/django/django/archive/stable/1.5.x.zip#egg=django deps =
deps16 = flake8==2.4.1
https://github.com/django/django/archive/stable/1.6.x.zip#egg=django commands=flake8 django_babel tests
deps17 =
https://github.com/django/django/archive/stable/1.7.x.zip#egg=django
master =
https://github.com/django/django/archive/stable/1.7.x.zip#egg=django
[testenv:2.6-1.5.x]
basepython = python2.6
deps = {[testenv]deps15}
[testenv:2.6-1.6.x]
basepython = python2.6
deps = {[testenv]deps16}
[testenv:2.7-1.5.x]
basepython = python2.7
deps = {[testenv]deps15}
[testenv:2.7-1.6.x]
basepython = python2.7
deps = {[testenv]deps16}
[testenv:2.7-1.7.x]
basepython = python2.7
deps = {[testenv]deps17}
[testenv:2.7-master]
basepython = python2.7
deps = {[testenv]master}
[testenv:3.3-1.5.x]
basepython = python3.3
deps = {[testenv]deps15}
[testenv:3.3-1.6.x]
basepython = python3.3
deps = {[testenv]deps16}
[testenv:3.3-1.7.x]
basepython = python3.3
deps = {[testenv]deps17}
[testenv:3.3-master]
basepython = python3.3
deps = {[testenv]master}
[testenv:3.4-1.5.x]
basepython = python3.4
deps = {[testenv]deps15}
[testenv:3.4-1.6.x]
basepython = python3.4
deps = {[testenv]deps16}
[testenv:3.4-1.7.x]
basepython = python3.4
deps = {[testenv]deps17}
[testenv:3.4-master]
basepython = python3.4
deps = {[testenv]master}
[testenv:pypy-1.5.x]
basepython = pypy
deps = {[testenv]deps17}
[testenv:pypy-1.6.x]
basepython = pypy
deps = {[testenv]deps17}
[testenv:pypy-1.7.x]
basepython = pypy
deps = {[testenv]deps17}
[testenv:pypy-master]
basepython = pypy
deps = {[testenv]master}
[docs]
commands =
pip install -e {toxinidir}
pip install -e {toxinidir}[docs]
sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/_build/html
sphinx-build -W -b doctest -d {envtmpdir}/doctrees docs docs/_build/html
sphinx-build -W -b linkcheck docs docs/_build/html