Download tests/test_contract.py from chrisuser/neuro-compiler: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/chrisuser/neuro-compiler/resolve/main/tests/test_contract.py
- Command line
-
hf download hf://chrisuser/neuro-compiler/tests/test_contract.py
-
curl -L -o test_contract.py https://huggingface.co/chrisuser/neuro-compiler/resolve/main/tests/test_contract.py
1.42 kB
| import unittest | |
| from neuro_compiler import NeuralCompiler | |
| from neuro_compiler.neurocc_graph_live import raw_bytes | |
| class Contract(unittest.TestCase): | |
| def test_invalid_sources(self): | |
| for source in ('', 'int f(){return 1;}', 'unsigned f(unsigned a,unsigned b,unsigned c){return (a/2u);}', 'unsigned f(unsigned a,unsigned b,unsigned c){return (a+64u);}', '\x00', 'λ'): | |
| with self.assertRaises(ValueError): NeuralCompiler._inputs([source]) | |
| with self.assertRaises(TypeError): NeuralCompiler._inputs('source') | |
| def test_byte_contract(self): | |
| for row in ([195,257,257],[195,256],[257],[195,257,0],[999,257]): self.assertIsNone(raw_bytes(row)) | |
| self.assertEqual(raw_bytes([195,257,256]),b'\xc3') | |
| def test_missing_and_corrupted_weights(self): | |
| from pathlib import Path | |
| import tempfile | |
| import shutil | |
| source=Path(__file__).resolve().parents[1]/'manifest.json' | |
| with tempfile.TemporaryDirectory() as folder: | |
| root=Path(folder); shutil.copy2(source,root/'manifest.json') | |
| with self.assertRaises(FileNotFoundError): NeuralCompiler.from_pretrained(root,device='cpu') | |
| (root/'weights').mkdir(); (root/'weights/ast.safetensors').write_bytes(b'corrupted') | |
| with self.assertRaisesRegex(ValueError,'integrity'): NeuralCompiler.from_pretrained(root,device='cpu') | |
| if __name__=='__main__': unittest.main() | |