@@ -106,20 +106,32 @@ def test_unit_number_of_retries_in_5xx(status_code: int, expect_retry: bool):
106
106
strategy = "backoff" , backoff = backoff_strategy , retry_connection_errors = True
107
107
)
108
108
109
- with requests_mock .Mocker () as mock :
110
- mock .post ("https://api.unstructuredapp.io/general/v0/general" , status_code = status_code )
111
- session = UnstructuredClient (api_key_auth = FAKE_KEY )
109
+ number_of_requests = [0 ]
110
+ def mock_post (request ):
111
+ if request .url == "https://api.unstructuredapp.io/general/v0/general" and request .method == "POST" :
112
+ number_of_requests [0 ] += 1
113
+ return Response (status_code , request = request )
114
+
115
+
116
+ transport = httpx .MockTransport (mock_post )
117
+ client = httpx .Client (transport = transport )
118
+ session = UnstructuredClient (api_key_auth = FAKE_KEY , client = client )
119
+
120
+
121
+ with open (filename , "rb" ) as f :
122
+ files = shared .Files (content = f .read (), file_name = filename )
123
+
124
+ req = operations .PartitionRequest (
125
+ shared .PartitionParameters (files = files )
126
+ )
112
127
113
- with open ( filename , "rb" ) as f :
114
- files = shared . Files ( content = f . read (), file_name = filename )
128
+ with pytest . raises ( Exception , match = f"Status { status_code } " ) :
129
+ session . general . partition ( req , retries = retries )
115
130
116
- req = shared .PartitionParameters (files = files )
117
- with pytest .raises (Exception , match = f"unknown content-type received: None: Status { status_code } " ):
118
- session .general .partition (req , retries = retries )
119
131
if expect_retry :
120
- assert len ( mock . request_history ) > 1
132
+ assert number_of_requests [ 0 ] > 1
121
133
else :
122
- assert len ( mock . request_history ) == 1
134
+ assert number_of_requests [ 0 ] == 1
123
135
124
136
125
137
def test_unit_backoff_strategy_logs_retries_connection_error (caplog ):
0 commit comments