Skip to content
Myr

Prevent multiline error message on invalid path (#2728)

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

authored by David Lord · committed by GitHub · parents e88c112, 38c0579 · Browse files · 3 files+16 added−1 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+16 added−1 removed

  • tests:+12 added−0 removed
  • other:+4 added−1 removed

3 files+16 added−1 removed

modified:src/click/types.py+1 added-1 removed
890 unmodified lines
891 ctx,892 )893 if not self.dir_okay and stat.S_ISDIR(st.st_mode):894 self.fail(895 _("{name} '{filename}' is a directory.").format(895 _("{name} {filename!r} is a directory.").format(896 name=self.name.title(), filename=format_filename(value)897 ),898 param,899 ctx,
191 unmodified lines
modified:tests/test_types.py+12 added
1import os.path2import pathlib3import platform4import tempfile56import pytest7
224 unmodified lines
232233def test_file_error_surrogates():234 message = FileError(filename="\udcff").format_message()235 assert message == "Could not open file '�': unknown error"236237238@pytest.mark.skipif(239 platform.system() == "Windows", reason="Filepath syntax differences."240)241def test_invalid_path_with_esc_sequence():242 with pytest.raises(click.BadParameter) as exc_info:243 with tempfile.TemporaryDirectory(prefix="my\ndir") as tempdir:244 click.Path(dir_okay=False).convert(tempdir, None, None)245246 assert "my\\ndir" in exc_info.value.message
modified:CHANGES.rst+3 added
4 unmodified lines
56Unreleased78- Fix an issue with type hints for ``click.open_file()``. :issue:`2717`9- Fix issue where error message for invalid ``click.Path`` displays on10 multiple lines. :issue:`2697`111213Version 8.1.714-------------1516Released 2023-08-17
1100 unmodified lines