File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
531561def test_open_binary_file_rejects_string_subclass_fspath_results ():
532562 class _PathLike :
533563 class _PathString (str ):
You can’t perform that action at this time.
0 commit comments