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))
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"
244
self.assertContainsString(self.pot_from_option(opt), b"\n"
245
b"# help of 'helpful' test\n"
246
b"msgid \"Info.\"\n")
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),
257
"# help of 'metaphor' test\n")
257
b"# help of 'metaphor' test\n")
259
259
def test_option_context_string(self):
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),
265
"# help of 'example' test\n")
265
b"# help of 'example' test\n")
267
267
def test_registry_option_title(self):
268
268
opt = option.RegistryOption.from_kwargs("group", help="Pick one.",
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")
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),
283
"# title of 'abstract' test\n")
283
b"# title of 'abstract' test\n")
285
285
def test_registry_option_title_context_string(self):
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")
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"
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"
304
self.assertContainsString(pot, b"\n"
305
b"# help of 'switch=green' test\n"
306
b"msgid \"Small.\"\n")
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'")
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."))
336
self.assertEqual(1, exporter.outf.getvalue().count(b"Common line."))
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."))
347
347
class PoEntryTestCase(tests.TestCase):
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)
452
452
self.assertEqualDiff(
453
'msgid "A sample command."\n'
455
'\n' # :Usage: should not be translated.
461
'msgid " cmd arg1"\n'
464
'msgid "Blah Blah Blah"\n'
453
b'msgid "A sample command."\n'
455
b'\n' # :Usage: should not be translated.
461
b'msgid " cmd arg1"\n'
464
b'msgid "Blah Blah Blah"\n'