annotate babel/messages/tests/extract.py @ 530:85e1beadacb0

Update the copyright line.
author jruigrok
date Sat, 05 Mar 2011 15:22:28 +0000
parents 48f46a943be9
children
rev   line source
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
2 #
530
85e1beadacb0 Update the copyright line.
jruigrok
parents: 367
diff changeset
3 # Copyright (C) 2007-2011 Edgewall Software
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
4 # All rights reserved.
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
5 #
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
9 #
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
13
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
14 import codecs
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
15 import doctest
36
56b931b23d5b Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 12
diff changeset
16 from StringIO import StringIO
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
17 import sys
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
18 import unittest
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
19
54
b3395b285104 Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents: 36
diff changeset
20 from babel.messages import extract
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
21
36
56b931b23d5b Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 12
diff changeset
22
56b931b23d5b Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 12
diff changeset
23 class ExtractPythonTestCase(unittest.TestCase):
56b931b23d5b Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 12
diff changeset
24
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
25 def test_nested_calls(self):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
26 buf = StringIO("""\
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
27 msg1 = _(i18n_arg.replace(r'\"', '"'))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
28 msg2 = ungettext(i18n_arg.replace(r'\"', '"'), multi_arg.replace(r'\"', '"'), 2)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
29 msg3 = ungettext("Babel", multi_arg.replace(r'\"', '"'), 2)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
30 msg4 = ungettext(i18n_arg.replace(r'\"', '"'), "Babels", 2)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
31 msg5 = ungettext('bunny', 'bunnies', random.randint(1, 2))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
32 msg6 = ungettext(arg0, 'bunnies', random.randint(1, 2))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
33 msg7 = _(hello.there)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
34 msg8 = gettext('Rabbit')
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
35 msg9 = dgettext('wiki', model.addPage())
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
36 msg10 = dngettext(getDomain(), 'Page', 'Pages', 3)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
37 """)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
38 messages = list(extract.extract_python(buf,
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
39 extract.DEFAULT_KEYWORDS.keys(),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
40 [], {}))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
41 self.assertEqual([
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
42 (1, '_', None, []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
43 (2, 'ungettext', (None, None, None), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
44 (3, 'ungettext', (u'Babel', None, None), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
45 (4, 'ungettext', (None, u'Babels', None), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
46 (5, 'ungettext', (u'bunny', u'bunnies', None), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
47 (6, 'ungettext', (None, u'bunnies', None), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
48 (7, '_', None, []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
49 (8, 'gettext', u'Rabbit', []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
50 (9, 'dgettext', (u'wiki', None), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
51 (10, 'dngettext', (None, u'Page', u'Pages', None), [])],
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
52 messages)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
53
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
54 def test_nested_comments(self):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
55 buf = StringIO("""\
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
56 msg = ngettext('pylon', # TRANSLATORS: shouldn't be
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
57 'pylons', # TRANSLATORS: seeing this
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
58 count)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
59 """)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
60 messages = list(extract.extract_python(buf, ('ngettext',),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
61 ['TRANSLATORS:'], {}))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
62 self.assertEqual([(1, 'ngettext', (u'pylon', u'pylons', None), [])],
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
63 messages)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
64
366
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
65 def test_comments_with_calls_that_spawn_multiple_lines(self):
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
66 buf = StringIO("""\
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
67 # NOTE: This Comment SHOULD Be Extracted
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
68 add_notice(req, ngettext("Catalog deleted.",
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
69 "Catalogs deleted.", len(selected)))
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
70
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
71 # NOTE: This Comment SHOULD Be Extracted
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
72 add_notice(req, _("Locale deleted."))
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
73
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
74
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
75 # NOTE: This Comment SHOULD Be Extracted
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
76 add_notice(req, ngettext("Foo deleted.", "Foos deleted.", len(selected)))
367
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
77
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
78 # NOTE: This Comment SHOULD Be Extracted
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
79 # NOTE: And This One Too
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
80 add_notice(req, ngettext("Bar deleted.",
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
81 "Bars deleted.", len(selected)))
366
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
82 """)
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
83 messages = list(extract.extract_python(buf, ('ngettext','_'), ['NOTE:'],
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
84
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
85 {'strip_comment_tags':False}))
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
86 self.assertEqual((6, '_', 'Locale deleted.',
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
87 [u'NOTE: This Comment SHOULD Be Extracted']),
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
88 messages[1])
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
89 self.assertEqual((10, 'ngettext', (u'Foo deleted.', u'Foos deleted.',
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
90 None),
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
91 [u'NOTE: This Comment SHOULD Be Extracted']),
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
92 messages[2])
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
93 self.assertEqual((3, 'ngettext',
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
94 (u'Catalog deleted.',
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
95 u'Catalogs deleted.', None),
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
96 [u'NOTE: This Comment SHOULD Be Extracted']),
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
97 messages[0])
367
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
98 self.assertEqual((15, 'ngettext', (u'Bar deleted.', u'Bars deleted.',
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
99 None),
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
100 [u'NOTE: This Comment SHOULD Be Extracted',
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
101 u'NOTE: And This One Too']),
48f46a943be9 Make sure the fix also works for multiple translator comments. Refs #119.
palgarvio
parents: 366
diff changeset
102 messages[3])
366
64dc3f943d3b Test and respective fix for gettext calls that spawn multiple lines. Fixes #119.
palgarvio
parents: 365
diff changeset
103
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
104 def test_declarations(self):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
105 buf = StringIO("""\
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
106 class gettext(object):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
107 pass
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
108 def render_body(context,x,y=_('Page arg 1'),z=_('Page arg 2'),**pageargs):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
109 pass
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
110 def ngettext(y='arg 1',z='arg 2',**pageargs):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
111 pass
223
edfdeabae397 fix skipping of class definitions without parens
pjenvey
parents: 222
diff changeset
112 class Meta:
edfdeabae397 fix skipping of class definitions without parens
pjenvey
parents: 222
diff changeset
113 verbose_name = _('log entry')
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
114 """)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
115 messages = list(extract.extract_python(buf,
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
116 extract.DEFAULT_KEYWORDS.keys(),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
117 [], {}))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
118 self.assertEqual([(3, '_', u'Page arg 1', []),
223
edfdeabae397 fix skipping of class definitions without parens
pjenvey
parents: 222
diff changeset
119 (3, '_', u'Page arg 2', []),
edfdeabae397 fix skipping of class definitions without parens
pjenvey
parents: 222
diff changeset
120 (8, '_', u'log entry', [])],
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
121 messages)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
122
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
123 def test_multiline(self):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
124 buf = StringIO("""\
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
125 msg1 = ngettext('pylon',
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
126 'pylons', count)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
127 msg2 = ngettext('elvis',
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
128 'elvises',
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
129 count)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
130 """)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
131 messages = list(extract.extract_python(buf, ('ngettext',), [], {}))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
132 self.assertEqual([(1, 'ngettext', (u'pylon', u'pylons', None), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
133 (3, 'ngettext', (u'elvis', u'elvises', None), [])],
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
134 messages)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
135
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
136 def test_triple_quoted_strings(self):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
137 buf = StringIO("""\
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
138 msg1 = _('''pylons''')
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
139 msg2 = ngettext(r'''elvis''', \"\"\"elvises\"\"\", count)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
140 msg2 = ngettext(\"\"\"elvis\"\"\", 'elvises', count)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
141 """)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
142 messages = list(extract.extract_python(buf,
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
143 extract.DEFAULT_KEYWORDS.keys(),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
144 [], {}))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
145 self.assertEqual([(1, '_', (u'pylons'), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
146 (2, 'ngettext', (u'elvis', u'elvises', None), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
147 (3, 'ngettext', (u'elvis', u'elvises', None), [])],
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
148 messages)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
149
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
150 def test_multiline_strings(self):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
151 buf = StringIO("""\
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
152 _('''This module provides internationalization and localization
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
153 support for your Python programs by providing an interface to the GNU
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
154 gettext message catalog library.''')
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
155 """)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
156 messages = list(extract.extract_python(buf,
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
157 extract.DEFAULT_KEYWORDS.keys(),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
158 [], {}))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
159 self.assertEqual(
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
160 [(1, '_',
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
161 u'This module provides internationalization and localization\n'
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
162 'support for your Python programs by providing an interface to '
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
163 'the GNU\ngettext message catalog library.', [])],
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
164 messages)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
165
257
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
166 def test_concatenated_strings(self):
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
167 buf = StringIO("""\
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
168 foobar = _('foo' 'bar')
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
169 """)
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
170 messages = list(extract.extract_python(buf,
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
171 extract.DEFAULT_KEYWORDS.keys(),
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
172 [], {}))
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
173 self.assertEqual(u'foobar', messages[0][2])
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
174
36
56b931b23d5b Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 12
diff changeset
175 def test_unicode_string_arg(self):
56b931b23d5b Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 12
diff changeset
176 buf = StringIO("msg = _(u'Foo Bar')")
83
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
177 messages = list(extract.extract_python(buf, ('_',), [], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
178 self.assertEqual(u'Foo Bar', messages[0][2])
36
56b931b23d5b Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 12
diff changeset
179
83
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
180 def test_comment_tag(self):
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
181 buf = StringIO("""
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
182 # NOTE: A translation comment
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
183 msg = _(u'Foo Bar')
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
184 """)
91
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
185 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
186 self.assertEqual(u'Foo Bar', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
187 self.assertEqual([u'NOTE: A translation comment'], messages[0][3])
83
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
188
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
189 def test_comment_tag_multiline(self):
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
190 buf = StringIO("""
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
191 # NOTE: A translation comment
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
192 # with a second line
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
193 msg = _(u'Foo Bar')
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
194 """)
91
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
195 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
196 self.assertEqual(u'Foo Bar', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
197 self.assertEqual([u'NOTE: A translation comment', u'with a second line'],
83
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
198 messages[0][3])
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
199
85
dc260efaed34 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 83
diff changeset
200 def test_translator_comments_with_previous_non_translator_comments(self):
dc260efaed34 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 83
diff changeset
201 buf = StringIO("""
dc260efaed34 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 83
diff changeset
202 # This shouldn't be in the output
dc260efaed34 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 83
diff changeset
203 # because it didn't start with a comment tag
dc260efaed34 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 83
diff changeset
204 # NOTE: A translation comment
dc260efaed34 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 83
diff changeset
205 # with a second line
dc260efaed34 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 83
diff changeset
206 msg = _(u'Foo Bar')
dc260efaed34 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 83
diff changeset
207 """)
91
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
208 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
209 self.assertEqual(u'Foo Bar', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
210 self.assertEqual([u'NOTE: A translation comment', u'with a second line'],
85
dc260efaed34 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 83
diff changeset
211 messages[0][3])
83
6b6aa2f9e93d Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 80
diff changeset
212
91
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
213 def test_comment_tags_not_on_start_of_comment(self):
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
214 buf = StringIO("""
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
215 # This shouldn't be in the output
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
216 # because it didn't start with a comment tag
365
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
217 # do NOTE: this will not be a translation comment
91
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
218 # NOTE: This one will be
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
219 msg = _(u'Foo Bar')
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
220 """)
018b2efe5df7 Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
palgarvio
parents: 85
diff changeset
221 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
222 self.assertEqual(u'Foo Bar', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
223 self.assertEqual([u'NOTE: This one will be'], messages[0][3])
93
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
224
92
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
225 def test_multiple_comment_tags(self):
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
226 buf = StringIO("""
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
227 # NOTE1: A translation comment for tag1
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
228 # with a second line
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
229 msg = _(u'Foo Bar1')
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
230
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
231 # NOTE2: A translation comment for tag2
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
232 msg = _(u'Foo Bar2')
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
233 """)
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
234 messages = list(extract.extract_python(buf, ('_',),
5bac3678e60d Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
palgarvio
parents: 91
diff changeset
235 ['NOTE1:', 'NOTE2:'], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
236 self.assertEqual(u'Foo Bar1', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
237 self.assertEqual([u'NOTE1: A translation comment for tag1',
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
238 u'with a second line'], messages[0][3])
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
239 self.assertEqual(u'Foo Bar2', messages[1][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
240 self.assertEqual([u'NOTE2: A translation comment for tag2'], messages[1][3])
93
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
241
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
242 def test_two_succeeding_comments(self):
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
243 buf = StringIO("""
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
244 # NOTE: one
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
245 # NOTE: two
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
246 msg = _(u'Foo Bar')
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
247 """)
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
248 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
249 self.assertEqual(u'Foo Bar', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
250 self.assertEqual([u'NOTE: one', u'NOTE: two'], messages[0][3])
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
251
93
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
252 def test_invalid_translator_comments(self):
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
253 buf = StringIO("""
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
254 # NOTE: this shouldn't apply to any messages
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
255 hello = 'there'
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
256
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
257 msg = _(u'Foo Bar')
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
258 """)
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
259 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
260 self.assertEqual(u'Foo Bar', messages[0][2])
93
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
261 self.assertEqual([], messages[0][3])
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
262
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
263 def test_invalid_translator_comments2(self):
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
264 buf = StringIO("""
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
265 # NOTE: Hi!
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
266 hithere = _('Hi there!')
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
267
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
268 # NOTE: you should not be seeing this in the .po
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
269 rows = [[v for v in range(0,10)] for row in range(0,10)]
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
270
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
271 # this (NOTE:) should not show up either
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
272 hello = _('Hello')
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
273 """)
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
274 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
275 self.assertEqual(u'Hi there!', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
276 self.assertEqual([u'NOTE: Hi!'], messages[0][3])
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
277 self.assertEqual(u'Hello', messages[1][2])
93
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
278 self.assertEqual([], messages[1][3])
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
279
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
280 def test_invalid_translator_comments3(self):
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
281 buf = StringIO("""
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
282 # NOTE: Hi,
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
283
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
284 # there!
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
285 hithere = _('Hi there!')
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
286 """)
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
287 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
288 self.assertEqual(u'Hi there!', messages[0][2])
93
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
289 self.assertEqual([], messages[0][3])
1ce6692ed625 Commiting patch provided by pjenvey: Translator comments don't apply unless they immediately preceed the message.
palgarvio
parents: 92
diff changeset
290
365
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
291 def test_comment_tag_with_leading_space(self):
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
292 buf = StringIO("""
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
293 #: A translation comment
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
294 #: with leading spaces
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
295 msg = _(u'Foo Bar')
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
296 """)
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
297 messages = list(extract.extract_python(buf, ('_',), [':'], {}))
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
298 self.assertEqual(u'Foo Bar', messages[0][2])
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
299 self.assertEqual([u': A translation comment', u': with leading spaces'],
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
300 messages[0][3])
cb94806aa82c Fix typo and add a test for translator comments with leading spaces.
palgarvio
parents: 343
diff changeset
301
257
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
302 def test_different_signatures(self):
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
303 buf = StringIO("""
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
304 foo = _('foo', 'bar')
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
305 n = ngettext('hello', 'there', n=3)
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
306 n = ngettext(n=3, 'hello', 'there')
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
307 n = ngettext(n=3, *messages)
258
f2cd4422d2cf skip messages that have less arguments than the keyword spec calls for
pjenvey
parents: 257
diff changeset
308 n = ngettext()
f2cd4422d2cf skip messages that have less arguments than the keyword spec calls for
pjenvey
parents: 257
diff changeset
309 n = ngettext('foo')
257
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
310 """)
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
311 messages = list(extract.extract_python(buf, ('_', 'ngettext'), [], {}))
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
312 self.assertEqual((u'foo', u'bar'), messages[0][2])
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
313 self.assertEqual((u'hello', u'there', None), messages[1][2])
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
314 self.assertEqual((None, u'hello', u'there'), messages[2][2])
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
315 self.assertEqual((None, None), messages[3][2])
258
f2cd4422d2cf skip messages that have less arguments than the keyword spec calls for
pjenvey
parents: 257
diff changeset
316 self.assertEqual(None, messages[4][2])
f2cd4422d2cf skip messages that have less arguments than the keyword spec calls for
pjenvey
parents: 257
diff changeset
317 self.assertEqual(('foo'), messages[5][2])
257
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
318
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
319 def test_utf8_message(self):
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
320 buf = StringIO("""
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
321 # NOTE: hello
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
322 msg = _('Bonjour à tous')
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
323 """)
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
324 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'],
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
325 {'encoding': 'utf-8'}))
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
326 self.assertEqual(u'Bonjour à tous', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
327 self.assertEqual([u'NOTE: hello'], messages[0][3])
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
328
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
329 def test_utf8_message_with_magic_comment(self):
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
330 buf = StringIO("""# -*- coding: utf-8 -*-
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
331 # NOTE: hello
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
332 msg = _('Bonjour à tous')
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
333 """)
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
334 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
335 self.assertEqual(u'Bonjour à tous', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
336 self.assertEqual([u'NOTE: hello'], messages[0][3])
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
337
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
338 def test_utf8_message_with_utf8_bom(self):
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
339 buf = StringIO(codecs.BOM_UTF8 + """
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
340 # NOTE: hello
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
341 msg = _('Bonjour à tous')
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
342 """)
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
343 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
344 self.assertEqual(u'Bonjour à tous', messages[0][2])
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
345 self.assertEqual([u'NOTE: hello'], messages[0][3])
164
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
346
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
347 def test_utf8_raw_strings_match_unicode_strings(self):
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
348 buf = StringIO(codecs.BOM_UTF8 + """
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
349 msg = _('Bonjour à tous')
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
350 msgu = _(u'Bonjour à tous')
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
351 """)
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
352 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
353 self.assertEqual(u'Bonjour à tous', messages[0][2])
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
354 self.assertEqual(messages[0][2], messages[1][2])
84a9e5f97658 made the python extractor detect source file encodings from the magic encoding
pjenvey
parents: 93
diff changeset
355
338
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
356 def test_extract_strip_comment_tags(self):
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
357 buf = StringIO("""\
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
358 #: This is a comment with a very simple
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
359 #: prefix specified
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
360 _('Servus')
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
361
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
362 # NOTE: This is a multiline comment with
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
363 # a prefix too
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
364 _('Babatschi')""")
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
365 messages = list(extract.extract('python', buf, comment_tags=['NOTE:', ':'],
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
366 strip_comment_tags=True))
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
367 self.assertEqual(u'Servus', messages[0][1])
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
368 self.assertEqual([u'This is a comment with a very simple',
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
369 u'prefix specified'], messages[0][2])
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
370 self.assertEqual(u'Babatschi', messages[1][1])
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
371 self.assertEqual([u'This is a multiline comment with',
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
372 u'a prefix too'], messages[1][2])
6fe060286ff0 Stripping of comment tags is optional now. If enabled it will strip the tags from all lines of a comment now.
aronacher
parents: 322
diff changeset
373
343
ffde9bbc75bb Remove leftover unused code from [365].
cmlenz
parents: 339
diff changeset
374
339
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
375 class ExtractJavaScriptTestCase(unittest.TestCase):
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
376
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
377 def test_simple_extract(self):
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
378 buf = StringIO("""\
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
379 msg1 = _('simple')
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
380 msg2 = gettext('simple')
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
381 msg3 = ngettext('s', 'p', 42)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
382 """)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
383 messages = \
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
384 list(extract.extract('javascript', buf, extract.DEFAULT_KEYWORDS,
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
385 [], {}))
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
386
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
387 self.assertEqual([(1, 'simple', []),
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
388 (2, 'simple', []),
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
389 (3, ('s', 'p'), [])], messages)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
390
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
391 def test_various_calls(self):
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
392 buf = StringIO("""\
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
393 msg1 = _(i18n_arg.replace(/"/, '"'))
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
394 msg2 = ungettext(i18n_arg.replace(/"/, '"'), multi_arg.replace(/"/, '"'), 2)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
395 msg3 = ungettext("Babel", multi_arg.replace(/"/, '"'), 2)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
396 msg4 = ungettext(i18n_arg.replace(/"/, '"'), "Babels", 2)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
397 msg5 = ungettext('bunny', 'bunnies', parseInt(Math.random() * 2 + 1))
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
398 msg6 = ungettext(arg0, 'bunnies', rparseInt(Math.random() * 2 + 1))
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
399 msg7 = _(hello.there)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
400 msg8 = gettext('Rabbit')
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
401 msg9 = dgettext('wiki', model.addPage())
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
402 msg10 = dngettext(domain, 'Page', 'Pages', 3)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
403 """)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
404 messages = \
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
405 list(extract.extract('javascript', buf, extract.DEFAULT_KEYWORDS, [],
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
406 {}))
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
407 self.assertEqual([(5, (u'bunny', u'bunnies'), []),
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
408 (8, u'Rabbit', []),
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
409 (10, (u'Page', u'Pages'), [])], messages)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
410
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
411 def test_message_with_line_comment(self):
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
412 buf = StringIO("""\
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
413 // NOTE: hello
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
414 msg = _('Bonjour à tous')
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
415 """)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
416 messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
417 self.assertEqual(u'Bonjour à tous', messages[0][2])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
418 self.assertEqual([u'NOTE: hello'], messages[0][3])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
419
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
420 def test_message_with_multiline_comment(self):
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
421 buf = StringIO("""\
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
422 /* NOTE: hello
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
423 and bonjour
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
424 and servus */
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
425 msg = _('Bonjour à tous')
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
426 """)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
427 messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
428 self.assertEqual(u'Bonjour à tous', messages[0][2])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
429 self.assertEqual([u'NOTE: hello', 'and bonjour', ' and servus'], messages[0][3])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
430
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
431 def test_ignore_function_definitions(self):
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
432 buf = StringIO("""\
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
433 function gettext(value) {
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
434 return translations[language][value] || value;
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
435 }""")
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
436
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
437 messages = list(extract.extract_javascript(buf, ('gettext',), [], {}))
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
438 self.assertEqual(messages, [])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
439
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
440 def test_misplaced_comments(self):
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
441 buf = StringIO("""\
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
442 /* NOTE: this won't show up */
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
443 foo()
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
444
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
445 /* NOTE: this will */
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
446 msg = _('Something')
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
447
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
448 // NOTE: this will show up
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
449 // too.
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
450 msg = _('Something else')
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
451
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
452 // NOTE: but this won't
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
453 bar()
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
454
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
455 _('no comment here')
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
456 """)
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
457 messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
458 self.assertEqual(u'Something', messages[0][2])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
459 self.assertEqual([u'NOTE: this will'], messages[0][3])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
460 self.assertEqual(u'Something else', messages[1][2])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
461 self.assertEqual([u'NOTE: this will show up', 'too.'], messages[1][3])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
462 self.assertEqual(u'no comment here', messages[2][2])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
463 self.assertEqual([], messages[2][3])
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
464
343
ffde9bbc75bb Remove leftover unused code from [365].
cmlenz
parents: 339
diff changeset
465
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
466 class ExtractTestCase(unittest.TestCase):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
467
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
468 def test_invalid_filter(self):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
469 buf = StringIO("""\
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
470 msg1 = _(i18n_arg.replace(r'\"', '"'))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
471 msg2 = ungettext(i18n_arg.replace(r'\"', '"'), multi_arg.replace(r'\"', '"'), 2)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
472 msg3 = ungettext("Babel", multi_arg.replace(r'\"', '"'), 2)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
473 msg4 = ungettext(i18n_arg.replace(r'\"', '"'), "Babels", 2)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
474 msg5 = ungettext('bunny', 'bunnies', random.randint(1, 2))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
475 msg6 = ungettext(arg0, 'bunnies', random.randint(1, 2))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
476 msg7 = _(hello.there)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
477 msg8 = gettext('Rabbit')
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
478 msg9 = dgettext('wiki', model.addPage())
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
479 msg10 = dngettext(domain, 'Page', 'Pages', 3)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
480 """)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
481 messages = \
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
482 list(extract.extract('python', buf, extract.DEFAULT_KEYWORDS, [],
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
483 {}))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
484 self.assertEqual([(5, (u'bunny', u'bunnies'), []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
485 (8, u'Rabbit', []),
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
486 (10, (u'Page', u'Pages'), [])], messages)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
487
322
8c634fa87793 fix invalid message extraction methods causing:
pjenvey
parents: 258
diff changeset
488 def test_invalid_extract_method(self):
8c634fa87793 fix invalid message extraction methods causing:
pjenvey
parents: 258
diff changeset
489 buf = StringIO('')
8c634fa87793 fix invalid message extraction methods causing:
pjenvey
parents: 258
diff changeset
490 self.assertRaises(ValueError, list, extract.extract('spam', buf))
8c634fa87793 fix invalid message extraction methods causing:
pjenvey
parents: 258
diff changeset
491
257
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
492 def test_different_signatures(self):
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
493 buf = StringIO("""
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
494 foo = _('foo', 'bar')
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
495 n = ngettext('hello', 'there', n=3)
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
496 n = ngettext(n=3, 'hello', 'there')
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
497 n = ngettext(n=3, *messages)
258
f2cd4422d2cf skip messages that have less arguments than the keyword spec calls for
pjenvey
parents: 257
diff changeset
498 n = ngettext()
f2cd4422d2cf skip messages that have less arguments than the keyword spec calls for
pjenvey
parents: 257
diff changeset
499 n = ngettext('foo')
257
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
500 """)
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
501 messages = \
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
502 list(extract.extract('python', buf, extract.DEFAULT_KEYWORDS, [],
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
503 {}))
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
504 self.assertEqual(len(messages), 2)
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
505 self.assertEqual(u'foo', messages[0][1])
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
506 self.assertEqual((u'hello', u'there'), messages[1][1])
4c9f98dd30eb add extractor tests for some odder method signatures and concatenated strings
pjenvey
parents: 223
diff changeset
507
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
508 def test_empty_string_msgid(self):
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
509 buf = StringIO("""\
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
510 msg = _('')
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
511 """)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
512 stderr = sys.stderr
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
513 sys.stderr = StringIO()
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
514 try:
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
515 messages = \
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
516 list(extract.extract('python', buf, extract.DEFAULT_KEYWORDS,
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
517 [], {}))
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
518 self.assertEqual([], messages)
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
519 assert 'warning: Empty msgid.' in sys.stderr.getvalue()
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
520 finally:
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
521 sys.stderr = stderr
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
522
343
ffde9bbc75bb Remove leftover unused code from [365].
cmlenz
parents: 339
diff changeset
523
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
524 def suite():
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
525 suite = unittest.TestSuite()
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
526 suite.addTest(doctest.DocTestSuite(extract))
36
56b931b23d5b Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 12
diff changeset
527 suite.addTest(unittest.makeSuite(ExtractPythonTestCase))
339
6104e7967a12 Added !JavaScript extractor
aronacher
parents: 338
diff changeset
528 suite.addTest(unittest.makeSuite(ExtractJavaScriptTestCase))
222
7945923e5fa6 o extract_python fixes:
pjenvey
parents: 164
diff changeset
529 suite.addTest(unittest.makeSuite(ExtractTestCase))
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
530 return suite
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
531
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
532 if __name__ == '__main__':
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
533 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software