Skip to content

Commit 1f15535

Browse files
Test file path display subclass fallback boundaries
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 2784085 commit 1f15535

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/test_file_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ def test_format_file_path_for_error_falls_back_for_non_string_values():
307307
assert format_file_path_for_error(object()) == "<provided path>"
308308

309309

310+
def test_format_file_path_for_error_falls_back_for_string_subclass_values():
311+
class _PathString(str):
312+
pass
313+
314+
assert format_file_path_for_error(_PathString("/tmp/value")) == "<provided path>"
315+
316+
310317
def test_format_file_path_for_error_falls_back_for_fspath_failures():
311318
class _BrokenPathLike:
312319
def __fspath__(self) -> str:
@@ -323,6 +330,17 @@ def __fspath__(self) -> str:
323330
assert format_file_path_for_error(_PathLike()) == "/tmp/path-value"
324331

325332

333+
def test_format_file_path_for_error_falls_back_for_pathlike_string_subclass_values():
334+
class _PathLike:
335+
class _PathString(str):
336+
pass
337+
338+
def __fspath__(self) -> str:
339+
return self._PathString("/tmp/path-value")
340+
341+
assert format_file_path_for_error(_PathLike()) == "<provided path>"
342+
343+
326344
def test_build_open_file_error_message_uses_prefix_and_sanitized_path():
327345
message = build_open_file_error_message(
328346
"bad\tpath.txt",

0 commit comments

Comments
 (0)