|
14 | 14 | class ExtractDjangoTestCase(unittest.TestCase):
|
15 | 15 | # TODO: translator comments are not yet supported!
|
16 | 16 |
|
17 |
| - def test_extract_simple(self): |
| 17 | + def test_extract_no_tags(self): |
| 18 | + buf = BytesIO(b'nothing') |
| 19 | + messages = list(extract_django(buf, default_keys, [], {})) |
| 20 | + self.assertEqual([], messages) |
| 21 | + |
| 22 | + def test_extract_simple_double_quotes(self): |
18 | 23 | buf = BytesIO(b'{% trans "Bunny" %}')
|
19 | 24 | messages = list(extract_django(buf, default_keys, [], {}))
|
20 | 25 | self.assertEqual([(1, None, u'Bunny', [])], messages)
|
21 | 26 |
|
| 27 | + def test_extract_simple_single_quotes(self): |
| 28 | + buf = BytesIO(b"{% trans 'Bunny' %}") |
| 29 | + messages = list(extract_django(buf, default_keys, [], {})) |
| 30 | + self.assertEqual([(1, None, u'Bunny', [])], messages) |
| 31 | + |
22 | 32 | def test_extract_var(self):
|
23 | 33 | buf = BytesIO(b'{% blocktrans %}{{ anton }}{% endblocktrans %}')
|
24 | 34 | messages = list(extract_django(buf, default_keys, [], {}))
|
@@ -69,3 +79,40 @@ def test_trans_blocks_must_not_include_other_block_tags(self):
|
69 | 79 | buf = BytesIO(b'{% blocktrans %}{% other_tag %}{% endblocktrans %}')
|
70 | 80 | gen = extract_django(buf, default_keys, [], {})
|
71 | 81 | pytest.raises(SyntaxError, gen.next)
|
| 82 | + |
| 83 | + def test_extract_var(self): |
| 84 | + buf = BytesIO(b'{{ book }}') |
| 85 | + messages = list(extract_django(buf, default_keys, [], {})) |
| 86 | + self.assertEqual([], messages) |
| 87 | + |
| 88 | + def test_extract_filters_default_translatable(self): |
| 89 | + buf = BytesIO(b'{{ book.author|default:_("Unknown") }}') |
| 90 | + messages = list(extract_django(buf, default_keys, [], {})) |
| 91 | + self.assertEqual([(1, None, u'Unknown', [])], messages) |
| 92 | + |
| 93 | + def test_extract_filters_default_translatable_single_quotes(self): |
| 94 | + buf = BytesIO(b"{{ book.author|default:_('Unknown') }}") |
| 95 | + messages = list(extract_django(buf, default_keys, [], {})) |
| 96 | + self.assertEqual([(1, None, u'Unknown', [])], messages) |
| 97 | + |
| 98 | + def test_extract_constant_single_quotes(self): |
| 99 | + buf = BytesIO(b"{{ _('constant') }}") |
| 100 | + messages = list(extract_django(buf, default_keys, [], {})) |
| 101 | + self.assertEqual([(1, None, u"'constant'", [])], messages) |
| 102 | + |
| 103 | + def test_extract_constant_single_quotes(self): |
| 104 | + buf = BytesIO(b'{{ _("constant") }}') |
| 105 | + messages = list(extract_django(buf, default_keys, [], {})) |
| 106 | + self.assertEqual([(1, None, u'"constant"', [])], messages) |
| 107 | + |
| 108 | + def test_extract_constant_block(self): |
| 109 | + buf = BytesIO(b'{% _("constant") %}') |
| 110 | + messages = list(extract_django(buf, default_keys, [], {})) |
| 111 | + self.assertEqual([(1, None, u'"constant"', [])], messages) |
| 112 | + |
| 113 | + def test_extract_constant_in_block(self): |
| 114 | + buf = BytesIO(b'{% blocktrans foo=_("constant") %}{{ foo }}{% endblocktrans %}') |
| 115 | + messages = list(extract_django(buf, default_keys, [], {})) |
| 116 | + self.assertEqual( |
| 117 | + [(1, None, u'"constant"', []), (1, None, u'%(foo)s', [])], |
| 118 | + messages) |
0 commit comments