39 lines
2.4 KiB
Python
39 lines
2.4 KiB
Python
import json
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
from unittest.mock import patch
|
|
import unittest
|
|
import numpy as np
|
|
from scipy.sparse import csr_matrix
|
|
import phase2_b11_gate as gate
|
|
|
|
|
|
class IntegrationTests(unittest.TestCase):
|
|
def test_out_of_fold_selection_rejects_learning_substitution(self):
|
|
row=dict(case='synthetic',assignments=[dict(fold=0,role='learning'),dict(fold=2,role='test')])
|
|
learning=dict(case='synthetic',protocol='grouped',pool=100,fold=0)
|
|
test=dict(case='synthetic',protocol='grouped',pool=100,fold=2)
|
|
self.assertEqual(gate.select_entry(row,[learning,test]),test)
|
|
with self.assertRaises(ValueError):gate.select_entry(row,[learning])
|
|
with self.assertRaises(ValueError):gate.select_entry(row,[test,test])
|
|
def test_eik_build_never_requires_target_files(self):
|
|
with TemporaryDirectory() as tmp:
|
|
base=Path(tmp);b3=base/'b3';d=b3/'parts/synthetic';d.mkdir(parents=True)
|
|
a=csr_matrix(([1.,1.,1.,1.],([0,1,1,2],[1,0,2,1])),shape=(3,3));raw=np.array([10,20,30])
|
|
np.savez(d/'geometry.npz',points=np.c_[np.arange(3),np.zeros((3,2))],raw_ids=raw,mass=[.970,.015,.015],rg=1.,data=a.data,indices=a.indices,indptr=a.indptr)
|
|
cache=base/'cache';cache.mkdir();np.save(cache/'Vf.npy',[4.,1.,2.])
|
|
row=dict(case='synthetic',component_id='synthetic',v5_cache=dict(output=str(cache),output_sha256={'Vf.npy':gate.sha(cache/'Vf.npy')}),preparation=dict(t_set=1.))
|
|
root=base/'gate';(root/'phases/eik-build').mkdir(parents=True)
|
|
c=dict(parts=[row],source_sha256={str(d/'geometry.npz'):gate.sha(d/'geometry.npz')},threshold=.020,disk_bytes=1024**3)
|
|
(root/'contract.json').write_text(json.dumps(c))
|
|
with patch.object(gate,'B3',b3):gate.build(root,c,'eik')
|
|
result=json.loads((root/'phases/eik-build/manifest.json').read_text());self.assertFalse(result['failures']);self.assertEqual(len(result['entries']),1)
|
|
with np.load(result['entries'][0]['path']) as z:np.testing.assert_array_equal(z['clean'],[4.,1.,1.])
|
|
self.assertFalse(result['entries'][0]['target_values_read']);self.assertFalse((cache/'seconds.npy').exists())
|
|
def test_scoring_requires_parent_git_freeze_authorization(self):
|
|
with TemporaryDirectory() as tmp:
|
|
with self.assertRaises(FileNotFoundError):gate.score(Path(tmp),{},'eik')
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|