/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2011, 2016 Canonical Ltd
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
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
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
17
import re
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
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
20
from io import StringIO
21
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from .. import (
5875.3.20 by INADA Naoki
Add test for exporting command help.
23
    commands,
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
24
    export_pot,
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
25
    option,
26
    registry,
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
27
    tests,
28
    )
5875.3.20 by INADA Naoki
Add test for exporting command help.
29
30
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
31
class TestEscape(tests.TestCase):
32
33
    def test_simple_escape(self):
34
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
35
            export_pot._escape('foobar'),
36
            'foobar')
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
37
38
        s = '''foo\nbar\r\tbaz\\"spam"'''
39
        e = '''foo\\nbar\\r\\tbaz\\\\\\"spam\\"'''
40
        self.assertEqual(export_pot._escape(s), e)
41
42
    def test_complex_escape(self):
43
        s = '''\\r \\\n'''
44
        e = '''\\\\r \\\\\\n'''
45
        self.assertEqual(export_pot._escape(s), e)
46
47
48
class TestNormalize(tests.TestCase):
49
50
    def test_single_line(self):
51
        s = 'foobar'
52
        e = '"foobar"'
53
        self.assertEqual(export_pot._normalize(s), e)
54
55
        s = 'foo"bar'
56
        e = '"foo\\"bar"'
57
        self.assertEqual(export_pot._normalize(s), e)
58
59
    def test_multi_lines(self):
60
        s = 'foo\nbar\n'
61
        e = '""\n"foo\\n"\n"bar\\n"'
62
        self.assertEqual(export_pot._normalize(s), e)
63
64
        s = '\nfoo\nbar\n'
65
        e = ('""\n'
66
             '"\\n"\n'
67
             '"foo\\n"\n'
68
             '"bar\\n"')
69
        self.assertEqual(export_pot._normalize(s), e)
70
71
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
72
class TestParseSource(tests.TestCase):
73
    """Check mappings to line numbers generated from python source"""
74
75
    def test_classes(self):
76
        src = '''
77
class Ancient:
78
    """Old style class"""
79
80
class Modern(object):
81
    """New style class"""
82
'''
83
        cls_lines, _ = export_pot._parse_source(src)
84
        self.assertEqual(cls_lines,
7143.15.2 by Jelmer Vernooij
Run autopep8.
85
                         {"Ancient": 2, "Modern": 5})
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
86
87
    def test_classes_nested(self):
88
        src = '''
89
class Matroska(object):
90
    class Smaller(object):
91
        class Smallest(object):
92
            pass
93
'''
94
        cls_lines, _ = export_pot._parse_source(src)
95
        self.assertEqual(cls_lines,
7143.15.2 by Jelmer Vernooij
Run autopep8.
96
                         {"Matroska": 2, "Smaller": 3, "Smallest": 4})
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
97
98
    def test_strings_docstrings(self):
99
        src = '''\
100
"""Module"""
101
102
def function():
103
    """Function"""
104
105
class Class(object):
106
    """Class"""
107
108
    def method(self):
109
        """Method"""
110
'''
111
        _, str_lines = export_pot._parse_source(src)
112
        self.assertEqual(str_lines,
7143.15.2 by Jelmer Vernooij
Run autopep8.
113
                         {"Module": 1, "Function": 4, "Class": 7, "Method": 10})
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
114
115
    def test_strings_literals(self):
116
        src = '''\
117
s = "One"
118
t = (2, "Two")
119
f = dict(key="Three")
120
'''
121
        _, str_lines = export_pot._parse_source(src)
122
        self.assertEqual(str_lines,
7143.15.2 by Jelmer Vernooij
Run autopep8.
123
                         {"One": 1, "Two": 2, "Three": 3})
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
124
125
    def test_strings_multiline(self):
126
        src = '''\
127
"""Start
128
129
End
130
"""
131
t = (
132
    "A"
133
    "B"
134
    "C"
135
    )
136
'''
137
        _, str_lines = export_pot._parse_source(src)
138
        self.assertEqual(str_lines,
7143.15.2 by Jelmer Vernooij
Run autopep8.
139
                         {"Start\n\nEnd\n": 1, "ABC": 6})
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
140
141
    def test_strings_multiline_escapes(self):
142
        src = '''\
143
s = "Escaped\\n"
144
r = r"Raw\\n"
145
t = (
146
    "A\\n\\n"
147
    "B\\n\\n"
148
    "C\\n\\n"
149
    )
150
'''
151
        _, str_lines = export_pot._parse_source(src)
152
        self.expectFailure("Escaped newlines confuses the multiline handling",
7143.15.2 by Jelmer Vernooij
Run autopep8.
153
                           self.assertNotEqual, str_lines,
154
                           {"Escaped\n": 0, "Raw\\n": 2, "A\n\nB\n\nC\n\n": -2})
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
155
        self.assertEqual(str_lines,
7143.15.2 by Jelmer Vernooij
Run autopep8.
156
                         {"Escaped\n": 1, "Raw\\n": 2, "A\n\nB\n\nC\n\n": 4})
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
157
158
159
class TestModuleContext(tests.TestCase):
160
    """Checks for source context tracking objects"""
161
162
    def check_context(self, context, path, lineno):
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
163
        self.assertEqual((context.path, context.lineno), (path, lineno))
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
164
165
    def test___init__(self):
166
        context = export_pot._ModuleContext("one.py")
167
        self.check_context(context, "one.py", 1)
168
        context = export_pot._ModuleContext("two.py", 5)
169
        self.check_context(context, "two.py", 5)
170
171
    def test_from_class(self):
172
        """New context returned with lineno updated from class"""
173
        path = "cls.py"
7143.15.2 by Jelmer Vernooij
Run autopep8.
174
175
        class A(object):
176
            pass
177
178
        class B(object):
179
            pass
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
180
        cls_lines = {"A": 5, "B": 7}
181
        context = export_pot._ModuleContext(path, _source_info=(cls_lines, {}))
182
        contextA = context.from_class(A)
183
        self.check_context(contextA, path, 5)
184
        contextB1 = context.from_class(B)
185
        self.check_context(contextB1, path, 7)
186
        contextB2 = contextA.from_class(B)
187
        self.check_context(contextB2, path, 7)
188
        self.check_context(context, path, 1)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
189
        self.assertEqual("", self.get_log())
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
190
191
    def test_from_class_missing(self):
192
        """When class has no lineno the old context details are returned"""
193
        path = "cls_missing.py"
7143.15.2 by Jelmer Vernooij
Run autopep8.
194
195
        class A(object):
196
            pass
197
198
        class M(object):
199
            pass
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
200
        context = export_pot._ModuleContext(path, 3, ({"A": 15}, {}))
201
        contextA = context.from_class(A)
202
        contextM1 = context.from_class(M)
203
        self.check_context(contextM1, path, 3)
204
        contextM2 = contextA.from_class(M)
205
        self.check_context(contextM2, path, 15)
206
        self.assertContainsRe(self.get_log(), "Definition of <.*M'> not found")
207
208
    def test_from_string(self):
209
        """New context returned with lineno updated from string"""
210
        path = "str.py"
211
        str_lines = {"one": 14, "two": 42}
212
        context = export_pot._ModuleContext(path, _source_info=({}, str_lines))
213
        context1 = context.from_string("one")
214
        self.check_context(context1, path, 14)
215
        context2A = context.from_string("two")
216
        self.check_context(context2A, path, 42)
217
        context2B = context1.from_string("two")
218
        self.check_context(context2B, path, 42)
219
        self.check_context(context, path, 1)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
220
        self.assertEqual("", self.get_log())
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
221
222
    def test_from_string_missing(self):
223
        """When string has no lineno the old context details are returned"""
224
        path = "str_missing.py"
225
        context = export_pot._ModuleContext(path, 4, ({}, {"line\n": 21}))
226
        context1 = context.from_string("line\n")
227
        context2A = context.from_string("not there")
228
        self.check_context(context2A, path, 4)
229
        context2B = context1.from_string("not there")
230
        self.check_context(context2B, path, 21)
7008.2.2 by Martin
Fix regressed tests and add to python3.passing
231
        self.assertContainsRe(self.get_log(), "String b?'not there' not found")
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
232
233
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
234
class TestWriteOption(tests.TestCase):
235
    """Tests for writing texts extracted from options in pot format"""
236
237
    def pot_from_option(self, opt, context=None, note="test"):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
238
        sio = StringIO()
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
239
        exporter = export_pot._PotExporter(sio)
240
        if context is None:
241
            context = export_pot._ModuleContext("nowhere", 0)
242
        export_pot._write_option(exporter, context, opt, note)
243
        return sio.getvalue()
244
245
    def test_option_without_help(self):
246
        opt = option.Option("helpless")
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
247
        self.assertEqual("", self.pot_from_option(opt))
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
248
249
    def test_option_with_help(self):
250
        opt = option.Option("helpful", help="Info.")
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
251
        self.assertContainsString(self.pot_from_option(opt), "\n"
7143.15.2 by Jelmer Vernooij
Run autopep8.
252
                                  "# help of 'helpful' test\n"
253
                                  "msgid \"Info.\"\n")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
254
255
    def test_option_hidden(self):
256
        opt = option.Option("hidden", help="Unseen.", hidden=True)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
257
        self.assertEqual("", self.pot_from_option(opt))
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
258
259
    def test_option_context_missing(self):
260
        context = export_pot._ModuleContext("remote.py", 3)
261
        opt = option.Option("metaphor", help="Not a literal in the source.")
262
        self.assertContainsString(self.pot_from_option(opt, context),
7143.15.2 by Jelmer Vernooij
Run autopep8.
263
                                  "#: remote.py:3\n"
264
                                  "# help of 'metaphor' test\n")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
265
266
    def test_option_context_string(self):
267
        s = "Literally."
268
        context = export_pot._ModuleContext("local.py", 3, ({}, {s: 17}))
269
        opt = option.Option("example", help=s)
270
        self.assertContainsString(self.pot_from_option(opt, context),
7143.15.2 by Jelmer Vernooij
Run autopep8.
271
                                  "#: local.py:17\n"
272
                                  "# help of 'example' test\n")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
273
274
    def test_registry_option_title(self):
275
        opt = option.RegistryOption.from_kwargs("group", help="Pick one.",
7143.15.2 by Jelmer Vernooij
Run autopep8.
276
                                                title="Choose!")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
277
        pot = self.pot_from_option(opt)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
278
        self.assertContainsString(pot, "\n"
7143.15.2 by Jelmer Vernooij
Run autopep8.
279
                                  "# title of 'group' test\n"
280
                                  "msgid \"Choose!\"\n")
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
281
        self.assertContainsString(pot, "\n"
7143.15.2 by Jelmer Vernooij
Run autopep8.
282
                                  "# help of 'group' test\n"
283
                                  "msgid \"Pick one.\"\n")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
284
285
    def test_registry_option_title_context_missing(self):
286
        context = export_pot._ModuleContext("theory.py", 3)
287
        opt = option.RegistryOption.from_kwargs("abstract", title="Unfounded!")
288
        self.assertContainsString(self.pot_from_option(opt, context),
7143.15.2 by Jelmer Vernooij
Run autopep8.
289
                                  "#: theory.py:3\n"
290
                                  "# title of 'abstract' test\n")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
291
292
    def test_registry_option_title_context_string(self):
293
        s = "Grounded!"
294
        context = export_pot._ModuleContext("practice.py", 3, ({}, {s: 144}))
295
        opt = option.RegistryOption.from_kwargs("concrete", title=s)
296
        self.assertContainsString(self.pot_from_option(opt, context),
7143.15.2 by Jelmer Vernooij
Run autopep8.
297
                                  "#: practice.py:144\n"
298
                                  "# title of 'concrete' test\n")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
299
300
    def test_registry_option_value_switches(self):
301
        opt = option.RegistryOption.from_kwargs("switch", help="Flip one.",
7143.15.2 by Jelmer Vernooij
Run autopep8.
302
                                                value_switches=True, enum_switch=False,
303
                                                red="Big.", green="Small.")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
304
        pot = self.pot_from_option(opt)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
305
        self.assertContainsString(pot, "\n"
7143.15.2 by Jelmer Vernooij
Run autopep8.
306
                                  "# help of 'switch' test\n"
307
                                  "msgid \"Flip one.\"\n")
308
        self.assertContainsString(pot, "\n"
309
                                  "# help of 'switch=red' test\n"
310
                                  "msgid \"Big.\"\n")
311
        self.assertContainsString(pot, "\n"
312
                                  "# help of 'switch=green' test\n"
313
                                  "msgid \"Small.\"\n")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
314
315
    def test_registry_option_value_switches_hidden(self):
316
        reg = registry.Registry()
7143.15.2 by Jelmer Vernooij
Run autopep8.
317
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
318
        class Hider(object):
319
            hidden = True
320
        reg.register("new", 1, "Current.")
321
        reg.register("old", 0, "Legacy.", info=Hider())
322
        opt = option.RegistryOption("protocol", "Talking.", reg,
7143.15.2 by Jelmer Vernooij
Run autopep8.
323
                                    value_switches=True, enum_switch=False)
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
324
        pot = self.pot_from_option(opt)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
325
        self.assertContainsString(pot, "\n"
7143.15.2 by Jelmer Vernooij
Run autopep8.
326
                                  "# help of 'protocol' test\n"
327
                                  "msgid \"Talking.\"\n")
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
328
        self.assertContainsString(pot, "\n"
7143.15.2 by Jelmer Vernooij
Run autopep8.
329
                                  "# help of 'protocol=new' test\n"
330
                                  "msgid \"Current.\"\n")
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
331
        self.assertNotContainsString(pot, "'protocol=old'")
6282.2.3 by Martin Packman
Export registry help to pot for unhidden option value switches
332
333
6351.2.1 by Martin Packman
Add export-pot --include-duplicates option for permitting multiple entries with the same msgid
334
class TestPotExporter(tests.TestCase):
335
    """Test for logic specific to the _PotExporter class"""
336
337
    # This test duplicates test_duplicates below
338
    def test_duplicates(self):
7027.3.7 by Jelmer Vernooij
drop broken tests.
339
        exporter = export_pot._PotExporter(StringIO())
6351.2.1 by Martin Packman
Add export-pot --include-duplicates option for permitting multiple entries with the same msgid
340
        context = export_pot._ModuleContext("mod.py", 1)
7027.3.7 by Jelmer Vernooij
drop broken tests.
341
        exporter.poentry_in_context(context, "Common line.")
6351.2.1 by Martin Packman
Add export-pot --include-duplicates option for permitting multiple entries with the same msgid
342
        context.lineno = 3
7027.3.7 by Jelmer Vernooij
drop broken tests.
343
        exporter.poentry_in_context(context, "Common line.")
344
        self.assertEqual(1, exporter.outf.getvalue().count("Common line."))
6973.11.1 by Jelmer Vernooij
Fix export_pot.
345
6351.2.1 by Martin Packman
Add export-pot --include-duplicates option for permitting multiple entries with the same msgid
346
    def test_duplicates_included(self):
7027.3.7 by Jelmer Vernooij
drop broken tests.
347
        exporter = export_pot._PotExporter(StringIO(), True)
6351.2.1 by Martin Packman
Add export-pot --include-duplicates option for permitting multiple entries with the same msgid
348
        context = export_pot._ModuleContext("mod.py", 1)
7027.3.7 by Jelmer Vernooij
drop broken tests.
349
        exporter.poentry_in_context(context, "Common line.")
6351.2.1 by Martin Packman
Add export-pot --include-duplicates option for permitting multiple entries with the same msgid
350
        context.lineno = 3
7027.3.7 by Jelmer Vernooij
drop broken tests.
351
        exporter.poentry_in_context(context, "Common line.")
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
352
        self.assertEqual(2, exporter.outf.getvalue().count("Common line."))
6351.2.1 by Martin Packman
Add export-pot --include-duplicates option for permitting multiple entries with the same msgid
353
354
5830.2.20 by INADA Naoki
Add test for _poentry_per_peragraph()
355
class PoEntryTestCase(tests.TestCase):
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
356
357
    def setUp(self):
5830.2.20 by INADA Naoki
Add test for _poentry_per_peragraph()
358
        super(PoEntryTestCase, self).setUp()
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
359
        self.exporter = export_pot._PotExporter(StringIO())
5830.2.20 by INADA Naoki
Add test for _poentry_per_peragraph()
360
361
    def check_output(self, expected):
362
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
363
            self.exporter.outf.getvalue(),
364
            textwrap.dedent(expected)
365
            )
5830.2.20 by INADA Naoki
Add test for _poentry_per_peragraph()
366
6282.2.2 by Martin Packman
Add export_pot._ModuleContext class for more structured source location tracking, and share option writing logic
367
5830.2.20 by INADA Naoki
Add test for _poentry_per_peragraph()
368
class TestPoEntry(PoEntryTestCase):
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
369
370
    def test_simple(self):
6282.2.1 by Martin Packman
Add export_pot._PotExporter class to avoid module global, and other minor cleanups
371
        self.exporter.poentry('dummy', 1, "spam")
372
        self.exporter.poentry('dummy', 2, "ham", 'EGG')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
373
        self.check_output('''\
5830.2.20 by INADA Naoki
Add test for _poentry_per_peragraph()
374
                #: dummy:1
375
                msgid "spam"
376
                msgstr ""
377
378
                #: dummy:2
379
                # EGG
380
                msgid "ham"
381
                msgstr ""
382
383
                ''')
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
384
385
    def test_duplicate(self):
6282.2.1 by Martin Packman
Add export_pot._PotExporter class to avoid module global, and other minor cleanups
386
        self.exporter.poentry('dummy', 1, "spam")
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
387
        # This should be ignored.
6282.2.1 by Martin Packman
Add export_pot._PotExporter class to avoid module global, and other minor cleanups
388
        self.exporter.poentry('dummy', 2, "spam", 'EGG')
5830.2.18 by INADA Naoki
Add some tests for export_pot module.
389
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
390
        self.check_output('''\
5830.2.20 by INADA Naoki
Add test for _poentry_per_peragraph()
391
                #: dummy:1
392
                msgid "spam"
393
                msgstr ""\n
394
                ''')
395
396
397
class TestPoentryPerPergraph(PoEntryTestCase):
398
399
    def test_single(self):
6282.2.1 by Martin Packman
Add export_pot._PotExporter class to avoid module global, and other minor cleanups
400
        self.exporter.poentry_per_paragraph(
7143.15.2 by Jelmer Vernooij
Run autopep8.
401
            'dummy',
402
            10,
403
            '''foo\nbar\nbaz\n'''
404
            )
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
405
        self.check_output('''\
5830.2.20 by INADA Naoki
Add test for _poentry_per_peragraph()
406
                #: dummy:10
407
                msgid ""
408
                "foo\\n"
409
                "bar\\n"
410
                "baz\\n"
411
                msgstr ""\n
412
                ''')
413
414
    def test_multi(self):
6282.2.1 by Martin Packman
Add export_pot._PotExporter class to avoid module global, and other minor cleanups
415
        self.exporter.poentry_per_paragraph(
7143.15.2 by Jelmer Vernooij
Run autopep8.
416
            'dummy',
417
            10,
418
            '''spam\nham\negg\n\nSPAM\nHAM\nEGG\n'''
419
            )
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
420
        self.check_output('''\
5830.2.20 by INADA Naoki
Add test for _poentry_per_peragraph()
421
                #: dummy:10
422
                msgid ""
423
                "spam\\n"
424
                "ham\\n"
425
                "egg"
426
                msgstr ""
427
428
                #: dummy:14
429
                msgid ""
430
                "SPAM\\n"
431
                "HAM\\n"
432
                "EGG\\n"
433
                msgstr ""\n
434
                ''')
5875.3.20 by INADA Naoki
Add test for exporting command help.
435
436
437
class TestExportCommandHelp(PoEntryTestCase):
438
439
    def test_command_help(self):
440
441
        class cmd_Demo(commands.Command):
442
            __doc__ = """A sample command.
443
444
            :Usage:
445
                bzr demo
446
447
            :Examples:
448
                Example 1::
449
450
                    cmd arg1
451
452
            Blah Blah Blah
453
            """
454
6282.2.1 by Martin Packman
Add export_pot._PotExporter class to avoid module global, and other minor cleanups
455
        export_pot._write_command_help(self.exporter, cmd_Demo())
456
        result = self.exporter.outf.getvalue()
5993.1.2 by Vincent Ladeuil
Fix python2.6 compatibility.
457
        # We don't care about filename and lineno here.
7027.3.7 by Jelmer Vernooij
drop broken tests.
458
        result = re.sub(r'(?m)^#: [^\n]+\n', '', result)
5875.3.20 by INADA Naoki
Add test for exporting command help.
459
460
        self.assertEqualDiff(
7143.15.2 by Jelmer Vernooij
Run autopep8.
461
            'msgid "A sample command."\n'
462
            'msgstr ""\n'
463
            '\n'                # :Usage: should not be translated.
464
            'msgid ""\n'
465
            '":Examples:\\n"\n'
466
            '"    Example 1::"\n'
467
            'msgstr ""\n'
468
            '\n'
469
            'msgid "        cmd arg1"\n'
470
            'msgstr ""\n'
471
            '\n'
472
            'msgid "Blah Blah Blah"\n'
473
            'msgstr ""\n'
474
            '\n',
475
            result
476
            )