11import asyncio
2+ import json
23import os
34from pathlib import Path
45
56import pytest
67from unstructured_client import UnstructuredClient
78from unstructured_client .models import shared
8- from unstructured_client .models .errors . sdkerror import SDKError
9+ from unstructured_client .models .errors import SDKError , ServerError , HTTPValidationError
910from unstructured_client .utils .retries import BackoffStrategy , RetryConfig
1011
1112
@@ -52,14 +53,20 @@ def event_loop():
5253
5354
5455@pytest .mark .parametrize ("split_pdf" , [True , False ])
55- @pytest .mark .parametrize ("error_code " , [500 , 403 ])
56- def test_partition_handling_server_error (error_code , split_pdf , monkeypatch , doc_path , event_loop ):
56+ @pytest .mark .parametrize ("error " , [( 500 , ServerError ), ( 403 , SDKError ), ( 422 , HTTPValidationError ) ])
57+ def test_partition_handling_server_error (error , split_pdf , monkeypatch , doc_path , event_loop ):
5758 filename = "layout-parser-paper-fast.pdf"
5859 import httpx
5960 from unstructured_client .sdkconfiguration import requests_http
6061
62+ error_code , sdk_raises = error
63+
6164 response = requests_http .Response ()
6265 response .status_code = error_code
66+ response .headers = {'Content-Type' : 'application/json' }
67+ json_data = {"detail" : "An error occurred" }
68+ response ._content = bytes (json .dumps (json_data ), 'utf-8' )
69+
6370 monkeypatch .setattr (requests_http .Session , "send" , lambda * args , ** kwargs : response )
6471 monkeypatch .setattr (httpx .AsyncClient , "send" , lambda * args , ** kwargs : response )
6572
@@ -82,5 +89,5 @@ def test_partition_handling_server_error(error_code, split_pdf, monkeypatch, doc
8289 split_pdf_page = split_pdf ,
8390 )
8491
85- with pytest .raises (SDKError , match = f"API error occurred: Status { error_code } " ):
92+ with pytest .raises (sdk_raises ):
8693 response = client .general .partition (req )
0 commit comments