238
237
def test_option_without_help(self):
239
238
opt = option.Option("helpless")
240
self.assertEqual(b"", self.pot_from_option(opt))
239
self.assertEqual("", self.pot_from_option(opt))
242
241
def test_option_with_help(self):
243
242
opt = option.Option("helpful", help="Info.")
244
self.assertContainsString(self.pot_from_option(opt), b"\n"
245
b"# help of 'helpful' test\n"
246
b"msgid \"Info.\"\n")
243
self.assertContainsString(self.pot_from_option(opt), "\n"
244
"# help of 'helpful' test\n"
248
247
def test_option_hidden(self):
249
248
opt = option.Option("hidden", help="Unseen.", hidden=True)
250
self.assertEqual(b"", self.pot_from_option(opt))
249
self.assertEqual("", self.pot_from_option(opt))
252
251
def test_option_context_missing(self):
253
252
context = export_pot._ModuleContext("remote.py", 3)
254
253
opt = option.Option("metaphor", help="Not a literal in the source.")
255
254
self.assertContainsString(self.pot_from_option(opt, context),
257
b"# help of 'metaphor' test\n")
256
"# help of 'metaphor' test\n")
259
258
def test_option_context_string(self):
261
260
context = export_pot._ModuleContext("local.py", 3, ({}, {s: 17}))
262
261
opt = option.Option("example", help=s)
263
262
self.assertContainsString(self.pot_from_option(opt, context),
265
b"# help of 'example' test\n")
264
"# help of 'example' test\n")
267
266
def test_registry_option_title(self):
268
267
opt = option.RegistryOption.from_kwargs("group", help="Pick one.",
270
269
pot = self.pot_from_option(opt)
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")
270
self.assertContainsString(pot, "\n"
271
"# title of 'group' test\n"
272
"msgid \"Choose!\"\n")
273
self.assertContainsString(pot, "\n"
274
"# help of 'group' test\n"
275
"msgid \"Pick one.\"\n")
278
277
def test_registry_option_title_context_missing(self):
279
278
context = export_pot._ModuleContext("theory.py", 3)
280
279
opt = option.RegistryOption.from_kwargs("abstract", title="Unfounded!")
281
280
self.assertContainsString(self.pot_from_option(opt, context),
283
b"# title of 'abstract' test\n")
282
"# title of 'abstract' test\n")
285
284
def test_registry_option_title_context_string(self):
287
286
context = export_pot._ModuleContext("practice.py", 3, ({}, {s: 144}))
288
287
opt = option.RegistryOption.from_kwargs("concrete", title=s)
289
288
self.assertContainsString(self.pot_from_option(opt, context),
290
b"#: practice.py:144\n"
291
b"# title of 'concrete' test\n")
289
"#: practice.py:144\n"
290
"# title of 'concrete' test\n")
293
292
def test_registry_option_value_switches(self):
294
293
opt = option.RegistryOption.from_kwargs("switch", help="Flip one.",
295
294
value_switches=True, enum_switch=False,
296
295
red="Big.", green="Small.")
297
296
pot = self.pot_from_option(opt)
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")
297
self.assertContainsString(pot, "\n"
298
"# help of 'switch' test\n"
299
"msgid \"Flip one.\"\n")
300
self.assertContainsString(pot, "\n"
301
"# help of 'switch=red' test\n"
303
self.assertContainsString(pot, "\n"
304
"# help of 'switch=green' test\n"
305
"msgid \"Small.\"\n")
308
307
def test_registry_option_value_switches_hidden(self):
309
308
reg = registry.Registry()
314
313
opt = option.RegistryOption("protocol", "Talking.", reg,
315
314
value_switches=True, enum_switch=False)
316
315
pot = self.pot_from_option(opt)
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'")
316
self.assertContainsString(pot, "\n"
317
"# help of 'protocol' test\n"
318
"msgid \"Talking.\"\n")
319
self.assertContainsString(pot, "\n"
320
"# help of 'protocol=new' test\n"
321
"msgid \"Current.\"\n")
322
self.assertNotContainsString(pot, "'protocol=old'")
326
325
class TestPotExporter(tests.TestCase):
329
328
# This test duplicates test_duplicates below
330
329
def test_duplicates(self):
331
exporter = export_pot._PotExporter(BytesIO())
330
exporter = export_pot._PotExporter(StringIO())
332
331
context = export_pot._ModuleContext("mod.py", 1)
333
332
exporter.poentry_in_context(context, "Common line.")
334
333
context.lineno = 3
335
334
exporter.poentry_in_context(context, "Common line.")
336
self.assertEqual(1, exporter.outf.getvalue().count(b"Common line."))
335
self.assertEqual(1, exporter.outf.getvalue().count("Common line."))
338
337
def test_duplicates_included(self):
339
exporter = export_pot._PotExporter(BytesIO(), True)
338
exporter = export_pot._PotExporter(StringIO(), True)
340
339
context = export_pot._ModuleContext("mod.py", 1)
341
340
exporter.poentry_in_context(context, "Common line.")
342
341
context.lineno = 3
343
342
exporter.poentry_in_context(context, "Common line.")
344
self.assertEqual(2, exporter.outf.getvalue().count(b"Common line."))
343
self.assertEqual(2, exporter.outf.getvalue().count("Common line."))
347
346
class PoEntryTestCase(tests.TestCase):
350
349
super(PoEntryTestCase, self).setUp()
351
self.exporter = export_pot._PotExporter(BytesIO())
350
self.exporter = export_pot._PotExporter(StringIO())
353
352
def check_output(self, expected):
354
353
self.assertEqual(
355
354
self.exporter.outf.getvalue(),
356
textwrap.dedent(expected.decode('utf-8')).encode('utf-8')
355
textwrap.dedent(expected)