summaryrefslogtreecommitdiff
path: root/test/ext
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-05-29 18:18:04 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-05-31 14:03:02 -0400
commitfb7f0437323ba836c68947d38f3604c3336e3a9b (patch)
tree756512a2b68f1c7270f028b487228fd0e3f13778 /test/ext
parentdb498f217e03d772e0c0c37a526226d48ed790e2 (diff)
downloadmako-fb7f0437323ba836c68947d38f3604c3336e3a9b.tar.gz
Use tox / zimports
Change-Id: Ia047c7052a6d242c2cf1c7a83981f1e38ea4d928
Diffstat (limited to 'test/ext')
-rw-r--r--test/ext/test_babelplugin.py127
-rw-r--r--test/ext/test_linguaplugin.py61
2 files changed, 111 insertions, 77 deletions
diff --git a/test/ext/test_babelplugin.py b/test/ext/test_babelplugin.py
index 3658c50..5f25a6a 100644
--- a/test/ext/test_babelplugin.py
+++ b/test/ext/test_babelplugin.py
@@ -1,93 +1,120 @@
import io
import os
import unittest
-from .. import TemplateTest, template_base, skip_if
+
from mako import compat
+from .. import skip_if
+from .. import template_base
+from .. import TemplateTest
try:
import babel.messages.extract as babel
from mako.ext.babelplugin import extract
-
+
except ImportError:
babel = None
def skip():
return skip_if(
- lambda: not babel,
- 'babel not installed: skipping babelplugin test')
+ lambda: not babel, "babel not installed: skipping babelplugin test"
+ )
class Test_extract(unittest.TestCase):
@skip()
def test_parse_python_expression(self):
- input = io.BytesIO(compat.b('<p>${_("Message")}</p>'))
- messages = list(extract(input, ['_'], [], {}))
- self.assertEqual(messages, [(1, '_', compat.u('Message'), [])])
+ input_ = io.BytesIO(compat.b('<p>${_("Message")}</p>'))
+ messages = list(extract(input_, ["_"], [], {}))
+ self.assertEqual(messages, [(1, "_", compat.u("Message"), [])])
@skip()
def test_python_gettext_call(self):
- input = io.BytesIO(compat.b('<p>${_("Message")}</p>'))
- messages = list(extract(input, ['_'], [], {}))
- self.assertEqual(messages, [(1, '_', compat.u('Message'), [])])
+ input_ = io.BytesIO(compat.b('<p>${_("Message")}</p>'))
+ messages = list(extract(input_, ["_"], [], {}))
+ self.assertEqual(messages, [(1, "_", compat.u("Message"), [])])
@skip()
def test_translator_comment(self):
- input = io.BytesIO(compat.b('''
+ input_ = io.BytesIO(
+ compat.b(
+ """
<p>
## TRANSLATORS: This is a comment.
${_("Message")}
- </p>'''))
- messages = list(extract(input, ['_'], ['TRANSLATORS:'], {}))
+ </p>"""
+ )
+ )
+ messages = list(extract(input_, ["_"], ["TRANSLATORS:"], {}))
self.assertEqual(
messages,
- [(4, '_', compat.u('Message'),
- [compat.u('TRANSLATORS: This is a comment.')])])
+ [
+ (
+ 4,
+ "_",
+ compat.u("Message"),
+ [compat.u("TRANSLATORS: This is a comment.")],
+ )
+ ],
+ )
class ExtractMakoTestCase(TemplateTest):
@skip()
def test_extract(self):
- mako_tmpl = open(os.path.join(template_base, 'gettext.mako'))
- messages = list(extract(mako_tmpl, {'_': None, 'gettext': None,
- 'ungettext': (1, 2)},
- ['TRANSLATOR:'], {}))
- expected = \
- [(1, '_', 'Page arg 1', []),
- (1, '_', 'Page arg 2', []),
- (10, 'gettext', 'Begin', []),
- (14, '_', 'Hi there!', ['TRANSLATOR: Hi there!']),
- (19, '_', 'Hello', []),
- (22, '_', 'Welcome', []),
- (25, '_', 'Yo', []),
- (36, '_', 'The', ['TRANSLATOR: Ensure so and', 'so, thanks']),
- (36, 'ungettext', ('bunny', 'bunnies', None), []),
- (41, '_', 'Goodbye', ['TRANSLATOR: Good bye']),
- (44, '_', 'Babel', []),
- (45, 'ungettext', ('hella', 'hellas', None), []),
- (62, '_', 'The', ['TRANSLATOR: Ensure so and', 'so, thanks']),
- (62, 'ungettext', ('bunny', 'bunnies', None), []),
- (68, '_', 'Goodbye, really!', ['TRANSLATOR: HTML comment']),
- (71, '_', 'P.S. byebye', []),
- (77, '_', 'Top', []),
- (83, '_', 'foo', []),
- (83, '_', 'hoho', []),
- (85, '_', 'bar', []),
- (92, '_', 'Inside a p tag', ['TRANSLATOR: <p> tag is ok?']),
- (95, '_', 'Later in a p tag', ['TRANSLATOR: also this']),
- (99, '_', 'No action at a distance.', []),
- ]
+ mako_tmpl = open(os.path.join(template_base, "gettext.mako"))
+ messages = list(
+ extract(
+ mako_tmpl,
+ {"_": None, "gettext": None, "ungettext": (1, 2)},
+ ["TRANSLATOR:"],
+ {},
+ )
+ )
+ expected = [
+ (1, "_", "Page arg 1", []),
+ (1, "_", "Page arg 2", []),
+ (10, "gettext", "Begin", []),
+ (14, "_", "Hi there!", ["TRANSLATOR: Hi there!"]),
+ (19, "_", "Hello", []),
+ (22, "_", "Welcome", []),
+ (25, "_", "Yo", []),
+ (36, "_", "The", ["TRANSLATOR: Ensure so and", "so, thanks"]),
+ (36, "ungettext", ("bunny", "bunnies", None), []),
+ (41, "_", "Goodbye", ["TRANSLATOR: Good bye"]),
+ (44, "_", "Babel", []),
+ (45, "ungettext", ("hella", "hellas", None), []),
+ (62, "_", "The", ["TRANSLATOR: Ensure so and", "so, thanks"]),
+ (62, "ungettext", ("bunny", "bunnies", None), []),
+ (68, "_", "Goodbye, really!", ["TRANSLATOR: HTML comment"]),
+ (71, "_", "P.S. byebye", []),
+ (77, "_", "Top", []),
+ (83, "_", "foo", []),
+ (83, "_", "hoho", []),
+ (85, "_", "bar", []),
+ (92, "_", "Inside a p tag", ["TRANSLATOR: <p> tag is ok?"]),
+ (95, "_", "Later in a p tag", ["TRANSLATOR: also this"]),
+ (99, "_", "No action at a distance.", []),
+ ]
self.assertEqual(expected, messages)
@skip()
def test_extract_utf8(self):
- mako_tmpl = open(os.path.join(template_base, 'gettext_utf8.mako'), 'rb')
- message = next(extract(mako_tmpl, set(['_', None]), [], {'encoding': 'utf-8'}))
- assert message == (1, '_', u'K\xf6ln', [])
+ mako_tmpl = open(
+ os.path.join(template_base, "gettext_utf8.mako"), "rb"
+ )
+ message = next(
+ extract(mako_tmpl, set(["_", None]), [], {"encoding": "utf-8"})
+ )
+ assert message == (1, "_", u"K\xf6ln", [])
@skip()
def test_extract_cp1251(self):
- mako_tmpl = open(os.path.join(template_base, 'gettext_cp1251.mako'), 'rb')
- message = next(extract(mako_tmpl, set(['_', None]), [], {'encoding': 'cp1251'}))
+ mako_tmpl = open(
+ os.path.join(template_base, "gettext_cp1251.mako"), "rb"
+ )
+ message = next(
+ extract(mako_tmpl, set(["_", None]), [], {"encoding": "cp1251"})
+ )
# "test" in Rusian. File encoding is cp1251 (aka "windows-1251")
- assert message == (1, '_', u'\u0442\u0435\u0441\u0442', [])
+ assert message == (1, "_", u"\u0442\u0435\u0441\u0442", [])
diff --git a/test/ext/test_linguaplugin.py b/test/ext/test_linguaplugin.py
index 9c46271..a563969 100644
--- a/test/ext/test_linguaplugin.py
+++ b/test/ext/test_linguaplugin.py
@@ -1,5 +1,8 @@
import os
-from .. import TemplateTest, template_base, skip_if
+
+from .. import skip_if
+from .. import template_base
+from .. import TemplateTest
try:
import lingua
@@ -18,40 +21,44 @@ class MockOptions:
def skip():
return skip_if(
- lambda: not lingua, 'lingua not installed: skipping linguaplugin test')
+ lambda: not lingua, "lingua not installed: skipping linguaplugin test"
+ )
class ExtractMakoTestCase(TemplateTest):
@skip()
def test_extract(self):
register_extractors()
- plugin = LinguaMakoExtractor({'comment-tags': 'TRANSLATOR'})
+ plugin = LinguaMakoExtractor({"comment-tags": "TRANSLATOR"})
messages = list(
- plugin(os.path.join(template_base, 'gettext.mako'), MockOptions()))
+ plugin(os.path.join(template_base, "gettext.mako"), MockOptions())
+ )
msgids = [(m.msgid, m.msgid_plural) for m in messages]
self.assertEqual(
msgids,
[
- ('Page arg 1', None),
- ('Page arg 2', None),
- ('Begin', None),
- ('Hi there!', None),
- ('Hello', None),
- ('Welcome', None),
- ('Yo', None),
- ('The', None),
- ('bunny', 'bunnies'),
- ('Goodbye', None),
- ('Babel', None),
- ('hella', 'hellas'),
- ('The', None),
- ('bunny', 'bunnies'),
- ('Goodbye, really!', None),
- ('P.S. byebye', None),
- ('Top', None),
- (u'foo', None),
- ('hoho', None),
- (u'bar', None),
- ('Inside a p tag', None),
- ('Later in a p tag', None),
- ('No action at a distance.', None)])
+ ("Page arg 1", None),
+ ("Page arg 2", None),
+ ("Begin", None),
+ ("Hi there!", None),
+ ("Hello", None),
+ ("Welcome", None),
+ ("Yo", None),
+ ("The", None),
+ ("bunny", "bunnies"),
+ ("Goodbye", None),
+ ("Babel", None),
+ ("hella", "hellas"),
+ ("The", None),
+ ("bunny", "bunnies"),
+ ("Goodbye, really!", None),
+ ("P.S. byebye", None),
+ ("Top", None),
+ (u"foo", None),
+ ("hoho", None),
+ (u"bar", None),
+ ("Inside a p tag", None),
+ ("Later in a p tag", None),
+ ("No action at a distance.", None),
+ ],
+ )