/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_export_pot.py

  • Committer: Martin
  • Date: 2018-06-30 22:18:39 UTC
  • mfrom: (7010 work)
  • mto: This revision was merged to the branch mainline in revision 7012.
  • Revision ID: gzlist@googlemail.com-20180630221839-98zi78xwcggestse
Merge trunk to fix conflict

Show diffs side-by-side

added added

removed removed

Lines of Context:
237
237
 
238
238
    def test_option_without_help(self):
239
239
        opt = option.Option("helpless")
240
 
        self.assertEqual("", self.pot_from_option(opt))
 
240
        self.assertEqual(b"", self.pot_from_option(opt))
241
241
 
242
242
    def test_option_with_help(self):
243
243
        opt = option.Option("helpful", help="Info.")
244
 
        self.assertContainsString(self.pot_from_option(opt), "\n"
245
 
            "# help of 'helpful' test\n"
246
 
            "msgid \"Info.\"\n")
 
244
        self.assertContainsString(self.pot_from_option(opt), b"\n"
 
245
            b"# help of 'helpful' test\n"
 
246
            b"msgid \"Info.\"\n")
247
247
 
248
248
    def test_option_hidden(self):
249
249
        opt = option.Option("hidden", help="Unseen.", hidden=True)
253
253
        context = export_pot._ModuleContext("remote.py", 3)
254
254
        opt = option.Option("metaphor", help="Not a literal in the source.")
255
255
        self.assertContainsString(self.pot_from_option(opt, context),
256
 
            "#: remote.py:3\n"
257
 
            "# help of 'metaphor' test\n")
 
256
            b"#: remote.py:3\n"
 
257
            b"# help of 'metaphor' test\n")
258
258
 
259
259
    def test_option_context_string(self):
260
260
        s = "Literally."
261
261
        context = export_pot._ModuleContext("local.py", 3, ({}, {s: 17}))
262
262
        opt = option.Option("example", help=s)
263
263
        self.assertContainsString(self.pot_from_option(opt, context),
264
 
            "#: local.py:17\n"
265
 
            "# help of 'example' test\n")
 
264
            b"#: local.py:17\n"
 
265
            b"# help of 'example' test\n")
266
266
 
267
267
    def test_registry_option_title(self):
268
268
        opt = option.RegistryOption.from_kwargs("group", help="Pick one.",
269
269
            title="Choose!")
270
270
        pot = self.pot_from_option(opt)
271
 
        self.assertContainsString(pot, "\n"
272
 
            "# title of 'group' test\n"
273
 
            "msgid \"Choose!\"\n")
274
 
        self.assertContainsString(pot, "\n"
275
 
            "# help of 'group' test\n"
276
 
            "msgid \"Pick one.\"\n")
 
271
        self.assertContainsString(pot, b"\n"
 
272
            b"# title of 'group' test\n"
 
273
            b"msgid \"Choose!\"\n")
 
274
        self.assertContainsString(pot, b"\n"
 
275
            b"# help of 'group' test\n"
 
276
            b"msgid \"Pick one.\"\n")
277
277
 
278
278
    def test_registry_option_title_context_missing(self):
279
279
        context = export_pot._ModuleContext("theory.py", 3)
280
280
        opt = option.RegistryOption.from_kwargs("abstract", title="Unfounded!")
281
281
        self.assertContainsString(self.pot_from_option(opt, context),
282
 
            "#: theory.py:3\n"
283
 
            "# title of 'abstract' test\n")
 
282
            b"#: theory.py:3\n"
 
283
            b"# title of 'abstract' test\n")
284
284
 
285
285
    def test_registry_option_title_context_string(self):
286
286
        s = "Grounded!"
287
287
        context = export_pot._ModuleContext("practice.py", 3, ({}, {s: 144}))
288
288
        opt = option.RegistryOption.from_kwargs("concrete", title=s)
289
289
        self.assertContainsString(self.pot_from_option(opt, context),
290
 
            "#: practice.py:144\n"
291
 
            "# title of 'concrete' test\n")
 
290
            b"#: practice.py:144\n"
 
291
            b"# title of 'concrete' test\n")
292
292
 
293
293
    def test_registry_option_value_switches(self):
294
294
        opt = option.RegistryOption.from_kwargs("switch", help="Flip one.",
295
295
            value_switches=True, enum_switch=False,
296
296
            red="Big.", green="Small.")
297
297
        pot = self.pot_from_option(opt)
298
 
        self.assertContainsString(pot, "\n"
299
 
            "# help of 'switch' test\n"
300
 
            "msgid \"Flip one.\"\n")
301
 
        self.assertContainsString(pot, "\n"
302
 
            "# help of 'switch=red' test\n"
303
 
            "msgid \"Big.\"\n")
304
 
        self.assertContainsString(pot, "\n"
305
 
            "# help of 'switch=green' test\n"
306
 
            "msgid \"Small.\"\n")
 
298
        self.assertContainsString(pot, b"\n"
 
299
            b"# help of 'switch' test\n"
 
300
            b"msgid \"Flip one.\"\n")
 
301
        self.assertContainsString(pot, b"\n"
 
302
            b"# help of 'switch=red' test\n"
 
303
            b"msgid \"Big.\"\n")
 
304
        self.assertContainsString(pot, b"\n"
 
305
            b"# help of 'switch=green' test\n"
 
306
            b"msgid \"Small.\"\n")
307
307
 
308
308
    def test_registry_option_value_switches_hidden(self):
309
309
        reg = registry.Registry()
314
314
        opt = option.RegistryOption("protocol", "Talking.", reg,
315
315
            value_switches=True, enum_switch=False)
316
316
        pot = self.pot_from_option(opt)
317
 
        self.assertContainsString(pot, "\n"
318
 
            "# help of 'protocol' test\n"
319
 
            "msgid \"Talking.\"\n")
320
 
        self.assertContainsString(pot, "\n"
321
 
            "# help of 'protocol=new' test\n"
322
 
            "msgid \"Current.\"\n")
323
 
        self.assertNotContainsString(pot, "'protocol=old'")
 
317
        self.assertContainsString(pot, b"\n"
 
318
            b"# help of 'protocol' test\n"
 
319
            b"msgid \"Talking.\"\n")
 
320
        self.assertContainsString(pot, b"\n"
 
321
            b"# help of 'protocol=new' test\n"
 
322
            b"msgid \"Current.\"\n")
 
323
        self.assertNotContainsString(pot, b"'protocol=old'")
324
324
 
325
325
 
326
326
class TestPotExporter(tests.TestCase):
333
333
        exporter.poentry_in_context(context, "Common line.")
334
334
        context.lineno = 3
335
335
        exporter.poentry_in_context(context, "Common line.")
336
 
        self.assertEqual(1, exporter.outf.getvalue().count("Common line."))
337
 
    
 
336
        self.assertEqual(1, exporter.outf.getvalue().count(b"Common line."))
 
337
 
338
338
    def test_duplicates_included(self):
339
339
        exporter = export_pot._PotExporter(BytesIO(), True)
340
340
        context = export_pot._ModuleContext("mod.py", 1)
341
341
        exporter.poentry_in_context(context, "Common line.")
342
342
        context.lineno = 3
343
343
        exporter.poentry_in_context(context, "Common line.")
344
 
        self.assertEqual(2, exporter.outf.getvalue().count("Common line."))
 
344
        self.assertEqual(2, exporter.outf.getvalue().count(b"Common line."))
345
345
 
346
346
 
347
347
class PoEntryTestCase(tests.TestCase):
353
353
    def check_output(self, expected):
354
354
        self.assertEqual(
355
355
                self.exporter.outf.getvalue(),
356
 
                textwrap.dedent(expected)
 
356
                textwrap.dedent(expected.decode('utf-8')).encode('utf-8')
357
357
                )
358
358
 
359
359
 
362
362
    def test_simple(self):
363
363
        self.exporter.poentry('dummy', 1, "spam")
364
364
        self.exporter.poentry('dummy', 2, "ham", 'EGG')
365
 
        self.check_output('''\
 
365
        self.check_output(b'''\
366
366
                #: dummy:1
367
367
                msgid "spam"
368
368
                msgstr ""
379
379
        # This should be ignored.
380
380
        self.exporter.poentry('dummy', 2, "spam", 'EGG')
381
381
 
382
 
        self.check_output('''\
 
382
        self.check_output(b'''\
383
383
                #: dummy:1
384
384
                msgid "spam"
385
385
                msgstr ""\n
394
394
                10,
395
395
                '''foo\nbar\nbaz\n'''
396
396
                )
397
 
        self.check_output('''\
 
397
        self.check_output(b'''\
398
398
                #: dummy:10
399
399
                msgid ""
400
400
                "foo\\n"
409
409
                10,
410
410
                '''spam\nham\negg\n\nSPAM\nHAM\nEGG\n'''
411
411
                )
412
 
        self.check_output('''\
 
412
        self.check_output(b'''\
413
413
                #: dummy:10
414
414
                msgid ""
415
415
                "spam\\n"
447
447
        export_pot._write_command_help(self.exporter, cmd_Demo())
448
448
        result = self.exporter.outf.getvalue()
449
449
        # We don't care about filename and lineno here.
450
 
        result = re.sub(r'(?m)^#: [^\n]+\n', '', result)
 
450
        result = re.sub(br'(?m)^#: [^\n]+\n', b'', result)
451
451
 
452
452
        self.assertEqualDiff(
453
 
                'msgid "A sample command."\n'
454
 
                'msgstr ""\n'
455
 
                '\n'                # :Usage: should not be translated.
456
 
                'msgid ""\n'
457
 
                '":Examples:\\n"\n'
458
 
                '"    Example 1::"\n'
459
 
                'msgstr ""\n'
460
 
                '\n'
461
 
                'msgid "        cmd arg1"\n'
462
 
                'msgstr ""\n'
463
 
                '\n'
464
 
                'msgid "Blah Blah Blah"\n'
465
 
                'msgstr ""\n'
466
 
                '\n',
 
453
                b'msgid "A sample command."\n'
 
454
                b'msgstr ""\n'
 
455
                b'\n'                # :Usage: should not be translated.
 
456
                b'msgid ""\n'
 
457
                b'":Examples:\\n"\n'
 
458
                b'"    Example 1::"\n'
 
459
                b'msgstr ""\n'
 
460
                b'\n'
 
461
                b'msgid "        cmd arg1"\n'
 
462
                b'msgstr ""\n'
 
463
                b'\n'
 
464
                b'msgid "Blah Blah Blah"\n'
 
465
                b'msgstr ""\n'
 
466
                b'\n',
467
467
                result
468
468
                )