File size: 851 Bytes
87cc7f2 | 1 2 3 4 5 6 7 8 9 10 | import ast,re,sys,unittest
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'src'))
from long_protocol import strict_extract
class CompareAuthors(unittest.TestCase):
def test_matches_authors_extraction(self):
tree=ast.parse(Path('research_source/mathqa.py').read_text(encoding='utf8'));names={'answer_text','_box_at','last_boxed','extract'};parts=[x for x in tree.body if isinstance(x,ast.FunctionDef) and x.name in names];module=ast.Module(body=parts,type_ignores=[]);ns={'re':re,'_BOX_FORMS':re.compile(r'\\boxed|\\fbox')};exec(compile(module,'upstream_mathqa.py','exec'),ns)
cases=[r'no box',r'\boxed{2}',r'\boxed{1} </think> \boxed{\frac{1}{2}}',r'\boxed{3} and \boxed{',r'\boxed 9$',r'\fbox{4}',r'\boxed{2} then \fbox{3}']
for t in cases:self.assertEqual(strict_extract(t),ns['extract'](t)[0],t)
|