Skip to content

Commit f9e79a0

Browse files
committed
tests: Add tests for MultiCommand
Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent d571fa2 commit f9e79a0

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tests/test_formatter.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,55 @@ def test_order_of_commands(self):
200200
201201
A sample command.
202202
""").lstrip(), '\n'.join(output))
203+
204+
205+
class CustomMultCommandTestCase(unittest.TestCase):
206+
def test_basics(self):
207+
"""Validate a custom ``click.MultiCommand`` with no parameters.
208+
209+
This exercises the code paths to extract commands correctly from these
210+
commands.
211+
"""
212+
213+
@click.command()
214+
def hello():
215+
"""A sample command."""
216+
217+
@click.command()
218+
def world():
219+
"""A world command."""
220+
221+
class MyCLI(click.MultiCommand):
222+
_command_mapping = {
223+
'hello': hello,
224+
'world': world,
225+
}
226+
def list_commands(self, ctx):
227+
return ['hello', 'world']
228+
229+
def get_command(self, ctx, name):
230+
return self._command_mapping[name]
231+
232+
cli = MyCLI(help='A sample custom multicommand.')
233+
ctx = click.Context(cli, info_name='cli')
234+
output = list(ext._format_command(ctx, show_nested=False))
235+
236+
self.assertEqual(
237+
textwrap.dedent("""
238+
A sample custom multicommand.
239+
240+
.. program:: cli
241+
.. code-block:: shell
242+
243+
cli [OPTIONS] COMMAND [ARGS]...
244+
245+
.. rubric:: Commands
246+
247+
.. object:: hello
248+
249+
A sample command.
250+
251+
.. object:: world
252+
253+
A world command.
254+
""").lstrip(), '\n'.join(output))

0 commit comments

Comments
 (0)