Skip to content
Myr

test_make_default_short_help.py

This file

Path

tests/test_utils/test_make_default_short_help.py

63 lines · 2.3 KiB · Python

Last changed by

Merge stable into main (#3876)Rowlando13before adoption3cbaa76

History of this file

Take it

1import pytest23import click456@pytest.mark.parametrize(7    ("value", "max_length", "expect"),8    [9        pytest.param("", 10, "", id="empty"),10        pytest.param("123 567 90", 10, "123 567 90", id="equal length, no dot"),11        pytest.param("123 567 9. Aaaa bbb", 10, "123 567 9.", id="sentence < max"),12        pytest.param("123 567 9.", 10, "123 567 9.", id="dot ends text"),13        pytest.param("123 567\n\n 9. aaaa bbb", 10, "123 567", id="paragraph < max"),14        pytest.param("123 567 90123.", 10, "123 567...", id="truncate"),15        pytest.param("123 5678 xxxxxx", 10, "123...", id="length includes suffix"),16        pytest.param(17            "token in ~/.netrc ciao ciao",18            20,19            "token in ~/.netrc...",20            id="ignore dot in word",21        ),22        pytest.param(23            "Weigh apples vs. pears.",24            30,25            "Weigh apples vs. pears.",26            id="abbreviation inside sentence",27        ),28        pytest.param(29            "Weigh apples vs. pears and plums.",30            20,31            "Weigh apples vs....",32            id="abbreviation inside truncated sentence",33        ),34        pytest.param("123 567 9. aaaa bbb", 10, "123 567...", id="lowercase after dot"),35        pytest.param(36            "Pick a fruit. 3 remain.", 20, "Pick a fruit.", id="digit after dot"37        ),38        pytest.param("well-behaved.", 8, "...", id="never split a hyphenated word"),39        pytest.param("supercalifragilistic", 10, "...", id="never split a long word"),40        pytest.param("ab cd", 3, "...", id="width fits the suffix only"),41        pytest.param("ab cd", 2, "...", id="width below the suffix"),42        pytest.param("ab", 2, "ab", id="text shorter than the suffix"),43        pytest.param("ab cd", -1, "...", id="negative width"),44    ],45)46@pytest.mark.parametrize(47    "alter",48    [49        pytest.param(None, id=""),50        pytest.param(51            lambda text: "\n\b\n" + "  ".join(text.split(" ")) + "\n", id="no-wrap mark"52        ),53    ],54)55def test_make_default_short_help(value, max_length, alter, expect):56    # A width too narrow for the suffix still returns the whole suffix.57    assert len(expect) <= max(max_length, len("..."))5859    if alter:60        value = alter(value)6162    out = click.utils._make_default_short_help(value, max_length)63    assert out == expect