Files
livekit-agents/tests/test_utils_env.py
61b14fdcd9 feat(eot): add audio models AGT-2520 (#4722)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Brian Yin <brian.yin@livekit.io>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Long Chen <longch1024@gmail.com>
Co-authored-by: Aditya <147301021+adityajha2005@users.noreply.github.com>
Co-authored-by: Théo Monnom <theo.8bits@gmail.com>
2026-06-16 19:28:59 +01:00

98 lines
3.1 KiB
Python

import pytest
from livekit.agents.types import NOT_GIVEN
from livekit.agents.utils.env import resolve_env_var
pytestmark = pytest.mark.unit
class TestResolveEnvVar:
"""Tests for the resolve_env_var helper contract."""
def test_returns_empty_string_when_no_env_or_default(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv("LIVEKIT_INFERENCE_URL", raising=False)
assert resolve_env_var(NOT_GIVEN, "LIVEKIT_INFERENCE_URL") == ""
def test_returns_default_when_no_matching_env_exists(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv("LIVEKIT_INFERENCE_URL", raising=False)
assert (
resolve_env_var(
NOT_GIVEN,
"LIVEKIT_INFERENCE_URL",
default="https://default.example.com",
)
== "https://default.example.com"
)
def test_returns_first_matching_env_value(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("LIVEKIT_INFERENCE_URL", "https://inference.example.com")
monkeypatch.setenv("LIVEKIT_URL", "https://livekit.example.com")
assert (
resolve_env_var(
NOT_GIVEN,
"LIVEKIT_INFERENCE_URL",
"LIVEKIT_URL",
default="https://default.example.com",
)
== "https://inference.example.com"
)
def test_falls_back_to_later_env_when_earlier_env_missing(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv("LIVEKIT_INFERENCE_URL", raising=False)
monkeypatch.setenv("LIVEKIT_URL", "https://livekit.example.com")
assert (
resolve_env_var(
NOT_GIVEN,
"LIVEKIT_INFERENCE_URL",
"LIVEKIT_URL",
default="https://default.example.com",
)
== "https://livekit.example.com"
)
def test_prefers_explicit_value_over_environment(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("LIVEKIT_INFERENCE_URL", "https://env.example.com")
assert (
resolve_env_var(
"https://explicit.example.com",
"LIVEKIT_INFERENCE_URL",
default="https://default.example.com",
)
== "https://explicit.example.com"
)
def test_treats_empty_env_value_as_missing(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("LIVEKIT_INFERENCE_URL", "")
assert (
resolve_env_var(
NOT_GIVEN,
"LIVEKIT_INFERENCE_URL",
default="https://default.example.com",
)
== "https://default.example.com"
)
def test_treats_whitespace_env_value_as_set(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("LIVEKIT_INFERENCE_URL", " ")
assert (
resolve_env_var(
NOT_GIVEN,
"LIVEKIT_INFERENCE_URL",
default="https://default.example.com",
)
== " "
)