Skip to content
Snippets Groups Projects
Commit 53b62023 authored by Wichert Akkerman's avatar Wichert Akkerman
Browse files

Add tests for Babel plugin

parent 285bc818
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
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')])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment