ctdb-scripts: Improve update and listing code
[samba4-gss.git] / python / samba / tests / samba_tool / help.py
blob16eb6b74c5d3c1c298b4067a195029473748804f
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Catalyst IT Ltd 2017.
4 # Originally written by Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 import re
21 from samba.tests.samba_tool.base import SambaToolCmdTest
22 from samba.tests import BlackboxProcessError
23 from samba.tests import check_help_consistency
24 from samba.common import get_string
27 class HelpTestCase(SambaToolCmdTest):
28 """Tests for samba-tool help and --help
30 We test for consistency and lack of crashes."""
32 def _find_sub_commands(self, args):
33 self.runcmd(*args)
35 def test_help_tree(self):
36 # we call actual subprocesses, because we are probing the
37 # actual help output where there is no sub-command. Don't copy
38 # this if you have an actual command: for that use
39 # self.runcmd() or self.runsubcmd().
40 known_commands = [[]]
41 failed_commands = []
43 for i in range(4):
44 new_commands = []
45 for c in known_commands:
46 line = ' '.join(['samba-tool'] + c + ['--help'])
47 try:
48 output = self.check_output(line)
49 except BlackboxProcessError as e:
50 output = e.stdout
51 failed_commands.append(c)
52 output = get_string(output)
53 tail = output.partition('Available subcommands:')[2]
54 subcommands = re.findall(r'^\s*([\w-]+)\s+-', tail,
55 re.MULTILINE)
56 for s in subcommands:
57 new_commands.append(c + [s])
59 # check that `samba-tool help X Y` == `samba-tool X Y --help`
60 line = ' '.join(['samba-tool', 'help'] + c)
61 try:
62 output2 = self.check_output(line)
63 except BlackboxProcessError as e:
64 output2 = e.stdout
65 failed_commands.append(c)
67 output2 = get_string(output2)
68 self.assertEqual(output, output2)
70 err = check_help_consistency(output,
71 options_start='Options:',
72 options_end='Available subcommands:')
73 if err is not None:
74 self.fail("consistency error with %s:\n%s" % (line, err))
76 if not new_commands:
77 break
79 known_commands = new_commands
81 self.assertEqual(failed_commands, [])
83 def test_bad_password_option(self):
84 """Do we get a warning with an invalid --pass option?"""
85 (result, out, err) = self.run_command(["samba-tool",
86 "processes",
87 "--pass-the-salt-please",
88 "pleeease"])
89 self.assertIn("if '--pass-the-salt-please' is not misspelt", err)
90 self.assertIn("the appropriate list in is_password_option", err)