Skip to content

Commit

Permalink
Add test for truncation
Browse files Browse the repository at this point in the history
Thanks to [1], this now "just works". Demonstrate that with a test.

[1] pallets/click#2151

Signed-off-by: Stephen Finucane <[email protected]>
Closes: #56
  • Loading branch information
stephenfin committed Apr 7, 2022
1 parent c0242ee commit d0552d1
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import click
from sphinx_click import ext

CLICK_VERSION = tuple(int(x) for x in click.__version__.split('.')[0:2])


class CommandTestCase(unittest.TestCase):
"""Validate basic ``click.Command`` instances."""
Expand Down Expand Up @@ -482,10 +484,59 @@ def cli():
'\n'.join(output),
)

@unittest.skipIf(
CLICK_VERSION < (8, 1), 'Click < 8.1.0 stores the modified help string'
)
def test_no_truncation(self):
r"""Validate behavior when a \b character is present.
https://click.palletsprojects.com/en/8.1.x/documentation/#truncating-help-texts
"""

@click.group()
def cli():
"""First paragraph.
This is a very long second
paragraph and not correctly
wrapped but it will be rewrapped.
\f
:param click.core.Context ctx: Click context.
"""
pass

ctx = click.Context(cli, info_name='cli')
output = list(ext._format_command(ctx, nested='short'))

# note that we have an extra newline because we're using
# docutils.statemachine.string2lines under the hood, which is
# converting the form feed to a newline
self.assertEqual(
textwrap.dedent(
"""
First paragraph.
This is a very long second
paragraph and not correctly
wrapped but it will be rewrapped.
:param click.core.Context ctx: Click context.
.. program:: cli
.. code-block:: shell
cli [OPTIONS] COMMAND [ARGS]...
"""
).lstrip(),
'\n'.join(output),
)

def test_no_line_wrapping(self):
r"""Validate behavior when a \b character is present.
https://click.palletsprojects.com/en/7.x/documentation/#preventing-rewrapping
https://click.palletsprojects.com/en/8.1.x/documentation/#preventing-rewrapping
"""

@click.group()
Expand Down

0 comments on commit d0552d1

Please sign in to comment.