File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
tests/unit/internal/retrieval Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ from io import BytesIO
2+ from unittest import mock
3+
4+ from neptune_api .proto .neptune_pb .api .v1 .model .requests_pb2 import ProtoGetTimeseriesBucketsRequest
5+ from neptune_query .internal .retrieval .util import ProtobufPayload
6+ from neptune_query .types import File
7+
8+
9+ @mock .patch ("neptune_query.internal.retrieval.util.BytesIO" , wraps = BytesIO )
10+ def test_bytesio_recreation_on_retry (mock_bytesio ):
11+ """Test that BytesIO instance is recreated when the API call is retried."""
12+
13+ file = ProtobufPayload (ProtoGetTimeseriesBucketsRequest ())
14+
15+ # Verify file is File as expected
16+ assert isinstance (file , File )
17+
18+ # Read file's payload two times to simulate two API calls:
19+ read1 = file .payload .read ()
20+ read2 = file .payload .read ()
21+
22+ # Verify that both reads return the same content
23+ # If the same BytesIO instance was used, the second read would return b''
24+ assert read1 == read2
25+ assert read2 != b''
26+
27+ # Verify BytesIO was called twice
28+ assert mock_bytesio .call_count == 2
You can’t perform that action at this time.
0 commit comments