summaryrefslogtreecommitdiff
path: root/test/ext/test_linguaplugin.py
blob: a563969122539d2a678ca8f08f1acaaca79dd53d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os

from .. import skip_if
from .. import template_base
from .. import TemplateTest

try:
    import lingua
except:
    lingua = None

if lingua is not None:
    from mako.ext.linguaplugin import LinguaMakoExtractor
    from lingua.extractors import register_extractors


class MockOptions:
    keywords = []
    domain = None


def skip():
    return skip_if(
        lambda: not lingua, "lingua not installed: skipping linguaplugin test"
    )


class ExtractMakoTestCase(TemplateTest):
    @skip()
    def test_extract(self):
        register_extractors()
        plugin = LinguaMakoExtractor({"comment-tags": "TRANSLATOR"})
        messages = list(
            plugin(os.path.join(template_base, "gettext.mako"), MockOptions())
        )
        msgids = [(m.msgid, m.msgid_plural) for m in messages]
        self.assertEqual(
            msgids,
            [
                ("Page arg 1", None),
                ("Page arg 2", None),
                ("Begin", None),
                ("Hi there!", None),
                ("Hello", None),
                ("Welcome", None),
                ("Yo", None),
                ("The", None),
                ("bunny", "bunnies"),
                ("Goodbye", None),
                ("Babel", None),
                ("hella", "hellas"),
                ("The", None),
                ("bunny", "bunnies"),
                ("Goodbye, really!", None),
                ("P.S. byebye", None),
                ("Top", None),
                (u"foo", None),
                ("hoho", None),
                (u"bar", None),
                ("Inside a p tag", None),
                ("Later in a p tag", None),
                ("No action at a distance.", None),
            ],
        )