~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_export_pot.py

  • Committer: Martin Packman
  • Date: 2011-11-24 11:49:43 UTC
  • mto: This revision was merged to the branch mainline in revision 6305.
  • Revision ID: martin.packman@canonical.com-20111124114943-3z7kt7icx0b8yjjm
Export registry help to pot for unhidden option value switches

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib import (
21
21
    commands,
22
22
    export_pot,
 
23
    option,
 
24
    registry,
23
25
    tests,
24
26
    )
25
27
 
221
223
        self.assertContainsRe(self.get_log(), "String 'not there' not found")
222
224
 
223
225
 
 
226
class TestWriteOption(tests.TestCase):
 
227
    """Tests for writing texts extracted from options in pot format"""
 
228
 
 
229
    def pot_from_option(self, opt, context=None, note="test"):
 
230
        sio = StringIO()
 
231
        exporter = export_pot._PotExporter(sio)
 
232
        if context is None:
 
233
            context = export_pot._ModuleContext("nowhere", 0)
 
234
        export_pot._write_option(exporter, context, opt, note)
 
235
        return sio.getvalue()
 
236
 
 
237
    def test_option_without_help(self):
 
238
        opt = option.Option("helpless")
 
239
        self.assertEqual("", self.pot_from_option(opt))
 
240
 
 
241
    def test_option_with_help(self):
 
242
        opt = option.Option("helpful", help="Info.")
 
243
        self.assertContainsString(self.pot_from_option(opt), "\n"
 
244
            "# help of 'helpful' test\n"
 
245
            "msgid \"Info.\"\n")
 
246
 
 
247
    def test_option_hidden(self):
 
248
        opt = option.Option("hidden", help="Unseen.", hidden=True)
 
249
        self.assertEqual("", self.pot_from_option(opt))
 
250
 
 
251
    def test_option_context_missing(self):
 
252
        context = export_pot._ModuleContext("remote.py", 3)
 
253
        opt = option.Option("metaphor", help="Not a literal in the source.")
 
254
        self.assertContainsString(self.pot_from_option(opt, context),
 
255
            "#: remote.py:3\n"
 
256
            "# help of 'metaphor' test\n")
 
257
 
 
258
    def test_option_context_string(self):
 
259
        s = "Literally."
 
260
        context = export_pot._ModuleContext("local.py", 3, ({}, {s: 17}))
 
261
        opt = option.Option("example", help=s)
 
262
        self.assertContainsString(self.pot_from_option(opt, context),
 
263
            "#: local.py:17\n"
 
264
            "# help of 'example' test\n")
 
265
 
 
266
    def test_registry_option_title(self):
 
267
        opt = option.RegistryOption.from_kwargs("group", help="Pick one.",
 
268
            title="Choose!")
 
269
        pot = self.pot_from_option(opt)
 
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")
 
276
 
 
277
    def test_registry_option_title_context_missing(self):
 
278
        context = export_pot._ModuleContext("theory.py", 3)
 
279
        opt = option.RegistryOption.from_kwargs("abstract", title="Unfounded!")
 
280
        self.assertContainsString(self.pot_from_option(opt, context),
 
281
            "#: theory.py:3\n"
 
282
            "# title of 'abstract' test\n")
 
283
 
 
284
    def test_registry_option_title_context_string(self):
 
285
        s = "Grounded!"
 
286
        context = export_pot._ModuleContext("practice.py", 3, ({}, {s: 144}))
 
287
        opt = option.RegistryOption.from_kwargs("concrete", title=s)
 
288
        self.assertContainsString(self.pot_from_option(opt, context),
 
289
            "#: practice.py:144\n"
 
290
            "# title of 'concrete' test\n")
 
291
 
 
292
    def test_registry_option_value_switches(self):
 
293
        opt = option.RegistryOption.from_kwargs("switch", help="Flip one.",
 
294
            value_switches=True, enum_switch=False,
 
295
            red="Big.", green="Small.")
 
296
        pot = self.pot_from_option(opt)
 
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"
 
302
            "msgid \"Big.\"\n")
 
303
        self.assertContainsString(pot, "\n"
 
304
            "# help of 'switch=green' test\n"
 
305
            "msgid \"Small.\"\n")
 
306
 
 
307
    def test_registry_option_value_switches_hidden(self):
 
308
        reg = registry.Registry()
 
309
        class Hider(object):
 
310
            hidden = True
 
311
        reg.register("new", 1, "Current.")
 
312
        reg.register("old", 0, "Legacy.", info=Hider())
 
313
        opt = option.RegistryOption("protocol", "Talking.", reg,
 
314
            value_switches=True, enum_switch=False)
 
315
        pot = self.pot_from_option(opt)
 
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'")
 
323
 
 
324
 
224
325
class PoEntryTestCase(tests.TestCase):
225
326
 
226
327
    def setUp(self):