Download tests/test_core.py from dotlabs/smolscript: direct link, hf CLI and curl.
- Browser
- Download file 3.89 kB
-
https://huggingface.co/datasets/dotlabs/smolscript/resolve/main/tests/test_core.py
- Command line
-
hf download hf://datasets/dotlabs/smolscript/tests/test_core.py
-
curl -L -o test_core.py https://huggingface.co/datasets/dotlabs/smolscript/resolve/main/tests/test_core.py
3.89 kB
| import ast | |
| import json | |
| from pathlib import Path | |
| import sys | |
| import unittest | |
| from unittest.mock import patch | |
| ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT)) | |
| from evaluate import prompt | |
| from metrics import aggregate | |
| from runners.common import extract_code,compare_output,FunctionRunner,BrowserRunner | |
| from runners.sandbox import Sandbox,SandboxUnavailable | |
| from validators.dataset import load | |
| class CoreTests(unittest.TestCase): | |
| def test_default_subset_is_fixed_and_preserves_original_tasks(self): | |
| from generators.subset import select | |
| from collections import Counter | |
| archive=load(ROOT/'archive/v0.2.0/smolscript.jsonl') | |
| rows=load(ROOT/'data/smolscript.jsonl') | |
| self.assertEqual(len(rows),350) | |
| self.assertEqual(select(archive),rows) | |
| self.assertEqual(select(list(reversed(archive)))[::-1],rows) | |
| self.assertEqual(Counter(r['difficulty'] for r in rows),{'easy':210,'medium':105,'moderate':35}) | |
| original={r['id']:r for r in archive} | |
| for r in rows: | |
| for key in ('prompt','output_format','tests'):self.assertEqual(r[key],original[r['id']][key]) | |
| def test_decode_settings_do_not_read_solutions(self): | |
| from generation_settings import DEFAULT_BATCH_SIZE,token_budget | |
| self.assertEqual(DEFAULT_BATCH_SIZE,64) | |
| rows=load(ROOT/'data/smolscript.jsonl') | |
| self.assertTrue(all(96<=token_budget(r)<=256 for r in rows)) | |
| def test_prompt_has_no_reference_or_tests(self): | |
| row=load(ROOT/'data/smolscript.jsonl')[0];row['tests']=[{'input':'SECRET_TEST','expected':'SECRET_ANSWER'}];row['reference_solution']='SECRET_REFERENCE' | |
| text=prompt(row) | |
| for token in ('SECRET_TEST','SECRET_ANSWER','SECRET_REFERENCE'):self.assertNotIn(token,text) | |
| def test_macro_not_micro(self): | |
| rows=[{'id':str(i),'language':'python','passed':True,'syntax_success':True} for i in range(3)] | |
| rows+=[{'id':'x','language':'rust','passed':False,'syntax_success':True}] | |
| result=aggregate(rows,[r['id'] for r in rows],full_run=False) | |
| self.assertEqual(result['filtered_macro_score'],50);self.assertEqual(result['micro_accuracy'],75) | |
| self.assertNotIn('smolscript_score',result) | |
| def test_incomplete_results_rejected(self): | |
| with self.assertRaises(ValueError):aggregate([],['missing']) | |
| def test_whitespace_observable_and_numeric_format(self): | |
| self.assertTrue(compare_output(' a \n',' a '));self.assertFalse(compare_output('a\n',' a')) | |
| self.assertTrue(compare_output('2.0\n',2));self.assertFalse(compare_output('NaN\n',2)) | |
| def test_extraction(self): | |
| self.assertEqual(extract_code('```python\ndef solve(n): return n\n```'),'def solve(n): return n\n') | |
| with self.assertRaises(ValueError):extract_code('```a\nx\n```\n```b\ny\n```') | |
| def test_missing_engine_fails_closed(self): | |
| with patch('runners.sandbox.shutil.which',return_value=None),self.assertRaises(SandboxUnavailable):Sandbox() | |
| def test_python_reference_syntax(self): | |
| ids={r['id'] for r in load(ROOT/'data/smolscript.jsonl') if r['language']=='python'} | |
| for r in load(ROOT/'references/solutions.jsonl'): | |
| if r['id'] in ids:ast.parse(r['reference_solution']) | |
| def test_answers_not_sent_to_sandbox(self): | |
| class Fake: | |
| def run(self,payload,timeout): | |
| self.payload=payload | |
| return {'syntax_success':True,'observations':[{'exit_code':0,'timeout':False,'output_limit':False,'stdout':'9\n'}]} | |
| fake=Fake();row={'language':'python','timeout_seconds':3,'metadata':{'family':'scalar'}} | |
| result=FunctionRunner().evaluate(row,'def solve(n): return 9',{'tests':[{'input':3,'expected':9}]},fake) | |
| self.assertTrue(result['passed']);self.assertNotIn('expected',json.dumps(fake.payload)) | |
| if __name__=='__main__':unittest.main() | |