aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWichert Akkerman <wichert@wiggy.net>2014-08-25 21:50:26 +0200
committerWichert Akkerman <wichert@wiggy.net>2014-08-25 21:50:26 +0200
commit53b6202319639c7264fd5de76f77e51d18cf94b2 (patch)
tree3426349401e7f43ec6065c5e8299bc48bd1cd9f0
parent285bc818a50ccc0f9549630f7c4f4c250585c3e7 (diff)
downloadexternal_python_mako-53b6202319639c7264fd5de76f77e51d18cf94b2.tar.gz
external_python_mako-53b6202319639c7264fd5de76f77e51d18cf94b2.tar.bz2
external_python_mako-53b6202319639c7264fd5de76f77e51d18cf94b2.zip
Add tests for Babel plugin
-rw-r--r--setup.py2
-rw-r--r--test/ext/__init__.py0
-rw-r--r--test/ext/test_babelplugin.py48
3 files changed, 49 insertions, 1 deletions
diff --git a/setup.py b/setup.py
index 0094901..a62a301 100644
--- a/setup.py
+++ b/setup.py
@@ -47,7 +47,7 @@ setup(name='Mako',
url='http://www.makotemplates.org/',
license='MIT',
packages=find_packages('.', exclude=['examples*', 'test*']),
- tests_require=['nose >= 0.11', 'mock'],
+ tests_require=['nose >= 0.11', 'mock', 'Babel'],
test_suite="nose.collector",
zip_safe=False,
install_requires=install_requires,
diff --git a/test/ext/__init__.py b/test/ext/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/ext/__init__.py
diff --git a/test/ext/test_babelplugin.py b/test/ext/test_babelplugin.py
new file mode 100644
index 0000000..e4b78d2
--- /dev/null
+++ b/test/ext/test_babelplugin.py
@@ -0,0 +1,48 @@
+import io
+import mock
+import unittest
+from mako.ext.babelplugin import _split_comment
+from mako.ext.babelplugin import extract
+from mako.ext.babelplugin import extract_nodes
+
+
+class Test_extract(unittest.TestCase):
+ def test_parse_and_invoke_extract_nodes(self):
+ input = io.BytesIO(b'<p>Hello world</p>')
+ with mock.patch('mako.ext.babelplugin.extract_nodes') as extract_nodes:
+ list(extract(input, [], [], {}))
+ extract_nodes.assert_called_once_with([mock.ANY], [], [], {})
+ self.assertEqual(
+ extract_nodes.mock_calls[0][1][0][0].content,
+ u'<p>Hello world</p>')
+
+ def test_parse_python_expression(self):
+ input = io.BytesIO(b'<p>${_("Message")}</p>')
+ messages = list(extract(input, ['_'], [], {}))
+ self.assertEqual(messages, [(1, '_', u'Message', [])])
+
+ def test_python_gettext_call(self):
+ input = io.BytesIO(b'<p>${_("Message")}</p>')
+ messages = list(extract(input, ['_'], [], {}))
+ self.assertEqual(messages, [(1, '_', u'Message', [])])
+
+ def test_translator_comment(self):
+ input = io.BytesIO(b'''
+ <p>
+ ## TRANSLATORS: This is a comment.
+ ${_("Message")}
+ </p>''')
+ messages = list(extract(input, ['_'], ['TRANSLATORS:'], {}))
+ self.assertEqual(
+ messages,
+ [(4, '_', u'Message', [u'TRANSLATORS: This is a comment.'])])
+
+
+class Test_split_comment(unittest.TestCase):
+ def test_empty_input(self):
+ self.assertEqual(_split_comment(1, ''), [])
+
+ def test_multiple_lines(self):
+ self.assertEqual(
+ _split_comment(5, 'one\ntwo\nthree'),
+ [(5, 'one'), (6, 'two'), (7, 'three')])