From 48e78ea471965f1e04236bbaafb05fe4e75b2f6d Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Sat, 6 Jul 2013 14:17:13 +0200 Subject: [PATCH] copy babel.messages.frontend doctests as unit tests --- tests/messages/test_frontend.py | 46 ++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/messages/test_frontend.py b/tests/messages/test_frontend.py index 0d76b660..d3b4e209 100644 --- a/tests/messages/test_frontend.py +++ b/tests/messages/test_frontend.py @@ -1055,9 +1055,53 @@ compiling catalog %r to %r os.unlink(mo_file) +def test_parse_mapping(): + buf = StringIO( + '[extractors]\n' + 'custom = mypackage.module:myfunc\n' + '\n' + '# Python source files\n' + '[python: **.py]\n' + '\n' + '# Genshi templates\n' + '[genshi: **/templates/**.html]\n' + 'include_attrs =\n' + '[genshi: **/templates/**.txt]\n' + 'template_class = genshi.template:TextTemplate\n' + 'encoding = latin-1\n' + '\n' + '# Some custom extractor\n' + '[custom: **/custom/*.*]\n') + + method_map, options_map = frontend.parse_mapping(buf) + assert len(method_map) == 4 + + assert method_map[0] == ('**.py', 'python') + assert options_map['**.py'] == {} + assert method_map[1] == ('**/templates/**.html', 'genshi') + assert options_map['**/templates/**.html']['include_attrs'] == '' + assert method_map[2] == ('**/templates/**.txt', 'genshi') + assert (options_map['**/templates/**.txt']['template_class'] + == 'genshi.template:TextTemplate') + assert options_map['**/templates/**.txt']['encoding'] == 'latin-1' + + assert method_map[3] == ('**/custom/*.*', 'mypackage.module:myfunc') + assert options_map['**/custom/*.*'] == {} + + +def test_parse_keywords(): + kw = frontend.parse_keywords(['_', 'dgettext:2', + 'dngettext:2,3', 'pgettext:1c,2']) + assert kw == { + '_': None, + 'dgettext': (2,), + 'dngettext': (2, 3), + 'pgettext': ((1, 'c'), 2), + } + + def suite(): suite = unittest.TestSuite() - suite.addTest(doctest.DocTestSuite(frontend)) suite.addTest(unittest.makeSuite(CompileCatalogTestCase)) suite.addTest(unittest.makeSuite(ExtractMessagesTestCase)) suite.addTest(unittest.makeSuite(InitCatalogTestCase)) -- 2.47.2