File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
tests/unit/internal/retrieval Expand file tree Collapse file tree 1 file changed +39
-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 .protobuf_v4plus .neptune_pb .api .v1 .model .requests_pb2 import (
5+ ProtoCustomExpression ,
6+ ProtoGetTimeseriesBucketsRequest ,
7+ ProtoScale ,
8+ ProtoView ,
9+ )
10+ from neptune_api .types import File
11+
12+ from neptune_query .internal .retrieval .util import ProtobufPayload
13+
14+
15+ @mock .patch ("neptune_query.internal.retrieval.util.BytesIO" , wraps = BytesIO )
16+ def test_bytesio_recreation_on_retry (mock_bytesio ):
17+ """Test that BytesIO instance is recreated when the API call is retried."""
18+
19+ file = ProtobufPayload (
20+ ProtoGetTimeseriesBucketsRequest (
21+ expressions = [ProtoCustomExpression (requestId = "0123" , customYFormula = "${abc}" )],
22+ view = ProtoView (xScale = ProtoScale .linear ),
23+ )
24+ )
25+
26+ # Verify file is neptune_api.types.File as expected
27+ assert isinstance (file , File )
28+
29+ # Read file's payload two times to simulate two API calls:
30+ read1 = file .payload .read ()
31+ read2 = file .payload .read ()
32+
33+ # Verify that both reads return the same content
34+ # If the same BytesIO instance was used, the second read would return b''
35+ assert read1 == read2
36+ assert read2 != b""
37+
38+ # Verify BytesIO was called twice
39+ assert mock_bytesio .call_count == 2
You can’t perform that action at this time.
0 commit comments