mirror of
https://github.com/affaan-m/ECC.git
synced 2026-08-17 21:15:40 +02:00
* ci: add ruff + mypy to the Python CI job and fix pyproject tool config The python-tests job runs pytest but not lint/type checks, and the ruff and mypy configuration in pyproject.toml was silently broken, so neither tool could run at all. - add ruff and mypy steps to the existing python-tests job - fix invalid pyproject keys: [tool.ruff] src-path -> src, [tool.mypy] src_paths -> mypy_path - ignore ruff UP042 (the (str, Enum) mixin is intentional) - resolve ruff findings (unused/unsorted imports) across src and tests - fix mypy errors in tools/executor.py and prompt/builder.py * fix(ci): satisfy Python lint after main refresh --------- Co-authored-by: haelyra <49814733+haelyra@users.noreply.github.com>
103 lines
3.5 KiB
Python
103 lines
3.5 KiB
Python
import pytest
|
|
|
|
from llm.core.types import ProviderType
|
|
from llm.providers import (
|
|
AstraflowCNProvider,
|
|
AstraflowProvider,
|
|
AtlasProvider,
|
|
ClaudeProvider,
|
|
OllamaProvider,
|
|
OpenAIProvider,
|
|
get_provider,
|
|
)
|
|
|
|
|
|
class TestGetProvider:
|
|
def test_get_claude_provider(self):
|
|
provider = get_provider("claude")
|
|
assert isinstance(provider, ClaudeProvider)
|
|
assert provider.provider_type == ProviderType.CLAUDE
|
|
|
|
def test_get_openai_provider(self):
|
|
provider = get_provider("openai")
|
|
assert isinstance(provider, OpenAIProvider)
|
|
assert provider.provider_type == ProviderType.OPENAI
|
|
|
|
def test_get_ollama_provider(self):
|
|
provider = get_provider("ollama")
|
|
assert isinstance(provider, OllamaProvider)
|
|
assert provider.provider_type == ProviderType.OLLAMA
|
|
|
|
def test_get_astraflow_provider(self):
|
|
provider = get_provider("astraflow")
|
|
assert isinstance(provider, AstraflowProvider)
|
|
assert provider.provider_type == ProviderType.ASTRAFLOW
|
|
|
|
def test_get_astraflow_cn_provider(self):
|
|
provider = get_provider("astraflow_cn")
|
|
assert isinstance(provider, AstraflowCNProvider)
|
|
assert provider.provider_type == ProviderType.ASTRAFLOW_CN
|
|
|
|
def test_get_atlas_provider(self):
|
|
provider = get_provider("atlas")
|
|
assert isinstance(provider, AtlasProvider)
|
|
assert provider.provider_type == ProviderType.ATLAS
|
|
|
|
def test_get_provider_by_enum(self):
|
|
provider = get_provider(ProviderType.CLAUDE)
|
|
assert isinstance(provider, ClaudeProvider)
|
|
|
|
def test_invalid_provider_raises(self):
|
|
with pytest.raises(ValueError, match="Unknown provider type"):
|
|
get_provider("invalid")
|
|
|
|
def test_saved_llm_env_selects_provider(self, monkeypatch, tmp_path):
|
|
monkeypatch.delenv("LLM_PROVIDER", raising=False)
|
|
monkeypatch.chdir(tmp_path)
|
|
tmp_path.joinpath(".llm.env").write_text("LLM_PROVIDER=ollama\nLLM_MODEL=llama3.2\n")
|
|
|
|
provider = get_provider()
|
|
|
|
assert isinstance(provider, OllamaProvider)
|
|
|
|
def test_env_provider_overrides_saved_llm_env(self, monkeypatch, tmp_path):
|
|
monkeypatch.setenv("LLM_PROVIDER", "ollama")
|
|
monkeypatch.chdir(tmp_path)
|
|
tmp_path.joinpath(".llm.env").write_text("LLM_PROVIDER=openai\n")
|
|
|
|
provider = get_provider()
|
|
|
|
assert isinstance(provider, OllamaProvider)
|
|
|
|
def test_env_provider_is_normalized(self, monkeypatch):
|
|
monkeypatch.setenv("LLM_PROVIDER", "OLLAMA")
|
|
|
|
provider = get_provider()
|
|
|
|
assert isinstance(provider, OllamaProvider)
|
|
|
|
def test_astraflow_env_provider_is_normalized(self, monkeypatch):
|
|
monkeypatch.setenv("LLM_PROVIDER", "ASTRAFLOW")
|
|
|
|
provider = get_provider()
|
|
|
|
assert isinstance(provider, AstraflowProvider)
|
|
|
|
def test_explicit_provider_overrides_saved_llm_env(self, monkeypatch, tmp_path):
|
|
monkeypatch.delenv("LLM_PROVIDER", raising=False)
|
|
monkeypatch.chdir(tmp_path)
|
|
tmp_path.joinpath(".llm.env").write_text("LLM_PROVIDER=openai\n")
|
|
|
|
provider = get_provider("ollama")
|
|
|
|
assert isinstance(provider, OllamaProvider)
|
|
|
|
def test_saved_llm_env_selects_astraflow_cn_provider(self, monkeypatch, tmp_path):
|
|
monkeypatch.delenv("LLM_PROVIDER", raising=False)
|
|
monkeypatch.chdir(tmp_path)
|
|
tmp_path.joinpath(".llm.env").write_text("LLM_PROVIDER=astraflow_cn\n")
|
|
|
|
provider = get_provider()
|
|
|
|
assert isinstance(provider, AstraflowCNProvider)
|