@@ -14,11 +14,7 @@ def test_normalize_upload_file_input_returns_path_for_plain_string(tmp_path: Pat
1414 file_path = tmp_path / "file.txt"
1515 file_path .write_text ("content" )
1616
17- normalized_path , file_obj = normalize_upload_file_input (
18- str (file_path ),
19- missing_file_message = f"Upload file not found at path: { file_path } " ,
20- not_file_message = f"Upload file path must point to a file: { file_path } " ,
21- )
17+ normalized_path , file_obj = normalize_upload_file_input (str (file_path ))
2218
2319 assert normalized_path == str (file_path )
2420 assert file_obj is None
@@ -28,11 +24,7 @@ def test_normalize_upload_file_input_returns_path_for_pathlike(tmp_path: Path):
2824 file_path = tmp_path / "file.txt"
2925 file_path .write_text ("content" )
3026
31- normalized_path , file_obj = normalize_upload_file_input (
32- file_path ,
33- missing_file_message = f"Upload file not found at path: { file_path } " ,
34- not_file_message = f"Upload file path must point to a file: { file_path } " ,
35- )
27+ normalized_path , file_obj = normalize_upload_file_input (file_path )
3628
3729 assert normalized_path == str (file_path )
3830 assert file_obj is None
@@ -45,11 +37,7 @@ class _PathString(str):
4537 with pytest .raises (
4638 HyperbrowserError , match = "file_input path must be a plain string path"
4739 ) as exc_info :
48- normalize_upload_file_input (
49- _PathString ("/tmp/file.txt" ), # type: ignore[arg-type]
50- missing_file_message = "Upload file not found at path: /tmp/file.txt" ,
51- not_file_message = "Upload file path must point to a file: /tmp/file.txt" ,
52- )
40+ normalize_upload_file_input (_PathString ("/tmp/file.txt" )) # type: ignore[arg-type]
5341
5442 assert exc_info .value .original_error is None
5543
@@ -62,23 +50,29 @@ def __fspath__(self) -> str:
6250 with pytest .raises (
6351 HyperbrowserError , match = "file_input path is invalid"
6452 ) as exc_info :
65- normalize_upload_file_input (
66- _BrokenPathLike (),
67- missing_file_message = "Upload file not found" ,
68- not_file_message = "Upload file path must point to a file" ,
69- )
53+ normalize_upload_file_input (_BrokenPathLike ())
7054
7155 assert isinstance (exc_info .value .original_error , RuntimeError )
7256
7357
58+ def test_normalize_upload_file_input_uses_fspath_path_in_missing_file_errors ():
59+ class _StringifyFailingPathLike (PathLike [str ]):
60+ def __fspath__ (self ) -> str :
61+ return "/tmp/nonexistent-path-for-upload-utils-test"
62+
63+ def __str__ (self ) -> str :
64+ raise RuntimeError ("broken stringify" )
65+
66+ with pytest .raises (HyperbrowserError , match = "Upload file not found at path: /tmp/nonexistent-path-for-upload-utils-test" ) as exc_info :
67+ normalize_upload_file_input (_StringifyFailingPathLike ())
68+
69+ assert exc_info .value .original_error is None
70+
71+
7472def test_normalize_upload_file_input_returns_open_file_like_object ():
7573 file_obj = io .BytesIO (b"content" )
7674
77- normalized_path , normalized_file_obj = normalize_upload_file_input (
78- file_obj ,
79- missing_file_message = "Upload file not found" ,
80- not_file_message = "Upload file path must point to a file" ,
81- )
75+ normalized_path , normalized_file_obj = normalize_upload_file_input (file_obj )
8276
8377 assert normalized_path is None
8478 assert normalized_file_obj is file_obj
@@ -89,19 +83,11 @@ def test_normalize_upload_file_input_rejects_closed_file_like_object():
8983 file_obj .close ()
9084
9185 with pytest .raises (HyperbrowserError , match = "file-like object must be open" ):
92- normalize_upload_file_input (
93- file_obj ,
94- missing_file_message = "Upload file not found" ,
95- not_file_message = "Upload file path must point to a file" ,
96- )
86+ normalize_upload_file_input (file_obj )
9787
9888
9989def test_normalize_upload_file_input_rejects_non_callable_read_attribute ():
10090 fake_file = type ("FakeFile" , (), {"read" : "not-callable" })()
10191
10292 with pytest .raises (HyperbrowserError , match = "file_input must be a file path" ):
103- normalize_upload_file_input (
104- fake_file , # type: ignore[arg-type]
105- missing_file_message = "Upload file not found" ,
106- not_file_message = "Upload file path must point to a file" ,
107- )
93+ normalize_upload_file_input (fake_file ) # type: ignore[arg-type]
0 commit comments