1
# Copyright (C) 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from cStringIO import StringIO
29
class TestEscape(tests.TestCase):
31
def test_simple_escape(self):
33
export_pot._escape('foobar'),
36
s = '''foo\nbar\r\tbaz\\"spam"'''
37
e = '''foo\\nbar\\r\\tbaz\\\\\\"spam\\"'''
38
self.assertEqual(export_pot._escape(s), e)
40
def test_complex_escape(self):
42
e = '''\\\\r \\\\\\n'''
43
self.assertEqual(export_pot._escape(s), e)
46
class TestNormalize(tests.TestCase):
48
def test_single_line(self):
51
self.assertEqual(export_pot._normalize(s), e)
55
self.assertEqual(export_pot._normalize(s), e)
57
def test_multi_lines(self):
59
e = '""\n"foo\\n"\n"bar\\n"'
60
self.assertEqual(export_pot._normalize(s), e)
67
self.assertEqual(export_pot._normalize(s), e)
70
class PoEntryTestCase(tests.TestCase):
73
self.overrideAttr(export_pot, '_FOUND_MSGID', set())
74
self._outf = StringIO()
75
super(PoEntryTestCase, self).setUp()
77
def check_output(self, expected):
79
self._outf.getvalue(),
80
textwrap.dedent(expected)
83
class TestPoEntry(PoEntryTestCase):
85
def test_simple(self):
86
export_pot._poentry(self._outf, 'dummy', 1, "spam")
87
export_pot._poentry(self._outf, 'dummy', 2, "ham", 'EGG')
88
self.check_output('''\
100
def test_duplicate(self):
101
export_pot._poentry(self._outf, 'dummy', 1, "spam")
102
# This should be ignored.
103
export_pot._poentry(self._outf, 'dummy', 2, "spam", 'EGG')
105
self.check_output('''\
112
class TestPoentryPerPergraph(PoEntryTestCase):
114
def test_single(self):
115
export_pot._poentry_per_paragraph(
119
'''foo\nbar\nbaz\n'''
121
self.check_output('''\
130
def test_multi(self):
131
export_pot._poentry_per_paragraph(
135
'''spam\nham\negg\n\nSPAM\nHAM\nEGG\n'''
137
self.check_output('''\
154
class TestExportCommandHelp(PoEntryTestCase):
156
def test_command_help(self):
158
class cmd_Demo(commands.Command):
159
__doc__ = """A sample command.
172
export_pot._write_command_help(self._outf, cmd_Demo())
173
result = self._outf.getvalue()
174
# We don't care about filename and lineno here.
175
result = re.sub(r'(?m)^#: [^\n]+\n', '', result)
177
self.assertEqualDiff(
178
'msgid "A sample command."\n'
180
'\n' # :Usage: should not be translated.
186
'msgid " cmd arg1"\n'
189
'msgid "Blah Blah Blah"\n'