Skip to content

Commit 011a998

Browse files
committed
tests: Use Command tests, not Group tests
A click.Group is a subclass of click.Command. Most tests should be for the latter since these will by definition tests the former. Move some tests around so this is the case. Signed-off-by: Stephen Finucane <[email protected]>
1 parent bc20219 commit 011a998

File tree

1 file changed

+77
-101
lines changed

1 file changed

+77
-101
lines changed

tests/test_formatter.py

Lines changed: 77 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,60 @@ def foobar():
356356
'\n'.join(output),
357357
)
358358

359-
def test_no_line_wrapping_epilog(self):
360-
r"""Validate behavior of the \b character in an epilog."""
359+
@unittest.skipIf(
360+
CLICK_VERSION < (8, 1), 'Click < 8.1.0 stores the modified help string'
361+
)
362+
def test_no_truncation(self):
363+
r"""Validate behavior when a \f character is present.
364+
365+
https://click.palletsprojects.com/en/8.1.x/documentation/#truncating-help-texts
366+
"""
367+
368+
@click.command()
369+
def cli():
370+
"""First paragraph.
371+
372+
This is a very long second
373+
paragraph and not correctly
374+
wrapped but it will be rewrapped.
375+
\f
376+
377+
:param click.core.Context ctx: Click context.
378+
"""
379+
pass
380+
381+
ctx = click.Context(cli, info_name='cli')
382+
output = list(ext._format_command(ctx, nested='short'))
383+
384+
# note that we have an extra newline because we're using
385+
# docutils.statemachine.string2lines under the hood, which is
386+
# converting the form feed to a newline
387+
self.assertEqual(
388+
textwrap.dedent(
389+
"""
390+
First paragraph.
391+
392+
This is a very long second
393+
paragraph and not correctly
394+
wrapped but it will be rewrapped.
395+
396+
397+
:param click.core.Context ctx: Click context.
398+
399+
.. program:: cli
400+
.. code-block:: shell
401+
402+
cli [OPTIONS]
403+
"""
404+
).lstrip(),
405+
'\n'.join(output),
406+
)
407+
408+
def test_no_line_wrapping(self):
409+
r"""Validate behavior when a \b character is present.
410+
411+
https://click.palletsprojects.com/en/8.1.x/documentation/#preventing-rewrapping
412+
"""
361413

362414
@click.command(
363415
epilog="""
@@ -372,21 +424,38 @@ def test_no_line_wrapping_epilog(self):
372424
that will be rewrapped again.
373425
"""
374426
)
375-
def foobar():
376-
"""A sample command."""
427+
def cli():
428+
"""A command containing pre-wrapped text.
377429
378-
ctx = click.Context(foobar, info_name='foobar')
430+
\b
431+
This is
432+
a paragraph
433+
without rewrapping.
434+
435+
And this is a paragraph
436+
that will be rewrapped again.
437+
"""
438+
pass
439+
440+
ctx = click.Context(cli, info_name='cli')
379441
output = list(ext._format_command(ctx, nested='short'))
380442

381443
self.assertEqual(
382444
textwrap.dedent(
383445
"""
384-
A sample command.
446+
A command containing pre-wrapped text.
385447
386-
.. program:: foobar
448+
| This is
449+
| a paragraph
450+
| without rewrapping.
451+
452+
And this is a paragraph
453+
that will be rewrapped again.
454+
455+
.. program:: cli
387456
.. code-block:: shell
388457
389-
foobar [OPTIONS]
458+
cli [OPTIONS]
390459
391460
An epilog containing pre-wrapped text.
392461
@@ -493,99 +562,6 @@ def cli():
493562
'\n'.join(output),
494563
)
495564

496-
@unittest.skipIf(
497-
CLICK_VERSION < (8, 1), 'Click < 8.1.0 stores the modified help string'
498-
)
499-
def test_no_truncation(self):
500-
r"""Validate behavior when a \b character is present.
501-
502-
https://click.palletsprojects.com/en/8.1.x/documentation/#truncating-help-texts
503-
"""
504-
505-
@click.group()
506-
def cli():
507-
"""First paragraph.
508-
509-
This is a very long second
510-
paragraph and not correctly
511-
wrapped but it will be rewrapped.
512-
\f
513-
514-
:param click.core.Context ctx: Click context.
515-
"""
516-
pass
517-
518-
ctx = click.Context(cli, info_name='cli')
519-
output = list(ext._format_command(ctx, nested='short'))
520-
521-
# note that we have an extra newline because we're using
522-
# docutils.statemachine.string2lines under the hood, which is
523-
# converting the form feed to a newline
524-
self.assertEqual(
525-
textwrap.dedent(
526-
"""
527-
First paragraph.
528-
529-
This is a very long second
530-
paragraph and not correctly
531-
wrapped but it will be rewrapped.
532-
533-
534-
:param click.core.Context ctx: Click context.
535-
536-
.. program:: cli
537-
.. code-block:: shell
538-
539-
cli [OPTIONS] COMMAND [ARGS]...
540-
"""
541-
).lstrip(),
542-
'\n'.join(output),
543-
)
544-
545-
def test_no_line_wrapping(self):
546-
r"""Validate behavior when a \b character is present.
547-
548-
https://click.palletsprojects.com/en/8.1.x/documentation/#preventing-rewrapping
549-
"""
550-
551-
@click.group()
552-
def cli():
553-
"""A sample command group.
554-
555-
\b
556-
This is
557-
a paragraph
558-
without rewrapping.
559-
560-
And this is a paragraph
561-
that will be rewrapped again.
562-
"""
563-
pass
564-
565-
ctx = click.Context(cli, info_name='cli')
566-
output = list(ext._format_command(ctx, nested='short'))
567-
568-
self.assertEqual(
569-
textwrap.dedent(
570-
"""
571-
A sample command group.
572-
573-
| This is
574-
| a paragraph
575-
| without rewrapping.
576-
577-
And this is a paragraph
578-
that will be rewrapped again.
579-
580-
.. program:: cli
581-
.. code-block:: shell
582-
583-
cli [OPTIONS] COMMAND [ARGS]...
584-
"""
585-
).lstrip(),
586-
'\n'.join(output),
587-
)
588-
589565

590566
class NestedCommandsTestCase(unittest.TestCase):
591567
"""Validate ``click.Command`` instances inside ``click.Group`` instances."""

0 commit comments

Comments
 (0)