Spaces:
Running
Running
File size: 2,017 Bytes
3685d4c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | """Test bootstrap for the ResearchBee Release A regression suite."""
from __future__ import annotations
import sys
import types
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
# The production image installs tenacity from requirements.txt. The execution
# environment used for static/offline review may not have it, so provide a tiny
# decorator-compatible fallback only when the real package is unavailable.
try: # pragma: no cover - exercised only in minimal review environments
import tenacity # noqa: F401
except ModuleNotFoundError: # pragma: no cover
module = types.ModuleType("tenacity")
def retry(*_args, **_kwargs):
def decorator(func):
return func
return decorator
def option(*_args, **_kwargs):
return object()
module.retry = retry
module.stop_after_attempt = option
module.wait_exponential = option
module.retry_if_exception_type = option
module.before_sleep_log = option
sys.modules["tenacity"] = module
# Same offline-review fallback for the OpenAI SDK. Production installs the real
# package from requirements.txt; these tests never make a model call.
try: # pragma: no cover
from openai import AsyncOpenAI # noqa: F401
except ModuleNotFoundError: # pragma: no cover
module = types.ModuleType("openai")
class OpenAIError(Exception):
pass
class RateLimitError(OpenAIError):
pass
class APIStatusError(OpenAIError):
def __init__(self, *args, status_code=500, **kwargs):
super().__init__(*args)
self.status_code = status_code
class AsyncOpenAI:
def __init__(self, *args, **kwargs):
self.chat = types.SimpleNamespace()
module.AsyncOpenAI = AsyncOpenAI
module.RateLimitError = RateLimitError
module.APIStatusError = APIStatusError
sys.modules["openai"] = module
|