1import os
2
3import pytest
4
5from mako.testing.assertions import eq_
6from mako.testing.config import config
7from mako.testing.exclusions import requires_lingua
8from mako.testing.fixtures import TemplateTest
9
10
11class MockOptions:
12    keywords = []
13    domain = None
14    comment_tag = True
15
16
17@requires_lingua
18class MakoExtractTest(TemplateTest):
19    @pytest.fixture(autouse=True)
20    def register_lingua_extractors(self):
21        from lingua.extractors import register_extractors
22
23        register_extractors()
24
25    def test_extract(self):
26        from mako.ext.linguaplugin import LinguaMakoExtractor
27
28        plugin = LinguaMakoExtractor({"comment-tags": "TRANSLATOR"})
29        messages = list(
30            plugin(
31                os.path.join(config.template_base, "gettext.mako"),
32                MockOptions(),
33            )
34        )
35        msgids = [(m.msgid, m.msgid_plural) for m in messages]
36        eq_(
37            msgids,
38            [
39                ("Page arg 1", None),
40                ("Page arg 2", None),
41                ("Begin", None),
42                ("Hi there!", None),
43                ("Hello", None),
44                ("Welcome", None),
45                ("Yo", None),
46                ("The", None),
47                ("bunny", "bunnies"),
48                ("Goodbye", None),
49                ("Babel", None),
50                ("hella", "hellas"),
51                ("The", None),
52                ("bunny", "bunnies"),
53                ("Goodbye, really!", None),
54                ("P.S. byebye", None),
55                ("Top", None),
56                ("foo", None),
57                ("hoho", None),
58                ("bar", None),
59                ("Inside a p tag", None),
60                ("Later in a p tag", None),
61                ("No action at a distance.", None),
62            ],
63        )
64