"""Test the real registry branch without changing files or launching a publisher.""" import ast import json from pathlib import Path import sys import unittest GENERATOR=Path(sys.argv[1])if len(sys.argv)>1 else Path('/tmp/turkos-k2100-site-experiments.py') if len(sys.argv)>1:sys.argv.pop(1) module=ast.parse(GENERATOR.read_text()) index=next(i for i,n in enumerate(module.body)if isinstance(n,ast.Assign)and any(isinstance(t,ast.Name)and t.id=='native_admission_result'for t in n.targets)) program=compile(ast.Module(body=module.body[index:index+2],type_ignores=[]),str(GENERATOR),'exec') class PublicationTests(unittest.TestCase): def branch(self,report,present=True): rows=[] class FixturePath: def __init__(self,path):self.path=path def is_file(self):return present def read_text(self):return 'fixture-report.json'if self.path.endswith('.txt')else json.dumps(report) def add(*args,**kwargs): self.assertFalse(report['guestAccepted'],'a real guest acceptance belongs to the canonical roadmap report') rows.append((args,kwargs)) exec(program,dict(Path=FixturePath,json=json,add=add)) return rows def test_accepted_guest_is_published_by_canonical_progress(self): self.assertEqual(self.branch(dict(status='NATIVE_ADMISSION_PASSED',guestAccepted=True,productAccepted=False,files=[])),[]) def test_failed_admission_remains_an_explicit_experiment(self): rows=self.branch(dict(status='NATIVE_ADMISSION_FAILED',guestAccepted=False,productAccepted=False,files=[dict(path='failure.log')])) self.assertEqual(len(rows),1);self.assertEqual(rows[0][0][0],'native-admission-result') def test_absent_result_does_not_create_experiment(self):self.assertEqual(self.branch({},False),[]) def test_missing_acceptance_flag_is_not_silently_assumed(self): with self.assertRaises(KeyError):self.branch(dict(status='NATIVE_ADMISSION_FAILED',files=[])) if __name__=='__main__':unittest.main(verbosity=2)