import ast,unittest import numpy as np from phase2_b13_e1 import pooled from phase2_b1213_gate import coverage from s2_custody_statistics import kendall_pairs class E1Tests(unittest.TestCase): def metric(v):return {m:dict(value=v,reason=None) for m in ['relative_l2','last_location','kendall_tau_b']} def test_component_not_part_weight(self): rows=[dict(component_id='a',new=self.metric(0),A=self.metric(0))]+[dict(component_id='b',new=self.metric(2),A=self.metric(0)) for i in range(10)] self.assertEqual(pooled(rows)['relative_l2']['new_minus_A']['value'],1) def test_coverage_requires_all_members(self): rows=[dict(component_id='a',case='1'),dict(component_id='a',case='2'),dict(component_id='b',case='3')] result={'1':dict(status='GEOMETRY_COMPLETE'),'2':dict(status='SCIENTIFIC_MISSING'),'3':dict(status='GEOMETRY_COMPLETE')} self.assertEqual(coverage(rows,result)['fraction'],.5) def test_undefined_component_retained_as_missing(self): rows=[dict(component_id='a',new=self.metric(None),A=self.metric(1))] self.assertIsNone(pooled(rows)['relative_l2']['new_minus_A']['high']) def test_frozen_fit_reads_learning_only(self): from pathlib import Path tree=ast.parse(Path('tools/phase2_b1213_gate.py').read_text());fn=next(n for n in tree.body if isinstance(n,ast.FunctionDef) and n.name=='train') constants=[n.value for n in ast.walk(fn) if isinstance(n,ast.Constant)] self.assertIn('learning',constants);self.assertNotIn('validation',constants);self.assertNotIn('test',constants) def test_tau_ties_undefined(self): self.assertIsNone(kendall_pairs([1,1,1],[1,2,3],7)['value']);self.assertEqual(kendall_pairs([1,2,3],[1,2,3],7)['value'],1.) metric=E1Tests.metric;E1Tests.metric=staticmethod(metric) if __name__=='__main__':unittest.main()