7a0da7932b
Backwards Compatibility / Verify Encryption Constants (push) Waiting to run
Backwards Compatibility / PyPI Version Compatibility (push) Waiting to run
Backwards Compatibility / Database Migration Tests (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Blocked by required conditions
Docker Tests (Consolidated) / detect-changes (push) Waiting to run
Docker Tests (Consolidated) / Build Test Image (push) Waiting to run
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Blocked by required conditions
Docker Tests (Consolidated) / Accessibility Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Unit Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Example Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / Production Image Smoke Test (push) Blocked by required conditions
Docker Tests (Consolidated) / Infrastructure Tests (push) Blocked by required conditions
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Waiting to run
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
140 lines
5.0 KiB
Python
140 lines
5.0 KiB
Python
"""High-value tests for benchmarks/comparison/results.py.
|
|
|
|
Covers Benchmark_results: add_result, get_all, get_best sorting,
|
|
file loading, and edge cases.
|
|
"""
|
|
|
|
import json
|
|
import pytest
|
|
from unittest.mock import patch
|
|
|
|
from local_deep_research.benchmarks.comparison.results import Benchmark_results
|
|
|
|
|
|
class TestBenchmarkResultsInit:
|
|
"""Test Benchmark_results initialization."""
|
|
|
|
def test_default_results_file(self, tmp_path, monkeypatch):
|
|
"""Default results file is benchmark_results.json."""
|
|
monkeypatch.chdir(tmp_path)
|
|
br = Benchmark_results()
|
|
assert br.results_file == "benchmark_results.json"
|
|
|
|
def test_custom_results_file(self, tmp_path):
|
|
"""Custom results file is used."""
|
|
f = tmp_path / "custom.json"
|
|
f.write_text("[]")
|
|
br = Benchmark_results(results_file=str(f))
|
|
assert br.results_file == str(f)
|
|
|
|
def test_empty_results_when_file_missing(self, tmp_path):
|
|
"""Missing file results in empty list."""
|
|
br = Benchmark_results(results_file=str(tmp_path / "nonexistent.json"))
|
|
assert br.results == []
|
|
|
|
def test_loads_existing_results(self, tmp_path):
|
|
"""Existing file's results are loaded."""
|
|
data = [{"model": "test", "accuracy_focused": 0.9}]
|
|
f = tmp_path / "results.json"
|
|
f.write_text(json.dumps(data))
|
|
br = Benchmark_results(results_file=str(f))
|
|
assert len(br.results) == 1
|
|
assert br.results[0]["model"] == "test"
|
|
|
|
|
|
class TestBenchmarkResultsAddResult:
|
|
"""Test add_result method."""
|
|
|
|
def test_add_result_appends_and_saves(self, tmp_path):
|
|
"""add_result appends to results and calls _save_results."""
|
|
with patch.object(Benchmark_results, "_save_results"):
|
|
br = Benchmark_results(results_file=str(tmp_path / "nonexist.json"))
|
|
result = br.add_result(
|
|
model="gpt-4",
|
|
hardware="RTX 4090",
|
|
accuracy_focused=0.95,
|
|
accuracy_source=0.90,
|
|
avg_time_per_question=5.0,
|
|
context_window=128000,
|
|
temperature=0.0,
|
|
ldr_version="1.0",
|
|
date_tested="2024-01-01",
|
|
notes="test run",
|
|
)
|
|
assert result is True
|
|
assert len(br.results) == 1
|
|
assert br.results[0]["model"] == "gpt-4"
|
|
assert br.results[0]["notes"] == "test run"
|
|
|
|
def test_add_result_default_notes_empty(self, tmp_path):
|
|
"""Notes defaults to empty string."""
|
|
with patch.object(Benchmark_results, "_save_results"):
|
|
br = Benchmark_results(results_file=str(tmp_path / "nonexist.json"))
|
|
br.add_result(
|
|
"m", "h", 0.5, 0.5, 1.0, 8192, 0.0, "1.0", "2024-01-01"
|
|
)
|
|
assert br.results[0]["notes"] == ""
|
|
|
|
|
|
class TestBenchmarkResultsGetBest:
|
|
"""Test get_best sorting."""
|
|
|
|
def _make_results(self, tmp_path):
|
|
f = tmp_path / "results.json"
|
|
data = [
|
|
{
|
|
"model": "fast",
|
|
"accuracy_focused": 0.7,
|
|
"accuracy_source": 0.6,
|
|
"avg_time_per_question": 1.0,
|
|
"hardware": "h",
|
|
"context_window": 8192,
|
|
"temperature": 0.0,
|
|
"ldr_version": "1.0",
|
|
"date_tested": "2024-01-01",
|
|
"notes": "",
|
|
},
|
|
{
|
|
"model": "accurate",
|
|
"accuracy_focused": 0.95,
|
|
"accuracy_source": 0.9,
|
|
"avg_time_per_question": 10.0,
|
|
"hardware": "h",
|
|
"context_window": 128000,
|
|
"temperature": 0.0,
|
|
"ldr_version": "1.0",
|
|
"date_tested": "2024-01-01",
|
|
"notes": "",
|
|
},
|
|
]
|
|
f.write_text(json.dumps(data))
|
|
return Benchmark_results(results_file=str(f))
|
|
|
|
def test_sort_by_accuracy_descending(self, tmp_path):
|
|
"""Default sort by accuracy_focused is descending."""
|
|
br = self._make_results(tmp_path)
|
|
best = br.get_best()
|
|
assert best[0]["model"] == "accurate"
|
|
|
|
def test_sort_by_time_ascending(self, tmp_path):
|
|
"""Sort by avg_time_per_question is ascending."""
|
|
br = self._make_results(tmp_path)
|
|
best = br.get_best(sort_by="avg_time_per_question")
|
|
assert best[0]["model"] == "fast"
|
|
|
|
def test_invalid_sort_key_raises(self, tmp_path):
|
|
"""Invalid sort_by key raises ValueError."""
|
|
br = self._make_results(tmp_path)
|
|
with pytest.raises(ValueError, match="Invalid sort_by key"):
|
|
br.get_best(sort_by="nonexistent_key")
|
|
|
|
def test_get_all_returns_all(self, tmp_path):
|
|
"""get_all returns all results unchanged."""
|
|
br = self._make_results(tmp_path)
|
|
assert len(br.get_all()) == 2
|
|
|
|
def test_get_best_empty_results(self, tmp_path):
|
|
"""get_best on empty results returns empty list."""
|
|
br = Benchmark_results(results_file=str(tmp_path / "nonexist.json"))
|
|
assert br.get_best() == []
|