Files
wehub-resource-sync 7a0da7932b
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
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

332 lines
11 KiB
Python

"""High-value tests for benchmarks/metrics/reporting.py.
Covers report generation, empty/null data handling, category metrics,
config info inclusion, and file I/O error paths.
"""
import json
from unittest.mock import patch
class TestGenerateReport:
"""Tests for generate_report function."""
def test_basic_report_generation(self, tmp_path):
"""Basic report generates with minimal metrics."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
results_file = tmp_path / "results.jsonl"
results_file.write_text("")
output_file = str(tmp_path / "report.md")
metrics = {
"total_examples": 10,
"graded_examples": 10,
"correct": 8,
"accuracy": 0.8,
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
result = generate_report(
metrics=metrics,
results_file=str(results_file),
output_file=output_file,
dataset_name="TestDataset",
)
assert result == output_file
mock_write.assert_called_once()
content = mock_write.call_args[0][1]
assert "TestDataset" in content
assert "0.800" in content
assert "8" in content
def test_report_with_processing_time(self, tmp_path):
"""Report includes average processing time when available."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
results_file = tmp_path / "results.jsonl"
results_file.write_text("")
metrics = {
"total_examples": 5,
"graded_examples": 5,
"correct": 3,
"accuracy": 0.6,
"average_processing_time": 12.345,
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
generate_report(
metrics=metrics,
results_file=str(results_file),
output_file=str(tmp_path / "report.md"),
)
content = mock_write.call_args[0][1]
assert "12.35" in content
def test_report_with_error_count(self, tmp_path):
"""Report includes error stats when error_count > 0."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
results_file = tmp_path / "results.jsonl"
results_file.write_text("")
metrics = {
"total_examples": 10,
"graded_examples": 8,
"correct": 6,
"accuracy": 0.75,
"error_count": 2,
"error_rate": 0.2,
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
generate_report(
metrics=metrics,
results_file=str(results_file),
output_file=str(tmp_path / "report.md"),
)
content = mock_write.call_args[0][1]
assert "Error Count" in content
assert "Error Rate" in content
def test_report_with_categories(self, tmp_path):
"""Report includes per-category metrics."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
results_file = tmp_path / "results.jsonl"
results_file.write_text("")
metrics = {
"total_examples": 10,
"graded_examples": 10,
"correct": 7,
"accuracy": 0.7,
"categories": {
"Science": {"total": 5, "correct": 4, "accuracy": 0.8},
"History": {"total": 5, "correct": 3, "accuracy": 0.6},
},
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
generate_report(
metrics=metrics,
results_file=str(results_file),
output_file=str(tmp_path / "report.md"),
)
content = mock_write.call_args[0][1]
assert "Science" in content
assert "History" in content
assert "0.800" in content
def test_report_with_config_info(self, tmp_path):
"""Report includes configuration info when provided."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
results_file = tmp_path / "results.jsonl"
results_file.write_text("")
metrics = {
"total_examples": 1,
"graded_examples": 1,
"correct": 1,
"accuracy": 1.0,
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
generate_report(
metrics=metrics,
results_file=str(results_file),
output_file=str(tmp_path / "report.md"),
config_info={"model": "gpt-4", "strategy": "rapid"},
)
content = mock_write.call_args[0][1]
assert "Configuration" in content
assert "gpt-4" in content
assert "rapid" in content
def test_report_with_correct_examples(self, tmp_path):
"""Report includes correct answer examples from results file."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
results_file = tmp_path / "results.jsonl"
results = [
{
"problem": "What is 2+2?",
"correct_answer": "4",
"extracted_answer": "4",
"is_correct": True,
},
]
results_file.write_text("\n".join(json.dumps(r) for r in results))
metrics = {
"total_examples": 1,
"graded_examples": 1,
"correct": 1,
"accuracy": 1.0,
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
generate_report(
metrics=metrics,
results_file=str(results_file),
output_file=str(tmp_path / "report.md"),
)
content = mock_write.call_args[0][1]
assert "Example Correct Answers" in content
assert "What is 2+2?" in content
def test_report_with_incorrect_examples(self, tmp_path):
"""Report includes incorrect answer examples."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
results_file = tmp_path / "results.jsonl"
results = [
{
"problem": "Capital of France?",
"correct_answer": "Paris",
"extracted_answer": "London",
"is_correct": False,
},
]
results_file.write_text("\n".join(json.dumps(r) for r in results))
metrics = {
"total_examples": 1,
"graded_examples": 1,
"correct": 0,
"accuracy": 0.0,
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
generate_report(
metrics=metrics,
results_file=str(results_file),
output_file=str(tmp_path / "report.md"),
)
content = mock_write.call_args[0][1]
assert "Example Incorrect Answers" in content
assert "Capital of France?" in content
def test_report_handles_missing_results_file(self, tmp_path):
"""Missing results file doesn't crash report generation."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
metrics = {
"total_examples": 0,
"graded_examples": 0,
"correct": 0,
"accuracy": 0.0,
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
result = generate_report(
metrics=metrics,
results_file="/nonexistent/path/results.jsonl",
output_file=str(tmp_path / "report.md"),
)
assert result == str(tmp_path / "report.md")
mock_write.assert_called_once()
def test_report_limits_examples_to_five(self, tmp_path):
"""Report limits correct/incorrect examples to 5 each."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
results_file = tmp_path / "results.jsonl"
results = [
{
"problem": f"Q{i}?",
"correct_answer": f"A{i}",
"extracted_answer": f"A{i}",
"is_correct": True,
}
for i in range(10)
]
results_file.write_text("\n".join(json.dumps(r) for r in results))
metrics = {
"total_examples": 10,
"graded_examples": 10,
"correct": 10,
"accuracy": 1.0,
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
generate_report(
metrics=metrics,
results_file=str(results_file),
output_file=str(tmp_path / "report.md"),
)
content = mock_write.call_args[0][1]
# Should have exactly 5 "Example N" entries
assert content.count("### Example") == 5
def test_report_includes_metadata_timestamp(self, tmp_path):
"""Report includes metadata section with timestamp."""
from local_deep_research.benchmarks.metrics.reporting import (
generate_report,
)
results_file = tmp_path / "results.jsonl"
results_file.write_text("")
metrics = {
"total_examples": 0,
"graded_examples": 0,
"correct": 0,
"accuracy": 0.0,
}
with patch(
"local_deep_research.security.file_write_verifier.write_file_verified"
) as mock_write:
generate_report(
metrics=metrics,
results_file=str(results_file),
output_file=str(tmp_path / "report.md"),
dataset_name="TestDS",
)
content = mock_write.call_args[0][1]
assert "Metadata" in content
assert "Generated" in content
assert "TestDS" in content