-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_extract.py
More file actions
73 lines (58 loc) · 2.12 KB
/
test_extract.py
File metadata and controls
73 lines (58 loc) · 2.12 KB
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
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
"""
test_extract
test Message extraction from template files
:copyright: (c) 2012 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
"""
import sys
sys.path.append('../')
from io import StringIO
import unittest
from tornadobabel.extract import extract_tornado
class TestExtract(unittest.TestCase):
def setUp(self):
pass
def test_extract(self):
template = StringIO("""
{{ _("Test String") }}
{{ something }}
{% block something %}{% end %}
""")
strings = list(extract_tornado(template, None, None, {}))
self.assertEqual(len(strings), 1)
# Ensure that the string is correct
string, = strings
self.assertEqual(string[0], 2) # Line number
self.assertEqual(string[1], '_') # Function name
self.assertEqual(string[2], "Test String") # Translatable string
def test_n_extract(self):
template = StringIO("""
{{ _("Test String") }}
{{ _N("%(num)d apple", "%(num)d apples", count) }}
{{ something }}
{% block something %}{% end %}
""")
strings = list(extract_tornado(template, None, None, {}))
self.assertEqual(len(strings), 2)
# Ensure that the string is correct
string = strings[1]
self.assertEqual(string[0], 3) # Line number
self.assertEqual(string[1], '_N') # Function name
self.assertEqual(string[2], ('%(num)d apple', '%(num)d apples', None))
def test_nested_extract(self):
template = StringIO("""
{% extends 'somethingelse.html' %}
{% block abc %}
{{ _("Test String") }}
{% end %}
""")
strings = list(extract_tornado(template, None, None, {}))
self.assertEqual(len(strings), 1)
# Ensure that the string is correct
string, = strings
self.assertEqual(string[0], 4) # Line number
self.assertEqual(string[1], '_') # Function name
self.assertEqual(string[2], "Test String") # Translatable string
if __name__ == "__main__":
unittest.main()