Skip to content
Myr

Add format_filename and sentinel files.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Edward G · committed by Edward G · parent 1103c5c · Browse files · 3 files+61 added−59 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+61 added−59 removed

  • tests:+61 added−59 removed

3 files+61 added−59 removed

added:tests/test_utils_2/test_format_filename.py+9 added
1import click234def test_filename_formatting():5 assert click.format_filename(b"foo.txt") == "foo.txt"6 assert click.format_filename(b"/x/foo.txt") == "/x/foo.txt"7 assert click.format_filename("/x/foo.txt") == "/x/foo.txt"8 assert click.format_filename("/x/foo.txt", shorten=True) == "foo.txt"9 assert click.format_filename("/x/\ufffd.txt", shorten=True) == "�.txt"
added:tests/test_utils_2/test_sentinel.py+52 added
1from decimal import Decimal2from fractions import Fraction34from click._utils import UNSET567def test_unset_sentinel():8 value = UNSET910 assert value11 assert value is UNSET12 assert value == UNSET13 assert repr(value) == "Sentinel.UNSET"14 assert str(value) == "Sentinel.UNSET"15 assert bool(value) is True1617 # Try all native Python values that can be falsy or truthy.18 # See: https://docs.python.org/3/library/stdtypes.html#truth-value-testing19 real_values = (20 None,21 True,22 False,23 0,24 1,25 0.0,26 1.0,27 0j,28 1j,29 Decimal(0),30 Decimal(1),31 Fraction(0, 1),32 Fraction(1, 1),33 "",34 "a",35 "UNSET",36 "Sentinel.UNSET",37 [1],38 (1),39 {1: "a"},40 set(),41 set([1]),42 frozenset(),43 frozenset([1]),44 range(0),45 range(1),46 )4748 for real_value in real_values:49 assert value != real_value50 assert value is not real_value5152 assert value not in real_values
modified:tests/test_utils.py-59 removed
1import os2import pathlib3import stat4from decimal import Decimal5from fractions import Fraction45import pytest67import click._termui_impl8import click.utils9from click._compat import WIN12from click._utils import UNSET101115def test_unset_sentinel():16 value = UNSET1718 assert value19 assert value is UNSET20 assert value == UNSET21 assert repr(value) == "Sentinel.UNSET"22 assert str(value) == "Sentinel.UNSET"23 assert bool(value) is True2425 # Try all native Python values that can be falsy or truthy.26 # See: https://docs.python.org/3/library/stdtypes.html#truth-value-testing27 real_values = (28 None,29 True,30 False,31 0,32 1,33 0.0,34 1.0,35 0j,36 1j,37 Decimal(0),38 Decimal(1),39 Fraction(0, 1),40 Fraction(1, 1),41 "",42 "a",43 "UNSET",44 "Sentinel.UNSET",45 [1],46 (1),47 {1: "a"},48 set(),49 set([1]),50 frozenset(),51 frozenset([1]),52 range(0),53 range(1),54 )5556 for real_value in real_values:57 assert value != real_value58 assert value is not real_value5960 assert value not in real_values616263def test_filename_formatting():64 assert click.format_filename(b"foo.txt") == "foo.txt"65 assert click.format_filename(b"/x/foo.txt") == "/x/foo.txt"66 assert click.format_filename("/x/foo.txt") == "/x/foo.txt"67 assert click.format_filename("/x/foo.txt", shorten=True) == "foo.txt"68 assert click.format_filename("/x/\ufffd.txt", shorten=True) == "�.txt"697012def test_open_file(runner):13 @click.command()14 @click.argument("filename")15 def cli(filename):
199 unmodified lines