File size: 2,486 Bytes
e1d44f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json,subprocess,sys,tempfile,unittest
from pathlib import Path


class MediumCLI(unittest.TestCase):
    def test_explicit_quota_and_references_in_empty_directory(self):
        root=Path(__file__).resolve().parent;family=root/'P0/known_stem_mix';data=family/'_shared/data';script=family/'_shared/pipe_code/medium_pairs.py'
        with tempfile.TemporaryDirectory() as d:
            work=Path(d);bank=work/'bank.json';bank.write_text('{"materials":[]}')
            allocation=json.loads((data/'allocation.example.json').read_text());allocation['candidate_quota']=3;allocation['references'][0].update(candidate_quota=3,variant_indices=[0,1,2]);a=work/'allocation.json';a.write_text(json.dumps(allocation));run=work/'run'
            command=[sys.executable,str(script),'plan','--materials',str(bank),'--run',str(run),'--allocation',str(a),'--references',str(data/'references.example.jsonl'),'--profile-mapping',str(data/'profile_mapping.example.jsonl'),'--metadata-only']
            r=subprocess.run(command,cwd=work,capture_output=True,text=True);self.assertEqual(r.returncode,0,r.stderr)
            plans=[json.loads(x) for x in (run/'plans.jsonl').read_text().splitlines()];self.assertEqual(len(plans),3)
            self.assertTrue(all(x['status'].startswith('pending') for x in plans));self.assertTrue(all(x['reference_trace']['candidate_quota']==3 for x in plans))
            self.assertEqual([x['reference_trace']['candidate_index'] for x in plans],[0,1,2])

    def test_invalid_quota_indices_rejected(self):
        root=Path(__file__).resolve().parent;family=root/'P0/known_stem_mix';data=family/'_shared/data';script=family/'_shared/pipe_code/medium_pairs.py'
        with tempfile.TemporaryDirectory() as d:
            work=Path(d);bank=work/'bank.json';bank.write_text('{"materials":[]}');allocation=json.loads((data/'allocation.example.json').read_text());allocation['candidate_quota']=2;allocation['references'][0].update(candidate_quota=2,variant_indices=[0,2]);a=work/'allocation.json';a.write_text(json.dumps(allocation));run=work/'run'
            r=subprocess.run([sys.executable,str(script),'plan','--materials',str(bank),'--run',str(run),'--allocation',str(a),'--references',str(data/'references.example.jsonl'),'--profile-mapping',str(data/'profile_mapping.example.jsonl')],cwd=work,capture_output=True,text=True)
            self.assertNotEqual(r.returncode,0);self.assertFalse((run/'plans.jsonl').exists())

if __name__=='__main__':unittest.main()