python_traceback.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can identify the buf and fix a program that handles python tracebacks. Useful to know if the model can handle more advanced python libraries."
  3. TAGS = ['code', 'fix']
  4. question = """
  5. Fix this program. Make sure to keep the format "var: value".
  6. import traceback
  7. def foo():
  8. y = 6
  9. raise Exception("This is a test exception")
  10. def crashes():
  11. x = 5
  12. foo()
  13. if __name__ == "__main__":
  14. try:
  15. crashes()
  16. except:
  17. # extract stack frames
  18. stack = traceback.extract_stack()
  19. # print all locals in each stack frame
  20. for frame in stack:
  21. for k,v in frame.locals:
  22. print(k + ": " + v)
  23. """
  24. TestProgramTB = question >> LLMRun() >> ExtractCode(keep_main=True) >> PythonRun("") >> (SubstringEvaluator("x: 5") & SubstringEvaluator("y: 6"))
  25. if __name__ == "__main__":
  26. print(run_test(TestProgramTB))