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
Provenance
- Commit
18400b2- Tree
18d9ae2- Author
Edward G <edward.g2013@gmail.com>- Committer
Edward G <edward.g2013@gmail.com>- Parent
1103c5c
3 files changed+61 added−59 removed
added:tests/test_utils_2/test_format_filename.py+9 added
1+import click2+3+4+def 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
1+from decimal import Decimal2+from fractions import Fraction3+4+from click._utils import UNSET5+6+7+def test_unset_sentinel():8+ value = UNSET9+10+ 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 True16+17+ # 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+ )47+48+ for real_value in real_values:49+ assert value != real_value50+ assert value is not real_value51+52+ assert value not in real_valuesmodified:tests/test_utils.py-59 removed
1 import os2 import pathlib3 import stat4-from decimal import Decimal5-from fractions import Fraction4 5 import pytest6 7 import click._termui_impl8 import click.utils9 from click._compat import WIN12-from click._utils import UNSET10 11 15-def test_unset_sentinel():16- value = UNSET17-18- 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 True24-25- # 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- )55-56- for real_value in real_values:57- assert value != real_value58- assert value is not real_value59-60- assert value not in real_values61-62-63-def 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"69-70-12 def test_open_file(runner):13 @click.command()14 @click.argument("filename")15 def cli(filename):199 unmodified lines