Datasets:
Formats:
json
Languages:
English
Size:
< 1K
Tags:
recursive-self-improvement
program-synthesis
term-rewriting
automated-reasoning
formal-methods
benchmark
Download test_export_data.py from PureOne/Nhais-DQ-Recursive-Search-Contraction: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/datasets/PureOne/Nhais-DQ-Recursive-Search-Contraction/resolve/main/test_export_data.py
- Command line
-
hf download hf://datasets/PureOne/Nhais-DQ-Recursive-Search-Contraction/test_export_data.py
-
curl -L -o test_export_data.py https://huggingface.co/datasets/PureOne/Nhais-DQ-Recursive-Search-Contraction/resolve/main/test_export_data.py
2.3 kB
| """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() | |