add django 1.8 tests
This commit is contained in:
43
.travis.yml
43
.travis.yml
@@ -1,22 +1,29 @@
|
||||
language: python
|
||||
python:
|
||||
- "2.6"
|
||||
- "2.7"
|
||||
- "3.3"
|
||||
- "3.4"
|
||||
- "pypy"
|
||||
python: 3.4
|
||||
env:
|
||||
- DJANGO_VERSION=master
|
||||
- DJANGO_VERSION=1.7.x
|
||||
- DJANGO_VERSION=1.6.x
|
||||
- DJANGO_VERSION=1.5.x
|
||||
- TOX_ENV=py27-django15
|
||||
- TOX_ENV=py27-django16
|
||||
- TOX_ENV=py27-django17
|
||||
- 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:
|
||||
- pip install tox
|
||||
- pip install tox
|
||||
script:
|
||||
- tox -e "$TRAVIS_PYTHON_VERSION-$DJANGO_VERSION"
|
||||
matrix:
|
||||
exclude:
|
||||
- python: "2.6"
|
||||
env: DJANGO_VERSION=master
|
||||
- python: "2.6"
|
||||
env: DJANGO_VERSION=1.7.x
|
||||
- tox -e $TOX_ENV
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.cache/pip
|
||||
|
@@ -2,7 +2,7 @@
|
||||
from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
|
||||
from django.utils.translation.trans_real import (
|
||||
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):
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#-*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
from distutils.dist import Distribution
|
||||
from optparse import make_option
|
||||
@@ -14,16 +14,20 @@ class Command(LabelCommand):
|
||||
|
||||
option_list = LabelCommand.option_list + (
|
||||
make_option(
|
||||
'--locale', '-l',
|
||||
default=None, dest='locale', action='append',
|
||||
help='Creates or updates the message files for the given locale(s)'
|
||||
' (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('--mapping-file', '-F',
|
||||
default=None, dest='mapping_file',
|
||||
help='Mapping file')
|
||||
'--locale', '-l', default=None, dest='locale', action='append',
|
||||
help=(
|
||||
'Creates or updates the message files for the given locale(s)'
|
||||
' (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(
|
||||
'--mapping-file', '-F', default=None, dest='mapping_file',
|
||||
help='Mapping file',
|
||||
)
|
||||
)
|
||||
|
||||
def handle_label(self, command, **options):
|
||||
|
@@ -101,7 +101,7 @@ pygments_style = 'sphinx'
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# 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
|
||||
# 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,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# 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
|
||||
# .htaccess) here, relative to this directory. These files are copied
|
||||
|
16
setup.cfg
16
setup.cfg
@@ -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]
|
||||
universal = 1
|
||||
|
51
setup.py
51
setup.py
@@ -4,7 +4,6 @@ import os
|
||||
import sys
|
||||
import codecs
|
||||
from setuptools import setup, find_packages
|
||||
from setuptools.command.test import test as TestCommand
|
||||
|
||||
|
||||
def read(*parts):
|
||||
@@ -13,43 +12,12 @@ def read(*parts):
|
||||
return fp.read()
|
||||
|
||||
|
||||
test_requires = [
|
||||
'coverage',
|
||||
'pytest',
|
||||
'pytest-cov>=1.4',
|
||||
'pytest-flakes',
|
||||
'pytest-pep8',
|
||||
'python-coveralls',
|
||||
]
|
||||
|
||||
|
||||
install_requires = [
|
||||
'Django>=1.4,<1.7',
|
||||
'Django>=1.4,<1.9',
|
||||
'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(
|
||||
name='django-babel',
|
||||
description='Utilities for using Babel in Django',
|
||||
@@ -58,17 +26,14 @@ setup(
|
||||
license='BSD',
|
||||
author='Christopher Grebs',
|
||||
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',)),
|
||||
tests_require=test_requires,
|
||||
install_requires=install_requires,
|
||||
cmdclass={'test': PyTest},
|
||||
extras_require={
|
||||
'docs': ['sphinx'],
|
||||
'tox': ['tox'],
|
||||
'tests': test_requires,
|
||||
'dev': dev_requires,
|
||||
},
|
||||
install_requires=[
|
||||
'Django>=1.4,<1.8',
|
||||
'Babel>=1.3',
|
||||
],
|
||||
classifiers=[
|
||||
'Development Status :: 4 - Beta',
|
||||
'Environment :: Web Environment',
|
||||
|
13
tasks.py
13
tasks.py
@@ -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))
|
@@ -1,7 +1,8 @@
|
||||
#-*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
|
||||
from babel.messages import extract
|
||||
from babel._compat import BytesIO
|
||||
|
||||
@@ -35,7 +36,11 @@ class ExtractDjangoTestCase(unittest.TestCase):
|
||||
self.assertEqual([(1, None, u'%(anton)s', [])], messages)
|
||||
|
||||
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, [], {}))
|
||||
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)
|
||||
|
||||
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, [], {}))
|
||||
self.assertEqual([(1, None, u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ', [])], messages)
|
||||
|
||||
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, [], {}))
|
||||
self.assertEqual([(1, None, u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ', [])], messages)
|
||||
|
||||
# TODO: Yet expected to not extract the comments.
|
||||
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, [], {}))
|
||||
self.assertEqual([(1, None, u'Translatable literal #9a', [])], messages)
|
||||
self.assertEqual(
|
||||
[(1, None, u'Translatable literal #9a', [])], messages
|
||||
)
|
||||
|
||||
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, [], {}))
|
||||
self.assertEqual([(1, None, u'Translatable literal #9a', [])], messages)
|
||||
self.assertEqual(
|
||||
[(1, None, u'Translatable literal #9a', [])], messages
|
||||
)
|
||||
|
||||
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, [], {}))
|
||||
self.assertEqual([(1, None, u'Translatable literal #9h', [])], messages)
|
||||
self.assertEqual(
|
||||
[(1, None, u'Translatable literal #9h', [])], messages
|
||||
)
|
||||
|
||||
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, [], {}))
|
||||
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):
|
||||
buf = BytesIO(b'{% blocktrans %}{% other_tag %}{% endblocktrans %}')
|
||||
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 }}')
|
||||
messages = list(extract_django(buf, default_keys, [], {}))
|
||||
self.assertEqual([], messages)
|
||||
@@ -100,7 +132,7 @@ class ExtractDjangoTestCase(unittest.TestCase):
|
||||
messages = list(extract_django(buf, default_keys, [], {}))
|
||||
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") }}')
|
||||
messages = list(extract_django(buf, default_keys, [], {}))
|
||||
self.assertEqual([(1, None, u'"constant"', [])], messages)
|
||||
@@ -111,8 +143,12 @@ class ExtractDjangoTestCase(unittest.TestCase):
|
||||
self.assertEqual([(1, None, u'"constant"', [])], messages)
|
||||
|
||||
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, [], {}))
|
||||
self.assertEqual(
|
||||
[(1, None, u'"constant"', []), (1, None, u'%(foo)s', [])],
|
||||
messages)
|
||||
messages,
|
||||
)
|
||||
|
115
tox.ini
115
tox.ini
@@ -1,95 +1,26 @@
|
||||
[tox]
|
||||
envlist = {py27,py33,py34}-django{15,16,17,18,master}, py26-django{15,16}, lint, docs
|
||||
|
||||
[testenv]
|
||||
skipsdist = True
|
||||
usedevelop = True
|
||||
deps =
|
||||
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 =
|
||||
pip install -e {toxinidir}
|
||||
pip install -e {toxinidir}[tests]
|
||||
sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/_build/html
|
||||
sphinx-build -W -b linkcheck docs {envtmpdir}/_build/html
|
||||
|
||||
deps15 =
|
||||
https://github.com/django/django/archive/stable/1.5.x.zip#egg=django
|
||||
deps16 =
|
||||
https://github.com/django/django/archive/stable/1.6.x.zip#egg=django
|
||||
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
|
||||
[testenv:lint]
|
||||
deps =
|
||||
flake8==2.4.1
|
||||
commands=flake8 django_babel tests
|
||||
|
Reference in New Issue
Block a user