Files
MeltMind/tools/test_phase2_h1_score_extension.py
T

23 lines
1.6 KiB
Python

import unittest
from unittest.mock import patch
from pathlib import Path
from phase2_h1_score_extension import scope,worker
class Acceptance(unittest.TestCase):
def test_only_interrupted_and_never_completed(self):
f=dict(entries=[dict(protocol='grouped',case=x) for x in ['a','b','c']])
r=[dict(name='score-0',protocol='grouped',case='a',guard=dict(status='PASS',stop_reason=None)),dict(name='score-1',protocol='grouped',case='b',guard=dict(status='FAILED',stop_reason='GUARD_SIGNAL_15'))]
done,todo,causes=scope(f,r);self.assertEqual(done,[('grouped','a')]);self.assertEqual(todo,[('grouped','b'),('grouped','c')]);self.assertEqual(causes[('grouped','c')],'NEVER_ATTEMPTED')
def test_unapproved_real_failure_refused(self):
f=dict(entries=[dict(protocol='g',case='a')]);r=[dict(name='score-0',protocol='g',case='a',guard=dict(status='FAILED',stop_reason='wall_limit'))]
with self.assertRaises(ValueError):scope(f,r)
def test_completed_case_cannot_enter_scorer(self):
with patch('phase2_h1_score_extension.engineering',return_value=dict(unfinished=[['g','b']])),patch('phase2_h1_recovery_postfit.score_part') as score:
with self.assertRaises(PermissionError):worker(Path('/synthetic'),'part','g','a')
score.assert_not_called()
def test_approved_worker_calls_original_scoring_function(self):
with patch('phase2_h1_score_extension.engineering',return_value=dict(unfinished=[['g','b']])),patch('phase2_h1_recovery_postfit.score_part') as score:
root=Path('/synthetic');worker(root,'part','g','b');score.assert_called_once_with(root,'g','b')
if __name__=='__main__':unittest.main()