| 1 |
# Test message extraction |
| 2 |
from gettext import gettext as _ |
| 3 |
|
| 4 |
# Empty string |
| 5 |
_("") |
| 6 |
|
| 7 |
# Extra parentheses |
| 8 |
(_("parentheses")) |
| 9 |
((_("parentheses"))) |
| 10 |
|
| 11 |
# Multiline strings |
| 12 |
_("Hello, " |
| 13 |
"world!") |
| 14 |
|
| 15 |
_("""Hello, |
| 16 |
multiline! |
| 17 |
""") |
| 18 |
|
| 19 |
# Invalid arguments |
| 20 |
_() |
| 21 |
_(None) |
| 22 |
_(1) |
| 23 |
_(False) |
| 24 |
_(x="kwargs are not allowed") |
| 25 |
_("foo", "bar") |
| 26 |
_("something", x="something else") |
| 27 |
|
| 28 |
# .format() |
| 29 |
_("Hello, {}!").format("world") # valid |
| 30 |
_("Hello, {}!".format("world")) # invalid |
| 31 |
|
| 32 |
# Nested structures |
| 33 |
_("1"), _("2") |
| 34 |
arr = [_("A"), _("B")] |
| 35 |
obj = {'a': _("A"), 'b': _("B")} |
| 36 |
{{{_('set')}}} |
| 37 |
|
| 38 |
|
| 39 |
# Nested functions and classes |
| 40 |
def test(): |
| 41 |
_("nested string") # XXX This should be extracted but isn't. |
| 42 |
[_("nested string")] |
| 43 |
|
| 44 |
|
| 45 |
class Foo: |
| 46 |
def bar(self): |
| 47 |
return _("baz") |
| 48 |
|
| 49 |
|
| 50 |
def bar(x=_('default value')): # XXX This should be extracted but isn't. |
| 51 |
pass |
| 52 |
|
| 53 |
|
| 54 |
def baz(x=[_('default value')]): # XXX This should be extracted but isn't. |
| 55 |
pass |
| 56 |
|
| 57 |
|
| 58 |
# Shadowing _() |
| 59 |
def _(x): |
| 60 |
pass |
| 61 |
|
| 62 |
|
| 63 |
def _(x="don't extract me"): |
| 64 |
pass |