diff options
| author | Mike Frysinger <vapier@google.com> | 2021-05-04 08:06:36 -0400 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2021-05-04 16:40:53 +0000 |
| commit | c177f944d95c460803f8a894fd13d4901c3155fe (patch) | |
| tree | 1645c1bcf6e2cd304600ebc1f5193a0edf329429 /tests | |
| parent | aedd1e5ef015fba194681e167edf460c21a1c980 (diff) | |
| download | git-repo-c177f944d95c460803f8a894fd13d4901c3155fe.tar.gz | |
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 <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_subcmds.py | 30 |
1 files changed, 30 insertions, 0 deletions
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 @@ | |||
| 14 | 14 | ||
| 15 | """Unittests for the subcmds module (mostly __init__.py than subcommands).""" | 15 | """Unittests for the subcmds module (mostly __init__.py than subcommands).""" |
| 16 | 16 | ||
| 17 | import optparse | ||
| 17 | import unittest | 18 | import unittest |
| 18 | 19 | ||
| 19 | import subcmds | 20 | import subcmds |
| @@ -41,3 +42,32 @@ class AllCommands(unittest.TestCase): | |||
| 41 | 42 | ||
| 42 | # Reject internal python paths like "__init__". | 43 | # Reject internal python paths like "__init__". |
| 43 | self.assertFalse(cmd.startswith('__')) | 44 | self.assertFalse(cmd.startswith('__')) |
| 45 | |||
| 46 | def test_help_desc_style(self): | ||
| 47 | """Force some consistency in option descriptions. | ||
| 48 | |||
| 49 | Python's optparse & argparse has a few default options like --help. Their | ||
| 50 | option description text uses lowercase sentence fragments, so enforce our | ||
| 51 | options follow the same style so UI is consistent. | ||
| 52 | |||
| 53 | We enforce: | ||
| 54 | * Text starts with lowercase. | ||
| 55 | * Text doesn't end with period. | ||
| 56 | """ | ||
| 57 | for name, cls in subcmds.all_commands.items(): | ||
| 58 | cmd = cls() | ||
| 59 | parser = cmd.OptionParser | ||
| 60 | for option in parser.option_list: | ||
| 61 | if option.help == optparse.SUPPRESS_HELP: | ||
| 62 | continue | ||
| 63 | |||
| 64 | c = option.help[0] | ||
| 65 | self.assertEqual( | ||
| 66 | c.lower(), c, | ||
| 67 | msg=f'subcmds/{name}.py: {option.get_opt_string()}: help text ' | ||
| 68 | f'should start with lowercase: "{option.help}"') | ||
| 69 | |||
| 70 | self.assertNotEqual( | ||
| 71 | option.help[-1], '.', | ||
| 72 | msg=f'subcmds/{name}.py: {option.get_opt_string()}: help text ' | ||
| 73 | f'should not end in a period: "{option.help}"') | ||
