Skip to content

Commit 33c7da2

Browse files
congminh1254claude
andcommitted
test: Count only session seeks in retry seek test
Patch out MultipartStream, which sizes file streams itself, so the test checks that the session rewinds file streams before each attempt without depending on how the generated encoder measures them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent b76b786 commit 33c7da2

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎test/boxsdk/unit/session/test_session.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from functools import partial
2-
from io import IOBase, BytesIO, SEEK_END
2+
from io import IOBase, BytesIO
33
from numbers import Number
44
import os
55
from unittest.mock import MagicMock, Mock, PropertyMock, call, patch, ANY
@@ -264,16 +264,20 @@ def test_box_session_seeks_file_after_retry(
264264
mock_file_2.tell.return_value = 3
265265
files = {'file': ('unused', mock_file_1), 'f2': ('unused', mock_file_2)}
266266

267-
box_response = box_session.post(url=test_url, files=files)
267+
# the multipart encoder sizes the streams itself, so only count the session's seeks
268+
with patch('boxsdk.session.session.MultipartStream'):
269+
box_response = box_session.post(url=test_url, files=files)
268270
assert box_response.status_code == 200
269271
assert box_response.json() == generic_successful_response.json()
270272
assert box_response.ok == generic_successful_response.ok
271273
mock_file_1.tell.assert_called_with()
272274
mock_file_2.tell.assert_called_with()
273-
# before each attempt the session rewinds the stream, then the multipart
274-
# encoder measures its size and restores the position
275-
assert mock_file_1.seek.call_args_list == [call(0), call(0, SEEK_END), call(0)] * 2
276-
assert mock_file_2.seek.call_args_list == [call(3), call(0, SEEK_END), call(3)] * 2
275+
mock_file_1.seek.assert_called_with(0)
276+
assert mock_file_1.seek.call_count == 2
277+
mock_file_1.seek.assert_has_calls([call(0), call(0)])
278+
mock_file_2.seek.assert_called_with(3)
279+
assert mock_file_2.seek.call_count == 2
280+
mock_file_2.seek.assert_has_calls([call(3), call(3)])
277281

278282

279283
def test_box_session_raises_for_non_json_response(

0 commit comments

Comments
 (0)