| import os |
| import shutil |
| import tempfile |
| import zipfile |
| from benchmark.artifacts import create_benchmark_package |
| from benchmark import config |
|
|
| def test_benchmark_package_generation(): |
| |
| run_id = "test-pkg-run-456" |
| source_metadata = { |
| "filename": "sample.txt", |
| "original_text": "Sample text", |
| "extracted_text": "Sample text", |
| "normalized_text": "sample text", |
| "style": "custom" |
| } |
| |
| questions = [{ |
| "question_id": "Q0001", |
| "question": "Sample?", |
| "expected_answer": "Yes", |
| "supporting_fact_ids": ["F0001"], |
| "source_position": 0.5 |
| }] |
| |
| results_summary = { |
| "run_label": "CUSTOM EVALUATOR RUN", |
| "per_question": [], |
| "overall": {}, |
| "config": {}, |
| "execution_order": [], |
| "hardware_comparison": {"plain_device": "cpu", "rif_device": "cpu", "different_hardware": False} |
| } |
| |
| try: |
| zip_path = create_benchmark_package( |
| run_id=run_id, |
| source_metadata=source_metadata, |
| questions=questions, |
| model_pairs_meta={}, |
| plain_models_list={}, |
| rif_models_list={}, |
| raw_logs=[], |
| results_summary=results_summary |
| ) |
| |
| assert os.path.exists(zip_path) |
| assert zip_path.endswith(".zip") |
| |
| |
| with zipfile.ZipFile(zip_path, "r") as z: |
| namelist = z.namelist() |
| assert any("integrity/sha256-checksums.txt" in x for x in namelist) |
| assert any("source/extracted-source.txt" in x for x in namelist) |
| finally: |
| |
| run_dir = os.path.join(config.RUNS_DIR, f"kalpana-benchmark-{run_id}") |
| if os.path.exists(run_dir): |
| shutil.rmtree(run_dir) |
| if os.path.exists(zip_path): |
| os.remove(zip_path) |
|
|