bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
5830.2.18
by INADA Naoki
Add some tests for export_pot module. |
1 |
# Copyright (C) 2011 Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
from cStringIO import StringIO |
|
|
5830.2.20
by INADA Naoki
Add test for _poentry_per_peragraph() |
18 |
import textwrap |
|
5830.2.18
by INADA Naoki
Add some tests for export_pot module. |
19 |
|
20 |
from bzrlib import ( |
|
21 |
export_pot, |
|
22 |
tests, |
|
23 |
)
|
|
24 |
||
25 |
class TestEscape(tests.TestCase): |
|
26 |
||
27 |
def test_simple_escape(self): |
|
28 |
self.assertEqual( |
|
29 |
export_pot._escape('foobar'), |
|
30 |
'foobar') |
|
31 |
||
32 |
s = '''foo\nbar\r\tbaz\\"spam"''' |
|
33 |
e = '''foo\\nbar\\r\\tbaz\\\\\\"spam\\"''' |
|
34 |
self.assertEqual(export_pot._escape(s), e) |
|
35 |
||
36 |
def test_complex_escape(self): |
|
37 |
s = '''\\r \\\n''' |
|
38 |
e = '''\\\\r \\\\\\n''' |
|
39 |
self.assertEqual(export_pot._escape(s), e) |
|
40 |
||
41 |
||
42 |
class TestNormalize(tests.TestCase): |
|
43 |
||
44 |
def test_single_line(self): |
|
45 |
s = 'foobar' |
|
46 |
e = '"foobar"' |
|
47 |
self.assertEqual(export_pot._normalize(s), e) |
|
48 |
||
49 |
s = 'foo"bar' |
|
50 |
e = '"foo\\"bar"' |
|
51 |
self.assertEqual(export_pot._normalize(s), e) |
|
52 |
||
53 |
def test_multi_lines(self): |
|
54 |
s = 'foo\nbar\n' |
|
55 |
e = '""\n"foo\\n"\n"bar\\n"' |
|
56 |
self.assertEqual(export_pot._normalize(s), e) |
|
57 |
||
58 |
s = '\nfoo\nbar\n' |
|
59 |
e = ('""\n' |
|
60 |
'"\\n"\n' |
|
61 |
'"foo\\n"\n' |
|
62 |
'"bar\\n"') |
|
63 |
self.assertEqual(export_pot._normalize(s), e) |
|
64 |
||
65 |
||
|
5830.2.20
by INADA Naoki
Add test for _poentry_per_peragraph() |
66 |
class PoEntryTestCase(tests.TestCase): |
|
5830.2.18
by INADA Naoki
Add some tests for export_pot module. |
67 |
|
68 |
def setUp(self): |
|
69 |
self.overrideAttr(export_pot, '_FOUND_MSGID', set()) |
|
70 |
self._outf = StringIO() |
|
|
5830.2.20
by INADA Naoki
Add test for _poentry_per_peragraph() |
71 |
super(PoEntryTestCase, self).setUp() |
72 |
||
73 |
def check_output(self, expected): |
|
74 |
self.assertEqual( |
|
75 |
self._outf.getvalue(), |
|
76 |
textwrap.dedent(expected) |
|
77 |
)
|
|
78 |
||
79 |
class TestPoEntry(PoEntryTestCase): |
|
|
5830.2.18
by INADA Naoki
Add some tests for export_pot module. |
80 |
|
81 |
def test_simple(self): |
|
|
5830.2.20
by INADA Naoki
Add test for _poentry_per_peragraph() |
82 |
export_pot._poentry(self._outf, 'dummy', 1, "spam") |
83 |
export_pot._poentry(self._outf, 'dummy', 2, "ham", 'EGG') |
|
84 |
self.check_output('''\ |
|
85 |
#: dummy:1
|
|
86 |
msgid "spam"
|
|
87 |
msgstr ""
|
|
88 |
||
89 |
#: dummy:2
|
|
90 |
# EGG
|
|
91 |
msgid "ham"
|
|
92 |
msgstr ""
|
|
93 |
||
94 |
''') |
|
|
5830.2.18
by INADA Naoki
Add some tests for export_pot module. |
95 |
|
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') |
|
100 |
||
|
5830.2.20
by INADA Naoki
Add test for _poentry_per_peragraph() |
101 |
self.check_output('''\ |
102 |
#: dummy:1
|
|
103 |
msgid "spam"
|
|
104 |
msgstr ""\n |
|
105 |
''') |
|
106 |
||
107 |
||
108 |
class TestPoentryPerPergraph(PoEntryTestCase): |
|
109 |
||
110 |
def test_single(self): |
|
111 |
export_pot._poentry_per_paragraph( |
|
112 |
self._outf, |
|
113 |
'dummy', |
|
114 |
10, |
|
115 |
'''foo\nbar\nbaz\n''' |
|
116 |
)
|
|
117 |
self.check_output('''\ |
|
118 |
#: dummy:10
|
|
119 |
msgid ""
|
|
120 |
"foo\\n" |
|
121 |
"bar\\n" |
|
122 |
"baz\\n" |
|
123 |
msgstr ""\n |
|
124 |
''') |
|
125 |
||
126 |
def test_multi(self): |
|
127 |
export_pot._poentry_per_paragraph( |
|
128 |
self._outf, |
|
129 |
'dummy', |
|
130 |
10, |
|
131 |
'''spam\nham\negg\n\nSPAM\nHAM\nEGG\n''' |
|
132 |
)
|
|
133 |
self.check_output('''\ |
|
134 |
#: dummy:10
|
|
135 |
msgid ""
|
|
136 |
"spam\\n" |
|
137 |
"ham\\n" |
|
138 |
"egg"
|
|
139 |
msgstr ""
|
|
140 |
||
141 |
#: dummy:14
|
|
142 |
msgid ""
|
|
143 |
"SPAM\\n" |
|
144 |
"HAM\\n" |
|
145 |
"EGG\\n" |
|
146 |
msgstr ""\n |
|
147 |
''') |