def test_extraction_with_nonstring_arg(self): buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> ${dgettext(curdomain, 'Foobar')} </html>""") results = list(extract(buf, ['dgettext'], [], {})) self.assertEqual([ (2, 'dgettext', (None, u'Foobar'), []), ], results)
def test_extraction_with_keyword_arg(self): buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> ${gettext('Foobar', foo='bar')} </html>""") results = list(extract(buf, ['gettext'], [], {})) self.assertEqual([ (2, 'gettext', (u'Foobar'), []), ], results)
def test_extraction_inside_ignored_tags_with_directives(self): buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> <script type="text/javascript"> <py:if test="foobar"> alert("This shouldn't be extracted"); </py:if> </script> </html>""") self.assertEqual([], list(extract(buf, ['_'], [], {})))
def test_extraction_without_text(self): buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> <p title="Bar">Foo</p> ${ngettext("Singular", "Plural", num)} </html>""") results = list( extract(buf, ['_', 'ngettext'], [], {'extract_text': 'no'})) self.assertEqual([ (3, 'ngettext', (u'Singular', u'Plural'), []), ], results)
def test_extraction_without_text(self): buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> <p title="Bar">Foo</p> ${ngettext("Singular", "Plural", num)} </html>""") results = list(extract(buf, ['_', 'ngettext'], [], { 'extract_text': 'no' })) self.assertEqual([ (3, 'ngettext', (u'Singular', u'Plural', None), []), ], results)
def test_extraction_inside_ignored_tags(self): buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> <script type="text/javascript"> $('#llist').tabs({ remote: true, spinner: "${_('Please wait...')}" }); </script> </html>""") results = list(extract(buf, ['_'], [], {})) self.assertEqual([ (5, '_', u'Please wait...', []), ], results)
def test_text_template_extraction(self): buf = StringIO("""${_("Dear %(name)s") % {'name': name}}, ${ngettext("Your item:", "Your items", len(items))} #for item in items * $item #end All the best, Foobar""") results = list( extract(buf, ['_', 'ngettext'], [], {'template_class': 'genshi.template:TextTemplate'})) self.assertEqual([(1, '_', u'Dear %(name)s', []), (3, 'ngettext', (u'Your item:', u'Your items'), []), (7, None, u'All the best,\n Foobar', [])], results)
def test_text_template_extraction(self): buf = StringIO("""${_("Dear %(name)s") % {'name': name}}, ${ngettext("Your item:", "Your items", len(items))} #for item in items * $item #end All the best, Foobar""") results = list(extract(buf, ['_', 'ngettext'], [], { 'template_class': 'genshi.template:TextTemplate' })) self.assertEqual([ (1, '_', u'Dear %(name)s', []), (3, 'ngettext', (u'Your item:', u'Your items', None), []), (7, None, u'All the best,\n Foobar', []) ], results)
def test_markup_template_extraction(self): buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> <head> <title>Example</title> </head> <body> <h1>Example</h1> <p>${_("Hello, %(name)s") % dict(name=username)}</p> <p>${ngettext("You have %d item", "You have %d items", num)}</p> </body> </html>""") results = list(extract(buf, ['_', 'ngettext'], [], {})) self.assertEqual([ (3, None, u'Example', []), (6, None, u'Example', []), (7, '_', u'Hello, %(name)s', []), (8, 'ngettext', (u'You have %d item', u'You have %d items'), []), ], results)
def test_markup_template_extraction(self): buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> <head> <title>Example</title> </head> <body> <h1>Example</h1> <p>${_("Hello, %(name)s") % dict(name=username)}</p> <p>${ngettext("You have %d item", "You have %d items", num)}</p> </body> </html>""") results = list(extract(buf, ['_', 'ngettext'], [], {})) self.assertEqual([ (3, None, u'Example', []), (6, None, u'Example', []), (7, '_', u'Hello, %(name)s', []), (8, 'ngettext', (u'You have %d item', u'You have %d items', None), []), ], results)