示例#1
0
    def __init__(self, template=None):
        answers = get_answers()
        with open("student", "w+") as f:
            f.write(answers['answer'])
        try:
            self.pld = json.load(open("pl.json", "r"))

        except Exception as e:

            self.fb = Feedback(template)
            self.fb.adddiv("err",
                           "# erreur de plateforme \n pl.json illissible\n")
            self.fb.success = True
            self.fb.flags = "-Wall -ansi"
            self.doOutput()
            sys.exit(1)
        self.fb = Feedback(template)
        self.fb.success = True
        self.fb.flags = "-Wall -ansi"
示例#2
0
    if len(sys.argv) < 5:
        msg = ("Sandbox did not call grader properly:\n"
               + "Usage: python3 grader.py [input_json] [output_json] [answer_file] [feedback_file]")
        print(msg, file=sys.stderr)
        sys.exit(1)

    from pltest_doc import PlRunner
    dic = get_context()
    if "pltest" not in dic and "pltest1" not in dic:
        print("No pltest neither pltest1-n  defined change template", file=sys.stderr)
        sys.exit(1)
    if 'stopfirsterror' in dic:
        stop=bool(dic['stopfirsterror'])
    else:
        stop=False
    student = get_answers()['answer']
    outstr=""
    if "pltest" in dic:
        pltest = dic['pltest']
        tester = PlRunner(student,pltest)
        a, b = tester.runpltest(1)
    else:
        a,b= True, ""
    i=1
    while "pltest"+str(i) in dic and (a or stop ) :
        outstr += b
        testi = PlRunner(student,dic["pltest"+str(i)])
        a, b = testi.runpltest(i+1)
        i=i+1

    outstr +=  b
示例#3
0
missing_score_stderr = """\
'evaluator' did not declare the variable 'score'.
The script have access to every variable declared in the PL and its 'before' script.
It should declare a variable 'score' which should contain an integer between [0, 100]."""

if __name__ == "__main__":
    if len(sys.argv) < 5:
        msg = (
            "Sandbox did not call grader properly:\n" +
            "Usage: python3 grader.py [input_json] [output_json] [answer_file] [feedback_file]"
        )
        print(msg, file=sys.stderr)
        sys.exit(1)

    dic = get_context()
    dic['answer'] = get_answers()
    if 'evaluator' in dic:
        glob = {}
        dic['StopEvaluatorExec'] = StopEvaluatorExec
        code = ""
        if 'headevaluator' in dic:
            code += dic['headevaluator'] + '\n'
        code += dic['evaluator'] + '\n'
        if 'footerevaluator' in dic:
            code += dic['footerevaluator']
        exec(add_try_clause(code, StopEvaluatorExec), dic)
        exec("", glob)
        for key in glob:
            if key in dic and dic[key] == glob[key]:
                del dic[key]
    else:
示例#4
0
answer of the student. The function should return a tuple (int, feedback) where int is the grade
between [0, 100]."""

missing_grade_stderr = """\
'evalfunc' did not return a tuple (int, feedback) where int is the grade between [0, 100]."""

if __name__ == "__main__":
    if len(sys.argv) < 5:
        msg = (
            "Sandbox did not call grader properly:\n" +
            "Usage: python3 grader.py [input_json] [output_json] [answer_file] ["
            "feedback_file]")
        print(msg, file=sys.stderr)
        sys.exit(1)

    dic = get_context()
    answers = get_answers()
    if 'evalfunc' in dic:
        exec(dic['evalfunc'], globals())
        grade = evalfunc(dic, answers)
    else:
        print(missing_evaluator_stderr, file=sys.stderr)
        sys.exit(1)

    if len(grade) < 2 or type(grade[0]) is not int or type(
            grade[1]) is not str:
        print(missing_grade_stderr, file=sys.stderr)
        sys.exit(1)

    output(grade[0], grade[1], dic)
示例#5
0
        if taboos:
            feedback = "These words are disallowed an cannot be used: " + str(
                taboos)
            sandboxio.output(-1, feedback)

        tests = grader.run_tests()
        if tests:
            grade, feedback = cls.parse_tests_result(tests)
            sandboxio.output(grade, feedback)

        junit = grader.run_junit()
        if junit:
            grade, feedback = junit
            feedback = (
                "<pre><code>%s</code></pre>" %
                feedback.replace("[36m", "").replace("[34m", "").replace(
                    "[32m", "").replace("[31m", "").replace("[0m", ""))
            sandboxio.output(grade, feedback)

        print(
            "Both of the keys 'stdout_tests' and 'junit' are missing. At least one must be "
            "present for the Grader to be able to grade the student's answer.",
            file=sys.stderr)
        sys.exit(1)


if __name__ == "__main__":
    answers = sandboxio.get_answers()
    context = sandboxio.get_context()
    Grader.grade(context, answers)
示例#6
0
#!/usr/bin/env python3
# coding: utf-8
import sys, jsonpickle
from sandboxio import output, get_context, get_answers

missing_evaluator_stderr = """\
The key 'evaluator' was not found in the context.
When using this grader, the PL must declare a script inside a key 'evaluator'. This script have
access to every variable declared in the PL and its 'before' script.
It should declare a variable 'grade' which should contain a tuple (int, feedback) where int is the grade between [0, 100]."""
missing_grade_stderr = """\
'evaluator' did not declare the variable 'grade'. 
The script have access to every variable declared in the PL and its 'before' script.
It should declare a variable 'grade' which should contain a tuple (int, feedback) where int is the grade between [0, 100]."""
if __name__ == "__main__":
    if len(sys.argv) < 5:
        msg = (
            "Sandbox did not call grader properly:\n" +
            "Usage: python3 grader.py [input_json] [output_json] [answer_file] [feedback_file]"
        )
        print(msg, file=sys.stderr)
        sys.exit(1)
    dic = get_context()

    studentdic = get_answers()
    dic["text"] = " Passez à l'exercice suivant "
    dic["form"] = ""

    output(100, " Merci de votre réponse  ", dic)
示例#7
0
missing_grade_stderr = """\
'evaluator' did not declare the variable 'grade'.
The script have access to every variable declared in the PL and its 'before' script.
It should declare a variable 'grade' which should contain a tuple (int, feedback) where int is the grade between [0, 100]."""

if __name__ == "__main__":
    if len(sys.argv) < 5:
        msg = (
            "Sandbox did not call grader properly:\n" +
            "Usage: python3 grader.py [input_json] [answer_jsonfile] [output_json] [feedback_file]"
        )
        print(msg, file=sys.stderr)
        sys.exit(1)

    dic = get_context()
    dic['response'] = get_answers()
    if 'evaluator' in dic:
        glob = {}
        dic['StopEvaluatorExec'] = StopEvaluatorExec
        exec(add_try_clause(dic['evaluator'], StopEvaluatorExec), dic)
        exec("", glob)
        for key in glob:
            if key in dic and dic[key] == glob[key]:
                del dic[key]
    else:
        print(missing_evaluator_stderr, file=sys.stderr)
        sys.exit(1)

    if 'grade' not in dic:
        print(missing_grade_stderr, file=sys.stderr)
        sys.exit(1)
示例#8
0
import graderC


if __name__ == "__main__":
    """
    This program proceed the grading of standard C sandbox exercice
    """
    if len(sys.argv) < 5:
        msg = ("Sandbox did not call grader properly:\n"
               +"Usage: python3 grader.py [input_json] [answer_file] [output_json] [feedback_file]")
        print(msg, file=sys.stderr)
        sys.exit(1)
    
    # Here
    dic = get_context()
    truc = get_answers() # {'answer':value } pas que form_answer 
    with open("basic.c","w") as basic:
        basic.write(truc["answer"])
        # print(truc["answer"], file=sys.stderr)
    basic.close()

    from graderC import graderI, graderII
    assert('tests' in dic), "Your exercice should defined tests inside a tests pl markup environement.%s %s"%(str(dic), str(dic['dic']))
    dico_tests = eval( dic['tests'] )
    if (len(dico_tests) == 0):
        print("Your exercice do not define any test ! You shoul add at least one test.", file=sys.stderr)
        sys.exit(1)
    if len(dico_tests[0]) not in [3, 4]:
        print("Your tests do not appear to be valid with the available graders.", file=sys.stderr)
        sys.exit(1)