Preserve mixed evaluation evidence with reserved atomic report checkpoints

This commit is contained in:
karl committed 2026-10-13 17:30:52 +02:00
1 parent ac90ce748d
commit 0b6c958907
4 files changed
+55 -3

No files matched your search

+26
View File
@@ -3,12 +3,38 @@ import importlib.util
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
spec = importlib.util.spec_from_file_location('mixed_eval', Path(__file__).with_name('evaluate.py'))
evaluate = importlib.util.module_from_spec(spec); spec.loader.exec_module(evaluate)
class EvaluationTests(unittest.TestCase):
def test_existing_report_is_preserved_and_new_report_is_reserved(self):
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / 'nested' / 'report.json'
evaluate.reserve_report(path)
evaluate.write_report(path, {'complete': False, 'query': 'Straße'})
previous = path.read_bytes()
with self.assertRaises(FileExistsError):
evaluate.reserve_report(path)
self.assertEqual(path.read_bytes(), previous)
evaluate.write_report(path, {'complete': True})
self.assertIn('true', path.read_text(encoding='utf-8'))
self.assertEqual(list(path.parent.glob('*.partial')), [])
def test_failed_checkpoint_publication_keeps_previous_report(self):
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / 'report.json'
evaluate.reserve_report(path)
evaluate.write_report(path, {'complete': False, 'rows': [1]})
previous = path.read_bytes()
with patch.object(evaluate.os, 'replace', side_effect=OSError('disk failure')):
with self.assertRaises(OSError):
evaluate.write_report(path, {'complete': True})
self.assertEqual(path.read_bytes(), previous)
self.assertEqual(list(path.parent.glob('*.partial')), [])
def test_frozen_real_assets_verify(self):
fixture, _ = evaluate.load_fixture()
self.assertEqual(len(fixture['assets']), 32)