diff options
Diffstat (limited to 'tests/test_subcmds.py')
| -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}"') | ||
