Esempio n. 1
0
def resolve_all(set_successful=False,
                no_phases_is_success=False,
                report=MAIN_REPORT):
    """

    Args:
        set_success:
        report:
    """
    _setup_assertions(report)
    orderings = report['assertions']['relationships']
    phase_functions = report['assertions']['phase_functions']
    phase_names = report['assertions']['phases']
    phase_names = topological_sort(phase_names, orderings)
    #pprint(orderings)
    phase_success = no_phases_is_success
    for phase_name in phase_names:
        phase_success = True
        for function in phase_functions[phase_name]:
            try:
                phase_success = phase_success and (function() is not False)
            except AssertionBreak:
                phase_success = False
            except SandboxStudentCodeException:
                phase_success = False
        if not phase_success:
            break

    #for f in report.feedback:
    #    print("\t", f, f.mistake, f.misconception)
    if not report['assertions'][
            'failures'] and phase_success and set_successful:
        set_success()

    _reset_phases(report)
Esempio n. 2
0
 def test_gently_and_set_success(self):
     clear_report()
     gently("What have you done?")
     set_success()
     final = simple.resolve()
     self.assertFalse(final.success)
     self.assertEqual(final.message, 'What have you done?')
Esempio n. 3
0
def load_question(data):
    """

    :param data:
    :return:
    """
    ast = parse_program()
    student_data = commands.get_student_data()
    # Check that there aren't any invalid syntactical structures
    # Get all of the function ASTs in a dictionary
    function_definitions = {
        definition._name: definition
        for definition in ast.find_all("FunctionDef")
    }
    settings = DEFAULT_SETTINGS.copy()
    settings.update(data.get('settings', {}))
    rubric = settings.get('rubric', {})
    function_points = 0
    if 'functions' in data:
        function_rubric = rubric.get('functions', {})
        successes = []
        for function in data['functions']:
            success = False
            try:
                definition = check_function_defined(function,
                                                    function_definitions,
                                                    settings)
                function_points += function_rubric.get('definition', 10)
                check_function_signature(function, definition, settings)
                function_points += function_rubric.get('signature', 10)
                student_function = check_function_value(
                    function, student_data, settings)
                function_points += function_rubric.get('value', 0)
            except FeedbackException as fe:
                yield fe.as_message(), fe.label
            else:
                try:
                    check_cases(function, student_function, settings)
                except FeedbackException as fe:
                    success_ratio = (
                        1.0 -
                        fe.fields['failure_count'] / fe.fields['cases_count'])
                    function_points += function_rubric.get(
                        'cases', 80 * success_ratio)
                    yield fe.as_message(), fe.label
                else:
                    function_points += function_rubric.get('cases', 80)
                    success = True
            successes.append(success)
        function_points /= len(data['functions'])
        if all(successes):
            set_success()
        else:
            give_partial(function_points,
                         tool=TOOL_NAME,
                         justification="Passed some but not all unit tests")
Esempio n. 4
0
 def test_success_suppression(self):
     clear_report()
     contextualize_report('a=0\na')
     verify()
     tifa_analysis()
     set_success()
     suppress(label='set_success')
     final = simple.resolve()
     self.assertEqual(Feedback.CATEGORIES.COMPLETE, final.category)
     self.assertEqual(SUCCESS_MESSAGE, final.title+"\n"+final.message)
Esempio n. 5
0
 def test_success(self):
     clear_report()
     contextualize_report('a=0\na')
     verify()
     tifa_analysis()
     set_success()
     final = simple.resolve()
     self.assertEqual(Feedback.CATEGORIES.COMPLETE, final.category)
     self.assertEqual("Complete", final.title)
     self.assertEqual("Great work!", final.message)
Esempio n. 6
0
    def test_partials(self):
        with Execution('0') as e:
            gently("You were incorrect.")
            give_partial(.1, message="You had a zero in your code.")
            give_partial(.1, message="You looped correctly.")
        self.assertFeedback(e, "Instructor Feedback\nYou were incorrect.")
        self.assertEqual(.2, e.final.score)
        self.assertFalse(e.final.success)

        with Execution('0') as e:
            give_partial(.1, message="You had a zero in your code.")
            give_partial(.1, message="You looped correctly.")
            gently("Okay but you still only wrote 0.")
        self.assertEqual(e.final.message, "Okay but you still only wrote 0.")
        self.assertEqual(e.final.score, .2)
        self.assertFalse(e.final.success)

        with Execution('0') as e:
            give_partial(.1, message="You had a zero in your code.")
            give_partial(.1, message="You looped correctly.")
            set_success()
        self.assertEqual(e.final.message, "Great work!")
        self.assertEqual(e.final.score, 1.2)
        self.assertTrue(e.final.success)
Esempio n. 7
0
"""
This file is meant to be an idealized example of Pedal with a completely generic autograding environment that
wants to do as little work as possible.
"""

from pedal.environments.quick import setup_pedal
from pedal.core.commands import set_success

ast, student, resolve = setup_pedal(main_code="print('Hello world!')")

if ast.find_all("Call"):
    set_success()

resolve()
Esempio n. 8
0
 def test_set_success(self):
     clear_report()
     set_success()
     final = simple.resolve()
     self.assertTrue(final.success)
     self.assertEqual(final.message, 'Great work!')