Skip to content

Commit 0213b85

Browse files
committed
Merge pull request #8 from graingert/fix-package
add django 1.8 tests fixup package RST HTML
2 parents 4c9a9f6 + f0305d2 commit 0213b85

File tree

11 files changed

+127
-215
lines changed

11 files changed

+127
-215
lines changed

.travis.yml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
language: python
2-
python:
3-
- "2.6"
4-
- "2.7"
5-
- "3.3"
6-
- "3.4"
7-
- "pypy"
2+
python: 3.4
83
env:
9-
- DJANGO_VERSION=master
10-
- DJANGO_VERSION=1.7.x
11-
- DJANGO_VERSION=1.6.x
12-
- DJANGO_VERSION=1.5.x
4+
- TOX_ENV=py27-django15
5+
- TOX_ENV=py27-django16
6+
- TOX_ENV=py27-django17
7+
- TOX_ENV=py27-django18
8+
- TOX_ENV=py27-djangomaster
9+
- TOX_ENV=py33-django15
10+
- TOX_ENV=py33-django16
11+
- TOX_ENV=py33-django17
12+
- TOX_ENV=py33-django18
13+
- TOX_ENV=py33-djangomaster
14+
- TOX_ENV=py34-django15
15+
- TOX_ENV=py34-django16
16+
- TOX_ENV=py34-django17
17+
- TOX_ENV=py34-django18
18+
- TOX_ENV=py34-djangomaster
19+
- TOX_ENV=py26-django15
20+
- TOX_ENV=py26-django16
21+
- TOX_ENV=lint
22+
- TOX_ENV=docs
1323
install:
14-
- pip install tox
24+
- pip install tox
1525
script:
16-
- tox -e "$TRAVIS_PYTHON_VERSION-$DJANGO_VERSION"
17-
matrix:
18-
exclude:
19-
- python: "2.6"
20-
env: DJANGO_VERSION=master
21-
- python: "2.6"
22-
env: DJANGO_VERSION=1.7.x
26+
- tox -e $TOX_ENV
27+
cache:
28+
directories:
29+
- $HOME/.cache/pip

README.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ the list of ``INSTALLED_APPS`` in your settings module:
176176
...
177177
'django_babel',
178178
...
179-
)
179+
)
180180
181181
And in every template you want to use the filters, you need to explicitly load
182182
the django-babel library:
@@ -294,7 +294,6 @@ Examples:
294294
.. code-block:: django
295295
296296
{{ book.price|currencyfmt:"USD" }}
297-
```
298297
299298
would render: **$49.90**
300299

django_babel/extract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
33
from django.utils.translation.trans_real import (
44
inline_re, block_re, endblock_re, plural_re, constant_re)
5-
from django.utils.encoding import smart_unicode
5+
from django.utils.encoding import smart_text as smart_unicode
66

77

88
def extract_django(fileobj, keywords, comment_tags, options):

django_babel/management/commands/babel.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#-*- coding: utf-8 -*-
1+
# -*- coding: utf-8 -*-
22
import os
33
from distutils.dist import Distribution
44
from optparse import make_option
@@ -14,16 +14,20 @@ class Command(LabelCommand):
1414

1515
option_list = LabelCommand.option_list + (
1616
make_option(
17-
'--locale', '-l',
18-
default=None, dest='locale', action='append',
19-
help='Creates or updates the message files for the given locale(s)'
20-
' (e.g pt_BR). Can be used multiple times.'),
21-
make_option('--domain', '-d',
22-
default='django', dest='domain',
23-
help='The domain of the message files (default: "django").'),
24-
make_option('--mapping-file', '-F',
25-
default=None, dest='mapping_file',
26-
help='Mapping file')
17+
'--locale', '-l', default=None, dest='locale', action='append',
18+
help=(
19+
'Creates or updates the message files for the given locale(s)'
20+
' (e.g pt_BR). Can be used multiple times.'
21+
),
22+
),
23+
make_option(
24+
'--domain', '-d', default='django', dest='domain',
25+
help='The domain of the message files (default: "django").',
26+
),
27+
make_option(
28+
'--mapping-file', '-F', default=None, dest='mapping_file',
29+
help='Mapping file',
30+
)
2731
)
2832

2933
def handle_label(self, command, **options):

docs/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101

102102
# The theme to use for HTML and HTML Help pages. See the documentation for
103103
# a list of builtin themes.
104-
html_theme = 'default'
104+
html_theme = 'alabaster'
105105

106106
# Theme options are theme-specific and customize the look and feel of a theme
107107
# further. For a list of options available for each theme, see the
@@ -130,7 +130,6 @@
130130
# Add any paths that contain custom static files (such as style sheets) here,
131131
# relative to this directory. They are copied after the builtin static files,
132132
# so a file named "default.css" will overwrite the builtin "default.css".
133-
html_static_path = ['_static']
134133

135134
# Add any extra paths that contain custom files (such as robots.txt or
136135
# .htaccess) here, relative to this directory. These files are copied

setup.cfg

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,2 @@
1-
[pytest]
2-
addopts=-vs --pep8 --flakes
3-
timeout=5
4-
norecursedirs=.tox
5-
pep8ignore =
6-
*.py E128
7-
docs/conf.py ALL
8-
tests/*.py ALL
9-
flakes-ignore =
10-
docs/conf.py ALL
11-
tests/*.py ALL
12-
13-
[flake8]
14-
ignore = E128
15-
exclude = .tox,.git,docs/conf.py,tests/*.py
16-
171
[wheel]
182
universal = 1

setup.py

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sys
55
import codecs
66
from setuptools import setup, find_packages
7-
from setuptools.command.test import test as TestCommand
87

98

109
def read(*parts):
@@ -13,43 +12,12 @@ def read(*parts):
1312
return fp.read()
1413

1514

16-
test_requires = [
17-
'coverage',
18-
'pytest',
19-
'pytest-cov>=1.4',
20-
'pytest-flakes',
21-
'pytest-pep8',
22-
'python-coveralls',
23-
]
24-
25-
2615
install_requires = [
27-
'Django>=1.4,<1.7',
16+
'Django>=1.4,<1.9',
2817
'Babel>=1.3',
2918
]
3019

3120

32-
dev_requires = [
33-
'flake8>=2.0',
34-
'invoke',
35-
'twine'
36-
]
37-
38-
39-
class PyTest(TestCommand):
40-
41-
def finalize_options(self):
42-
TestCommand.finalize_options(self)
43-
self.test_args = []
44-
self.test_suite = True
45-
46-
def run_tests(self):
47-
# import here, cause outside the eggs aren't loaded
48-
import pytest
49-
errno = pytest.main(self.test_args)
50-
sys.exit(errno)
51-
52-
5321
setup(
5422
name='django-babel',
5523
description='Utilities for using Babel in Django',
@@ -58,17 +26,14 @@ def run_tests(self):
5826
license='BSD',
5927
author='Christopher Grebs',
6028
author_email='[email protected]',
61-
url='http://github.com/graingert/django-babel/',
29+
maintainer='Thomas Grainger',
30+
maintainer_email='[email protected]',
31+
url='https://github.com/graingert/django-babel/',
6232
packages=find_packages(exclude=('tests',)),
63-
tests_require=test_requires,
64-
install_requires=install_requires,
65-
cmdclass={'test': PyTest},
66-
extras_require={
67-
'docs': ['sphinx'],
68-
'tox': ['tox'],
69-
'tests': test_requires,
70-
'dev': dev_requires,
71-
},
33+
install_requires=[
34+
'Django>=1.4,<1.8',
35+
'Babel>=1.3',
36+
],
7237
classifiers=[
7338
'Development Status :: 4 - Beta',
7439
'Environment :: Web Environment',

tasks.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/__init__.py

Whitespace-only changes.

tests/test_extract.py

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#-*- coding: utf-8 -*-
1+
# -*- coding: utf-8 -*-
22
import unittest
33

44
import pytest
5+
56
from babel.messages import extract
67
from babel._compat import BytesIO
78

@@ -35,7 +36,11 @@ def test_extract_var(self):
3536
self.assertEqual([(1, None, u'%(anton)s', [])], messages)
3637

3738
def test_extract_filter_with_filter(self):
38-
buf = BytesIO(b'{% blocktrans with berta=anton|lower %}{{ berta }}{% endblocktrans %}')
39+
test_tmpl = (
40+
b'{% blocktrans with berta=anton|lower %}'
41+
b'{{ berta }}{% endblocktrans %}'
42+
)
43+
buf = BytesIO(test_tmpl)
3944
messages = list(extract_django(buf, default_keys, [], {}))
4045
self.assertEqual([(1, None, u'%(berta)s', [])], messages)
4146

@@ -45,42 +50,69 @@ def test_extract_with_interpolation(self):
4550
self.assertEqual([(1, None, u'xxx%(anton)sxxx', [])], messages)
4651

4752
def test_extract_unicode(self):
48-
buf = BytesIO(b'{% trans "@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ" %}')
53+
buf = BytesIO(u'{% trans "@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ" %}'.encode('utf8'))
4954
messages = list(extract_django(buf, default_keys, [], {}))
5055
self.assertEqual([(1, None, u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ', [])], messages)
5156

5257
def test_extract_unicode_blocktrans(self):
53-
buf = BytesIO(b'{% blocktrans %}@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ{% endblocktrans %}')
58+
test_tmpl = u'{% blocktrans %}@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ{% endblocktrans %}'
59+
buf = BytesIO(test_tmpl.encode('utf8'))
5460
messages = list(extract_django(buf, default_keys, [], {}))
5561
self.assertEqual([(1, None, u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ', [])], messages)
5662

5763
# TODO: Yet expected to not extract the comments.
5864
def test_extract_ignored_comment(self):
59-
buf = BytesIO(b'{# ignored comment #1 #}{% trans "Translatable literal #9a" %}')
65+
buf = BytesIO(
66+
b'{# ignored comment #1 #}{% trans "Translatable literal #9a" %}',
67+
)
6068
messages = list(extract_django(buf, default_keys, [], {}))
61-
self.assertEqual([(1, None, u'Translatable literal #9a', [])], messages)
69+
self.assertEqual(
70+
[(1, None, u'Translatable literal #9a', [])], messages
71+
)
6272

6373
def test_extract_ignored_comment2(self):
64-
buf = BytesIO(b'{# Translators: ignored i18n comment #1 #}{% trans "Translatable literal #9a" %}')
74+
test_tmpl = (
75+
b'{# Translators: ignored i18n comment #1 #}'
76+
b'{% trans "Translatable literal #9a" %}'
77+
)
78+
buf = BytesIO(test_tmpl)
6579
messages = list(extract_django(buf, default_keys, [], {}))
66-
self.assertEqual([(1, None, u'Translatable literal #9a', [])], messages)
80+
self.assertEqual(
81+
[(1, None, u'Translatable literal #9a', [])], messages
82+
)
6783

6884
def test_extract_valid_comment(self):
69-
buf = BytesIO(b'{# ignored comment #6 #}{% trans "Translatable literal #9h" %}{# Translators: valid i18n comment #7 #}')
85+
test_tmpl = (
86+
b'{# ignored comment #6 #}'
87+
b'{% trans "Translatable literal #9h" %}'
88+
b'{# Translators: valid i18n comment #7 #}'
89+
)
90+
buf = BytesIO(test_tmpl)
7091
messages = list(extract_django(buf, default_keys, [], {}))
71-
self.assertEqual([(1, None, u'Translatable literal #9h', [])], messages)
92+
self.assertEqual(
93+
[(1, None, u'Translatable literal #9h', [])], messages
94+
)
7295

7396
def test_extract_singular_form(self):
74-
buf = BytesIO(b'{% blocktrans count counter=number %}singular{% plural %}{{ counter }} plural{% endblocktrans %}')
97+
test_tmpl = (
98+
b'{% blocktrans count counter=number %}'
99+
b'singular{% plural %}{{ counter }} plural'
100+
b'{% endblocktrans %}'
101+
)
102+
buf = BytesIO(test_tmpl)
75103
messages = list(extract_django(buf, default_keys, [], {}))
76-
self.assertEqual([(1, 'ngettext', (u'singular', u'%(counter)s plural'), [])], messages)
104+
self.assertEqual(
105+
[(1, 'ngettext', (u'singular', u'%(counter)s plural'), [])],
106+
messages
107+
)
77108

78109
def test_trans_blocks_must_not_include_other_block_tags(self):
79110
buf = BytesIO(b'{% blocktrans %}{% other_tag %}{% endblocktrans %}')
80111
gen = extract_django(buf, default_keys, [], {})
81-
pytest.raises(SyntaxError, gen.next)
112+
with pytest.raises(SyntaxError):
113+
next(gen)
82114

83-
def test_extract_var(self):
115+
def test_extract_var_other(self):
84116
buf = BytesIO(b'{{ book }}')
85117
messages = list(extract_django(buf, default_keys, [], {}))
86118
self.assertEqual([], messages)
@@ -100,7 +132,7 @@ def test_extract_constant_single_quotes(self):
100132
messages = list(extract_django(buf, default_keys, [], {}))
101133
self.assertEqual([(1, None, u"'constant'", [])], messages)
102134

103-
def test_extract_constant_single_quotes(self):
135+
def test_extract_constant_double_quotes(self):
104136
buf = BytesIO(b'{{ _("constant") }}')
105137
messages = list(extract_django(buf, default_keys, [], {}))
106138
self.assertEqual([(1, None, u'"constant"', [])], messages)
@@ -111,8 +143,12 @@ def test_extract_constant_block(self):
111143
self.assertEqual([(1, None, u'"constant"', [])], messages)
112144

113145
def test_extract_constant_in_block(self):
114-
buf = BytesIO(b'{% blocktrans foo=_("constant") %}{{ foo }}{% endblocktrans %}')
146+
test_tmpl = (
147+
b'{% blocktrans foo=_("constant") %}{{ foo }}{% endblocktrans %}'
148+
)
149+
buf = BytesIO(test_tmpl)
115150
messages = list(extract_django(buf, default_keys, [], {}))
116151
self.assertEqual(
117152
[(1, None, u'"constant"', []), (1, None, u'%(foo)s', [])],
118-
messages)
153+
messages,
154+
)

0 commit comments

Comments
 (0)