LittlePlyResearch notebook

test_matched_nll.py

python · 34 lines · Exact bytes

Line 1 ↗
Version & provenance · foundation-20261029

Recorded SHA-256 56a08b92bf0263f3f30dc7448aa0ff3c498c784a4e1915afd392c3257fd50258Rendered SHA-256 09d3404761fd43c7612fe2ecee53d8b9aa9d041dbe81c901772f11704f1bb3fe

Original project code: Apache-2.0. Dependency licenses remain separate. License notes. Line links are stable within this snapshot. Allowlisted foundation training and frozen evaluation source; recorded hashes refer to original files, rendered hashes identify any path-redacted derivatives. This subset is not a standalone training distribution; no host configs, credentials, optimizer state or dataset bulk included.

1import json,tempfile,unittest
2from pathlib import Path
3from unittest.mock import patch
4import matched_nll as m
5
6class Guards(unittest.TestCase):
7    def test_frozen_sample_exact(self):
8        values,binding=m.sample()
9        self.assertEqual(binding,m.load(m.ROOT/'slice.json'))
10        self.assertEqual(len(values),7000)
11        self.assertEqual(sum(len(v)-1 for v in values),1595704)
12    def test_sample_mutation_rejected_before_terminal(self):
13        with patch.object(m,'sample',return_value=([],{})):
14            with self.assertRaisesRegex(ValueError,'fixed sample changed'):m.specification()
15    def test_requires_terminal_receipt(self):
16        real=m.load
17        def fake(p):
18            if Path(p).name=='four-hour-terminal-verification.json':return {'status':'running'}
19            return real(p)
20        with patch.object(m,'load',side_effect=fake):
21            with self.assertRaisesRegex(ValueError,'terminal training'):m.specification()
22    def test_worker_requires_guardian(self):
23        with self.assertRaisesRegex(ValueError,'owned guardian'):m.worker()
24    def test_approval_cannot_launch_changed_spec(self):
25        with patch.object(m,'specification',return_value={'fixed':1}),patch.object(m,'load',return_value={'approved':True,'specification':{'fixed':2}}):
26            with self.assertRaisesRegex(ValueError,'exact reviewed'):m.launch('unused')
27    def test_receipt_cannot_overwrite(self):
28        with tempfile.TemporaryDirectory() as td:
29            p=Path(td)/'receipt.json';m.write_new(p,{'a':1})
30            with self.assertRaises(FileExistsError):m.write_new(p,{'a':2})
31            self.assertEqual(json.loads(p.read_text()),{'a':1})
32
33if __name__=='__main__':unittest.main(verbosity=2)
34