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
25
class TestEscape(tests.TestCase):
27
def test_simple_escape(self):
29
export_pot._escape('foobar'),
32
s = '''foo\nbar\r\tbaz\\"spam"'''
33
e = '''foo\\nbar\\r\\tbaz\\\\\\"spam\\"'''
34
self.assertEqual(export_pot._escape(s), e)
36
def test_complex_escape(self):
38
e = '''\\\\r \\\\\\n'''
39
self.assertEqual(export_pot._escape(s), e)
42
class TestNormalize(tests.TestCase):
44
def test_single_line(self):
47
self.assertEqual(export_pot._normalize(s), e)
51
self.assertEqual(export_pot._normalize(s), e)
53
def test_multi_lines(self):
55
e = '""\n"foo\\n"\n"bar\\n"'
56
self.assertEqual(export_pot._normalize(s), e)
63
self.assertEqual(export_pot._normalize(s), e)
66
class PoEntryTestCase(tests.TestCase):
69
self.overrideAttr(export_pot, '_FOUND_MSGID', set())
70
self._outf = StringIO()
71
super(PoEntryTestCase, self).setUp()
73
def check_output(self, expected):
75
self._outf.getvalue(),
76
textwrap.dedent(expected)
79
class TestPoEntry(PoEntryTestCase):
81
def test_simple(self):
82
export_pot._poentry(self._outf, 'dummy', 1, "spam")
83
export_pot._poentry(self._outf, 'dummy', 2, "ham", 'EGG')
84
self.check_output('''\
96
def test_duplicate(self):
97
export_pot._poentry(self._outf, 'dummy', 1, "spam")
98
# This should be ignored.
99
export_pot._poentry(self._outf, 'dummy', 2, "spam", 'EGG')
101
self.check_output('''\
108
class TestPoentryPerPergraph(PoEntryTestCase):
110
def test_single(self):
111
export_pot._poentry_per_paragraph(
115
'''foo\nbar\nbaz\n'''
117
self.check_output('''\
126
def test_multi(self):
127
export_pot._poentry_per_paragraph(
131
'''spam\nham\negg\n\nSPAM\nHAM\nEGG\n'''
133
self.check_output('''\