From 53b6202319639c7264fd5de76f77e51d18cf94b2 Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Mon, 25 Aug 2014 21:50:26 +0200 Subject: Add tests for Babel plugin --- test/ext/test_babelplugin.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/ext/test_babelplugin.py (limited to 'test/ext/test_babelplugin.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'

Hello world

') + 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'

Hello world

') + + def test_parse_python_expression(self): + input = io.BytesIO(b'

${_("Message")}

') + messages = list(extract(input, ['_'], [], {})) + self.assertEqual(messages, [(1, '_', u'Message', [])]) + + def test_python_gettext_call(self): + input = io.BytesIO(b'

${_("Message")}

') + messages = list(extract(input, ['_'], [], {})) + self.assertEqual(messages, [(1, '_', u'Message', [])]) + + def test_translator_comment(self): + input = io.BytesIO(b''' +

+ ## TRANSLATORS: This is a comment. + ${_("Message")} +

''') + 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')]) -- cgit v1.2.3