Skip to content

Commit 3ba18bc

Browse files
Add open_binary_file fspath error regression tests
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 8073e94 commit 3ba18bc

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/test_file_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,36 @@ def test_open_binary_file_rejects_non_string_fspath_results():
528528
pass
529529

530530

531+
def test_open_binary_file_wraps_fspath_runtime_errors():
532+
class _BrokenPathLike:
533+
def __fspath__(self) -> str:
534+
raise RuntimeError("bad fspath")
535+
536+
with pytest.raises(HyperbrowserError, match="file_path is invalid") as exc_info:
537+
with open_binary_file(
538+
_BrokenPathLike(), # type: ignore[arg-type]
539+
open_error_message="open failed",
540+
):
541+
pass
542+
543+
assert exc_info.value.original_error is not None
544+
545+
546+
def test_open_binary_file_preserves_hyperbrowser_fspath_errors():
547+
class _BrokenPathLike:
548+
def __fspath__(self) -> str:
549+
raise HyperbrowserError("custom fspath failure")
550+
551+
with pytest.raises(HyperbrowserError, match="custom fspath failure") as exc_info:
552+
with open_binary_file(
553+
_BrokenPathLike(), # type: ignore[arg-type]
554+
open_error_message="open failed",
555+
):
556+
pass
557+
558+
assert exc_info.value.original_error is None
559+
560+
531561
def test_open_binary_file_rejects_string_subclass_fspath_results():
532562
class _PathLike:
533563
class _PathString(str):

0 commit comments

Comments
 (0)