diff options
author | Wichert Akkerman <wichert@wiggy.net> | 2014-08-25 21:50:26 +0200 |
---|---|---|
committer | Wichert Akkerman <wichert@wiggy.net> | 2014-08-25 21:50:26 +0200 |
commit | 53b6202319639c7264fd5de76f77e51d18cf94b2 (patch) | |
tree | 3426349401e7f43ec6065c5e8299bc48bd1cd9f0 /test/ext | |
parent | 285bc818a50ccc0f9549630f7c4f4c250585c3e7 (diff) | |
download | mako-53b6202319639c7264fd5de76f77e51d18cf94b2.tar.gz |
Add tests for Babel plugin
Diffstat (limited to 'test/ext')
-rw-r--r-- | test/ext/__init__.py | 0 | ||||
-rw-r--r-- | test/ext/test_babelplugin.py | 48 |
2 files changed, 48 insertions, 0 deletions
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')]) |