From c177f944d95c460803f8a894fd13d4901c3155fe Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 4 May 2021 08:06:36 -0400 Subject: subcmds: force consistent help text format We're inconsistent with help text as to whether it uses title case and whether it ends in a period. Add a test to enforce a standard, and use the style that Python optparse & argparse use themselves (e.g. with the --help option): always lowercase, and never trailing period. Change-Id: Ic1defae23daeac0ac9116aaf487427f50b34050d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/305144 Reviewed-by: Raman Tenneti Tested-by: Mike Frysinger --- tests/test_subcmds.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/test_subcmds.py') diff --git a/tests/test_subcmds.py b/tests/test_subcmds.py index 2234e646..bc53051a 100644 --- a/tests/test_subcmds.py +++ b/tests/test_subcmds.py @@ -14,6 +14,7 @@ """Unittests for the subcmds module (mostly __init__.py than subcommands).""" +import optparse import unittest import subcmds @@ -41,3 +42,32 @@ class AllCommands(unittest.TestCase): # Reject internal python paths like "__init__". self.assertFalse(cmd.startswith('__')) + + def test_help_desc_style(self): + """Force some consistency in option descriptions. + + Python's optparse & argparse has a few default options like --help. Their + option description text uses lowercase sentence fragments, so enforce our + options follow the same style so UI is consistent. + + We enforce: + * Text starts with lowercase. + * Text doesn't end with period. + """ + for name, cls in subcmds.all_commands.items(): + cmd = cls() + parser = cmd.OptionParser + for option in parser.option_list: + if option.help == optparse.SUPPRESS_HELP: + continue + + c = option.help[0] + self.assertEqual( + c.lower(), c, + msg=f'subcmds/{name}.py: {option.get_opt_string()}: help text ' + f'should start with lowercase: "{option.help}"') + + self.assertNotEqual( + option.help[-1], '.', + msg=f'subcmds/{name}.py: {option.get_opt_string()}: help text ' + f'should not end in a period: "{option.help}"') -- cgit v1.2.3-54-g00ecf