diff options
Diffstat (limited to 'tests/test_subcmds.py')
-rw-r--r-- | tests/test_subcmds.py | 86 |
1 files changed, 45 insertions, 41 deletions
diff --git a/tests/test_subcmds.py b/tests/test_subcmds.py index bc53051a..73b66e3f 100644 --- a/tests/test_subcmds.py +++ b/tests/test_subcmds.py | |||
@@ -21,53 +21,57 @@ import subcmds | |||
21 | 21 | ||
22 | 22 | ||
23 | class AllCommands(unittest.TestCase): | 23 | class AllCommands(unittest.TestCase): |
24 | """Check registered all_commands.""" | 24 | """Check registered all_commands.""" |
25 | 25 | ||
26 | def test_required_basic(self): | 26 | def test_required_basic(self): |
27 | """Basic checking of registered commands.""" | 27 | """Basic checking of registered commands.""" |
28 | # NB: We don't test all subcommands as we want to avoid "change detection" | 28 | # NB: We don't test all subcommands as we want to avoid "change |
29 | # tests, so we just look for the most common/important ones here that are | 29 | # detection" tests, so we just look for the most common/important ones |
30 | # unlikely to ever change. | 30 | # here that are unlikely to ever change. |
31 | for cmd in {'cherry-pick', 'help', 'init', 'start', 'sync', 'upload'}: | 31 | for cmd in {"cherry-pick", "help", "init", "start", "sync", "upload"}: |
32 | self.assertIn(cmd, subcmds.all_commands) | 32 | self.assertIn(cmd, subcmds.all_commands) |
33 | 33 | ||
34 | def test_naming(self): | 34 | def test_naming(self): |
35 | """Verify we don't add things that we shouldn't.""" | 35 | """Verify we don't add things that we shouldn't.""" |
36 | for cmd in subcmds.all_commands: | 36 | for cmd in subcmds.all_commands: |
37 | # Reject filename suffixes like "help.py". | 37 | # Reject filename suffixes like "help.py". |
38 | self.assertNotIn('.', cmd) | 38 | self.assertNotIn(".", cmd) |
39 | 39 | ||
40 | # Make sure all '_' were converted to '-'. | 40 | # Make sure all '_' were converted to '-'. |
41 | self.assertNotIn('_', cmd) | 41 | self.assertNotIn("_", cmd) |
42 | 42 | ||
43 | # Reject internal python paths like "__init__". | 43 | # Reject internal python paths like "__init__". |
44 | self.assertFalse(cmd.startswith('__')) | 44 | self.assertFalse(cmd.startswith("__")) |
45 | 45 | ||
46 | def test_help_desc_style(self): | 46 | def test_help_desc_style(self): |
47 | """Force some consistency in option descriptions. | 47 | """Force some consistency in option descriptions. |
48 | 48 | ||
49 | Python's optparse & argparse has a few default options like --help. Their | 49 | Python's optparse & argparse has a few default options like --help. |
50 | option description text uses lowercase sentence fragments, so enforce our | 50 | Their option description text uses lowercase sentence fragments, so |
51 | options follow the same style so UI is consistent. | 51 | enforce our options follow the same style so UI is consistent. |
52 | 52 | ||
53 | We enforce: | 53 | We enforce: |
54 | * Text starts with lowercase. | 54 | * Text starts with lowercase. |
55 | * Text doesn't end with period. | 55 | * Text doesn't end with period. |
56 | """ | 56 | """ |
57 | for name, cls in subcmds.all_commands.items(): | 57 | for name, cls in subcmds.all_commands.items(): |
58 | cmd = cls() | 58 | cmd = cls() |
59 | parser = cmd.OptionParser | 59 | parser = cmd.OptionParser |
60 | for option in parser.option_list: | 60 | for option in parser.option_list: |
61 | if option.help == optparse.SUPPRESS_HELP: | 61 | if option.help == optparse.SUPPRESS_HELP: |
62 | continue | 62 | continue |
63 | 63 | ||
64 | c = option.help[0] | 64 | c = option.help[0] |
65 | self.assertEqual( | 65 | self.assertEqual( |
66 | c.lower(), c, | 66 | c.lower(), |
67 | msg=f'subcmds/{name}.py: {option.get_opt_string()}: help text ' | 67 | c, |
68 | f'should start with lowercase: "{option.help}"') | 68 | msg=f"subcmds/{name}.py: {option.get_opt_string()}: " |
69 | f'help text should start with lowercase: "{option.help}"', | ||
70 | ) | ||
69 | 71 | ||
70 | self.assertNotEqual( | 72 | self.assertNotEqual( |
71 | option.help[-1], '.', | 73 | option.help[-1], |
72 | msg=f'subcmds/{name}.py: {option.get_opt_string()}: help text ' | 74 | ".", |
73 | f'should not end in a period: "{option.help}"') | 75 | msg=f"subcmds/{name}.py: {option.get_opt_string()}: " |
76 | f'help text should not end in a period: "{option.help}"', | ||
77 | ) | ||