dedent_code_fn.py 794 B

123456789101112131415161718192021222324252627282930
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can write a Python function that removes excess indentation from a given block of code."
  3. TAGS = ['code', 'python']
  4. question = """
  5. Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
  6. """
  7. test_case, answer = make_python_test([("""dedent(''' print("hello")
  8. print("world")
  9. if True:
  10. print("true")
  11. else:
  12. print("false")''')""", '''"""print("hello")
  13. print("world")
  14. if True:
  15. print("true")
  16. else:
  17. print("false")"""''')])
  18. TestDedent = question >> LLMRun() >> ExtractCode(keep_main=True) >> PythonRun(test_case) >> SubstringEvaluator(answer)
  19. if __name__ == "__main__":
  20. print(run_test(TestDedent))