Datasets:
Formats:
json
Languages:
English
Size:
< 1K
Tags:
recursive-self-improvement
program-synthesis
term-rewriting
automated-reasoning
formal-methods
benchmark
File size: 2,297 Bytes
be823b7 | 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | """Offline tests for deterministic data conversion and mismatch rejection."""
import hashlib
import importlib.util
import json
import shutil
import tempfile
import unittest
from pathlib import Path
MODULE=Path(__file__).with_name('export_data.py')
spec=importlib.util.spec_from_file_location('export_data',MODULE)
exporter=importlib.util.module_from_spec(spec)
spec.loader.exec_module(exporter)
class ExportTests(unittest.TestCase):
source=Path(__file__).parent/'research'
def test_determinism_schema_and_integrity(self):
source_hashes={p.relative_to(self.source).as_posix():hashlib.sha256(p.read_bytes()).hexdigest() for p in self.source.rglob('*') if p.is_file()}
with tempfile.TemporaryDirectory() as d:
a,b=Path(d)/'a',Path(d)/'b'
exporter.export(self.source,a)
exporter.export(self.source,b)
for name,count in [('cases.jsonl',24),('generations.jsonl',192)]:
self.assertEqual((a/name).read_bytes(),(b/name).read_bytes())
rows=[json.loads(s) for s in (a/name).read_text().splitlines()]
self.assertEqual(len(rows),count)
keys=set(rows[0])
for row in rows:
self.assertEqual(set(row),keys)
for key,value in row.items():
self.assertIn(type(value),(str,int,float,bool,type(None)))
self.assertEqual(type(value),type(rows[0][key]))
self.assertEqual(source_hashes,{p.relative_to(self.source).as_posix():hashlib.sha256(p.read_bytes()).hexdigest() for p in self.source.rglob('*') if p.is_file()})
def test_snapshot_mismatch_rejected(self):
with tempfile.TemporaryDirectory() as d:
copy=Path(d)/'research'
shutil.copytree(self.source,copy)
path=copy/'snapshots/n8_seed81200_g1.json'
payload=json.loads(path.read_text())
payload['known_semantics'] += 1
path.write_text(json.dumps(payload))
with self.assertRaises(AssertionError):
exporter.export(copy,Path(d)/'data')
if __name__=='__main__':
import sys
if len(sys.argv)>1 and sys.argv[1]=='--source':
ExportTests.source=Path(sys.argv[2]); del sys.argv[1:3]
unittest.main()
|