Rev 6305: (gz) Include registry value switch help text in translation template (Martin in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Nov 25 18:14:47 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6305 [merge]
revision-id: pqm at pqm.ubuntu.com-20111125181446-mwg1kfaj9ir4r9ku
parent: pqm at pqm.ubuntu.com-20111125174944-cwzx7kzwxgw9a0u7
parent: martin.packman at canonical.com-20111124114943-3z7kt7icx0b8yjjm
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2011-11-25 18:14:46 +0000
message:
(gz) Include registry value switch help text in translation template (Martin
Packman)
modified:
bzrlib/export_pot.py bzrgettext-20110429104643-3wjy38532whc21yj-2
bzrlib/tests/test_export_pot.py test_export_pot.py-20110509102137-efovgz233s9uk2b2-1
=== modified file 'bzrlib/export_pot.py'
--- a/bzrlib/export_pot.py 2011-11-22 18:48:16 +0000
+++ b/bzrlib/export_pot.py 2011-11-24 11:49:43 +0000
@@ -180,12 +180,18 @@
def _write_option(exporter, context, opt, note):
if getattr(opt, 'hidden', False):
return
+ optname = opt.name
if getattr(opt, 'title', None):
exporter.poentry_in_context(context, opt.title,
- "title of {name!r} {what}".format(name=opt.name, what=note))
- if getattr(opt, 'help', None):
- exporter.poentry_in_context(context, opt.help,
- "help of {name!r} {what}".format(name=opt.name, what=note))
+ "title of {name!r} {what}".format(name=optname, what=note))
+ for name, _, _, helptxt in opt.iter_switches():
+ if name != optname:
+ if opt.is_hidden(name):
+ continue
+ name = "=".join([optname, name])
+ if helptxt:
+ exporter.poentry_in_context(context, helptxt,
+ "help of {name!r} {what}".format(name=name, what=note))
def _standard_options(exporter):
=== modified file 'bzrlib/tests/test_export_pot.py'
--- a/bzrlib/tests/test_export_pot.py 2011-11-22 18:48:16 +0000
+++ b/bzrlib/tests/test_export_pot.py 2011-11-24 11:49:43 +0000
@@ -20,6 +20,8 @@
from bzrlib import (
commands,
export_pot,
+ option,
+ registry,
tests,
)
@@ -221,6 +223,105 @@
self.assertContainsRe(self.get_log(), "String 'not there' not found")
+class TestWriteOption(tests.TestCase):
+ """Tests for writing texts extracted from options in pot format"""
+
+ def pot_from_option(self, opt, context=None, note="test"):
+ sio = StringIO()
+ exporter = export_pot._PotExporter(sio)
+ if context is None:
+ context = export_pot._ModuleContext("nowhere", 0)
+ export_pot._write_option(exporter, context, opt, note)
+ return sio.getvalue()
+
+ def test_option_without_help(self):
+ opt = option.Option("helpless")
+ self.assertEqual("", self.pot_from_option(opt))
+
+ def test_option_with_help(self):
+ opt = option.Option("helpful", help="Info.")
+ self.assertContainsString(self.pot_from_option(opt), "\n"
+ "# help of 'helpful' test\n"
+ "msgid \"Info.\"\n")
+
+ def test_option_hidden(self):
+ opt = option.Option("hidden", help="Unseen.", hidden=True)
+ self.assertEqual("", self.pot_from_option(opt))
+
+ def test_option_context_missing(self):
+ context = export_pot._ModuleContext("remote.py", 3)
+ opt = option.Option("metaphor", help="Not a literal in the source.")
+ self.assertContainsString(self.pot_from_option(opt, context),
+ "#: remote.py:3\n"
+ "# help of 'metaphor' test\n")
+
+ def test_option_context_string(self):
+ s = "Literally."
+ context = export_pot._ModuleContext("local.py", 3, ({}, {s: 17}))
+ opt = option.Option("example", help=s)
+ self.assertContainsString(self.pot_from_option(opt, context),
+ "#: local.py:17\n"
+ "# help of 'example' test\n")
+
+ def test_registry_option_title(self):
+ opt = option.RegistryOption.from_kwargs("group", help="Pick one.",
+ title="Choose!")
+ pot = self.pot_from_option(opt)
+ self.assertContainsString(pot, "\n"
+ "# title of 'group' test\n"
+ "msgid \"Choose!\"\n")
+ self.assertContainsString(pot, "\n"
+ "# help of 'group' test\n"
+ "msgid \"Pick one.\"\n")
+
+ def test_registry_option_title_context_missing(self):
+ context = export_pot._ModuleContext("theory.py", 3)
+ opt = option.RegistryOption.from_kwargs("abstract", title="Unfounded!")
+ self.assertContainsString(self.pot_from_option(opt, context),
+ "#: theory.py:3\n"
+ "# title of 'abstract' test\n")
+
+ def test_registry_option_title_context_string(self):
+ s = "Grounded!"
+ context = export_pot._ModuleContext("practice.py", 3, ({}, {s: 144}))
+ opt = option.RegistryOption.from_kwargs("concrete", title=s)
+ self.assertContainsString(self.pot_from_option(opt, context),
+ "#: practice.py:144\n"
+ "# title of 'concrete' test\n")
+
+ def test_registry_option_value_switches(self):
+ opt = option.RegistryOption.from_kwargs("switch", help="Flip one.",
+ value_switches=True, enum_switch=False,
+ red="Big.", green="Small.")
+ pot = self.pot_from_option(opt)
+ self.assertContainsString(pot, "\n"
+ "# help of 'switch' test\n"
+ "msgid \"Flip one.\"\n")
+ self.assertContainsString(pot, "\n"
+ "# help of 'switch=red' test\n"
+ "msgid \"Big.\"\n")
+ self.assertContainsString(pot, "\n"
+ "# help of 'switch=green' test\n"
+ "msgid \"Small.\"\n")
+
+ def test_registry_option_value_switches_hidden(self):
+ reg = registry.Registry()
+ class Hider(object):
+ hidden = True
+ reg.register("new", 1, "Current.")
+ reg.register("old", 0, "Legacy.", info=Hider())
+ opt = option.RegistryOption("protocol", "Talking.", reg,
+ value_switches=True, enum_switch=False)
+ pot = self.pot_from_option(opt)
+ self.assertContainsString(pot, "\n"
+ "# help of 'protocol' test\n"
+ "msgid \"Talking.\"\n")
+ self.assertContainsString(pot, "\n"
+ "# help of 'protocol=new' test\n"
+ "msgid \"Current.\"\n")
+ self.assertNotContainsString(pot, "'protocol=old'")
+
+
class PoEntryTestCase(tests.TestCase):
def setUp(self):
More information about the bazaar-commits
mailing list