1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from evaluator import *

DESCRIPTION = "Test if the model can write a Python function that removes excess indentation from a given block of code."

TAGS = ['code', 'python']

question = """
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.
"""

test_case, answer = make_python_test([("""dedent('''    print("hello")
    print("world")

    if True:
        print("true")
    else:
        print("false")''')""", '''"""print("hello")
print("world")

if True:
    print("true")
else:
    print("false")"""''')])


TestDedent = question >> LLMRun() >> ExtractCode(keep_main=True) >> PythonRun(test_case) >> SubstringEvaluator(answer)

if __name__ == "__main__":
    print(run_test(TestDedent))