File tree Expand file tree Collapse file tree
hyperbrowser/client/managers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ async def upload_file(
119119 self ._client ._build_url (f"/session/{ id } /uploads" ),
120120 files = files ,
121121 )
122- elif hasattr ( file_input , "read" ):
122+ elif callable ( getattr ( file_input , "read" , None ) ):
123123 files = {"file" : file_input }
124124 response = await self ._client .transport .post (
125125 self ._client ._build_url (f"/session/{ id } /uploads" ),
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ def upload_file(
111111 self ._client ._build_url (f"/session/{ id } /uploads" ),
112112 files = files ,
113113 )
114- elif hasattr ( file_input , "read" ):
114+ elif callable ( getattr ( file_input , "read" , None ) ):
115115 files = {"file" : file_input }
116116 response = self ._client .transport .post (
117117 self ._client ._build_url (f"/session/{ id } /uploads" ),
Original file line number Diff line number Diff line change @@ -137,3 +137,22 @@ async def run():
137137 await manager .upload_file ("session_123" , 123 ) # type: ignore[arg-type]
138138
139139 asyncio .run (run ())
140+
141+
142+ def test_sync_session_upload_file_rejects_non_callable_read_attribute ():
143+ manager = SyncSessionManager (_FakeClient (_SyncTransport ()))
144+ fake_file = type ("FakeFile" , (), {"read" : "not-callable" })()
145+
146+ with pytest .raises (TypeError , match = "file_input must be a file path" ):
147+ manager .upload_file ("session_123" , fake_file )
148+
149+
150+ def test_async_session_upload_file_rejects_non_callable_read_attribute ():
151+ manager = AsyncSessionManager (_FakeClient (_AsyncTransport ()))
152+ fake_file = type ("FakeFile" , (), {"read" : "not-callable" })()
153+
154+ async def run ():
155+ with pytest .raises (TypeError , match = "file_input must be a file path" ):
156+ await manager .upload_file ("session_123" , fake_file )
157+
158+ asyncio .run (run ())
You can’t perform that action at this time.
0 commit comments