File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,3 +49,8 @@ def get_inference_service_dep() -> InferenceService:
4949 status_code = status .HTTP_503_SERVICE_UNAVAILABLE ,
5050 detail = f"Inference service unavailable: { exc } " ,
5151 ) from exc
52+ except (ModuleNotFoundError , ImportError , OSError ) as exc :
53+ raise HTTPException (
54+ status_code = status .HTTP_503_SERVICE_UNAVAILABLE ,
55+ detail = f"Inference service unavailable: { exc } " ,
56+ ) from exc
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ import sys
4+ import unittest
5+ from pathlib import Path
6+ from unittest .mock import patch
7+
8+ from fastapi import HTTPException
9+
10+ sys .path .insert (0 , str (Path (__file__ ).resolve ().parents [1 ] / "src" ))
11+
12+ from api .deps .inference import get_inference_service_dep
13+
14+
15+ class TestApiInferenceDep (unittest .TestCase ):
16+ @patch ("api.deps.inference._build_inference_service" , side_effect = ModuleNotFoundError ("hf_xet" ))
17+ @patch ("api.deps.inference.resolve_artifact_uri" , side_effect = lambda value : value )
18+ def test_maps_module_not_found_to_http_503 (self , * _ : object ) -> None :
19+ with self .assertRaises (HTTPException ) as ctx :
20+ get_inference_service_dep ()
21+
22+ self .assertEqual (ctx .exception .status_code , 503 )
23+ self .assertIn ("Inference service unavailable" , str (ctx .exception .detail ))
24+
25+
26+ if __name__ == "__main__" :
27+ unittest .main ()
28+
You can’t perform that action at this time.
0 commit comments