Datasets:
Download tests/test_providers.py from Nabidnur/RoboRACE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/tests/test_providers.py
- Command line
-
hf download hf://datasets/Nabidnur/RoboRACE-Bench/tests/test_providers.py
-
curl -L -o test_providers.py https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/tests/test_providers.py
1.17 kB
| import urllib.error | |
| import pytest | |
| from robotics.llm import providers as P | |
| def test_falls_through_on_connection_reset(monkeypatch): | |
| monkeypatch.setenv("GROQ_API_KEY", "x") | |
| monkeypatch.setenv("CEREBRAS_API_KEY", "y") | |
| calls = [] | |
| def fake_post(url, key, payload, timeout): | |
| calls.append(url) | |
| if "groq" in url: | |
| raise ConnectionResetError(104, "reset") | |
| return {"choices": [{"message": {"content": "hi"}}]} | |
| monkeypatch.setattr(P, "_post", fake_post) | |
| assert P.chat([{"role": "user", "content": "x"}], providers=["groq", "cerebras"]) == ("hi", "cerebras") | |
| def test_empty_content_is_an_error(monkeypatch): | |
| monkeypatch.setenv("GROQ_API_KEY", "x") | |
| monkeypatch.setattr(P, "_post", lambda *a: {"choices": [{"message": {"content": None}}]}) | |
| with pytest.raises(P.LLMError, match="empty content"): | |
| P.chat([{"role": "user", "content": "x"}], providers=["groq"]) | |
| def test_no_keys(monkeypatch): | |
| for p in P.PROVIDERS.values(): | |
| monkeypatch.delenv(p.key_env, raising=False) | |
| with pytest.raises(P.LLMError, match="No LLM provider keys"): | |
| P.chat([{"role": "user", "content": "x"}]) | |