151
151
_, str_lines = export_pot._parse_source(src)
152
152
self.expectFailure("Escaped newlines confuses the multiline handling",
153
self.assertNotEqual, str_lines,
154
{"Escaped\n": 0, "Raw\\n": 2, "A\n\nB\n\nC\n\n": -2})
153
self.assertNotEqual, str_lines,
154
{"Escaped\n": 0, "Raw\\n": 2, "A\n\nB\n\nC\n\n": -2})
155
155
self.assertEqual(str_lines,
156
{"Escaped\n": 1, "Raw\\n": 2, "A\n\nB\n\nC\n\n": 4})
156
{"Escaped\n": 1, "Raw\\n": 2, "A\n\nB\n\nC\n\n": 4})
159
159
class TestModuleContext(tests.TestCase):
252
260
context = export_pot._ModuleContext("remote.py", 3)
253
261
opt = option.Option("metaphor", help="Not a literal in the source.")
254
262
self.assertContainsString(self.pot_from_option(opt, context),
256
"# help of 'metaphor' test\n")
264
"# help of 'metaphor' test\n")
258
266
def test_option_context_string(self):
260
268
context = export_pot._ModuleContext("local.py", 3, ({}, {s: 17}))
261
269
opt = option.Option("example", help=s)
262
270
self.assertContainsString(self.pot_from_option(opt, context),
264
"# help of 'example' test\n")
272
"# help of 'example' test\n")
266
274
def test_registry_option_title(self):
267
275
opt = option.RegistryOption.from_kwargs("group", help="Pick one.",
269
277
pot = self.pot_from_option(opt)
270
278
self.assertContainsString(pot, "\n"
271
"# title of 'group' test\n"
272
"msgid \"Choose!\"\n")
279
"# title of 'group' test\n"
280
"msgid \"Choose!\"\n")
273
281
self.assertContainsString(pot, "\n"
274
"# help of 'group' test\n"
275
"msgid \"Pick one.\"\n")
282
"# help of 'group' test\n"
283
"msgid \"Pick one.\"\n")
277
285
def test_registry_option_title_context_missing(self):
278
286
context = export_pot._ModuleContext("theory.py", 3)
279
287
opt = option.RegistryOption.from_kwargs("abstract", title="Unfounded!")
280
288
self.assertContainsString(self.pot_from_option(opt, context),
282
"# title of 'abstract' test\n")
290
"# title of 'abstract' test\n")
284
292
def test_registry_option_title_context_string(self):
286
294
context = export_pot._ModuleContext("practice.py", 3, ({}, {s: 144}))
287
295
opt = option.RegistryOption.from_kwargs("concrete", title=s)
288
296
self.assertContainsString(self.pot_from_option(opt, context),
289
"#: practice.py:144\n"
290
"# title of 'concrete' test\n")
297
"#: practice.py:144\n"
298
"# title of 'concrete' test\n")
292
300
def test_registry_option_value_switches(self):
293
301
opt = option.RegistryOption.from_kwargs("switch", help="Flip one.",
294
value_switches=True, enum_switch=False,
295
red="Big.", green="Small.")
302
value_switches=True, enum_switch=False,
303
red="Big.", green="Small.")
296
304
pot = self.pot_from_option(opt)
297
305
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")
306
"# help of 'switch' test\n"
307
"msgid \"Flip one.\"\n")
308
self.assertContainsString(pot, "\n"
309
"# help of 'switch=red' test\n"
311
self.assertContainsString(pot, "\n"
312
"# help of 'switch=green' test\n"
313
"msgid \"Small.\"\n")
307
315
def test_registry_option_value_switches_hidden(self):
308
316
reg = registry.Registry()
309
318
class Hider(object):
311
320
reg.register("new", 1, "Current.")
312
321
reg.register("old", 0, "Legacy.", info=Hider())
313
322
opt = option.RegistryOption("protocol", "Talking.", reg,
314
value_switches=True, enum_switch=False)
323
value_switches=True, enum_switch=False)
315
324
pot = self.pot_from_option(opt)
316
325
self.assertContainsString(pot, "\n"
317
"# help of 'protocol' test\n"
318
"msgid \"Talking.\"\n")
326
"# help of 'protocol' test\n"
327
"msgid \"Talking.\"\n")
319
328
self.assertContainsString(pot, "\n"
320
"# help of 'protocol=new' test\n"
321
"msgid \"Current.\"\n")
329
"# help of 'protocol=new' test\n"
330
"msgid \"Current.\"\n")
322
331
self.assertNotContainsString(pot, "'protocol=old'")