Skip to content

Commit

Permalink
tests: Add tests for MultiCommand
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Apr 26, 2018
1 parent d571fa2 commit f9e79a0
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,55 @@ def test_order_of_commands(self):
A sample command.
""").lstrip(), '\n'.join(output))


class CustomMultCommandTestCase(unittest.TestCase):
def test_basics(self):
"""Validate a custom ``click.MultiCommand`` with no parameters.
This exercises the code paths to extract commands correctly from these
commands.
"""

@click.command()
def hello():
"""A sample command."""

@click.command()
def world():
"""A world command."""

class MyCLI(click.MultiCommand):
_command_mapping = {
'hello': hello,
'world': world,
}
def list_commands(self, ctx):
return ['hello', 'world']

def get_command(self, ctx, name):
return self._command_mapping[name]

cli = MyCLI(help='A sample custom multicommand.')
ctx = click.Context(cli, info_name='cli')
output = list(ext._format_command(ctx, show_nested=False))

self.assertEqual(
textwrap.dedent("""
A sample custom multicommand.
.. program:: cli
.. code-block:: shell
cli [OPTIONS] COMMAND [ARGS]...
.. rubric:: Commands
.. object:: hello
A sample command.
.. object:: world
A world command.
""").lstrip(), '\n'.join(output))

0 comments on commit f9e79a0

Please sign in to comment.