icp/oer/exercise-formats/input/text/controller.py

37 lines
837 B
Python
Raw Normal View History

2018-05-05 22:18:02 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# program/match-regex
# Standardized types do not require authors to specify any control script as
# it can be generated on import. However when provided it will overwrite the
# default behaivior.
import sys
import subprocess
import re
def grade(ctx):
"""A function that governs the grading process when different from default.
Expected is return value that indicates if the task passed or failed."""
print(ctx.data['data']['regex'], file=sys.stderr)
print(ctx.data['solution'], file=sys.stderr)
if re.match(ctx.data['data']['regex'], ctx.data['solution') != None:
return 'PASS'
else:
return 'FAIL'
def response(ctx):
grade = ctx.grade_result
msg = ""
return {'output': output, 'grade': grade, 'msg': msg, 'data': None}