def from_json(cls, data): new = object.__new__(cls) for k, v in data.items(): setattr(new, k, v) new.case = TestCase.from_json(new.case) new.answer_key = TestCase.from_json(new.answer_key) new.grade = decimal.Decimal(new.grade) return new
def feedback(response: TestCase, answer_key: TestCase): """Return a feedback structure that represents the success/error for a single testcase.""" grade = decimal.Decimal(0) status = None # Error messages if isinstance(response, ErrorTestCase): status = response.type # Correct response elif list(response) == list(answer_key): status = 'ok' grade = decimal.Decimal(1.0) # Presentation errors elif presentation_equal(response, answer_key): status = 'wrong-presentation' grade = decimal.Decimal(0.5) # Wrong answer elif isinstance(response, IoTestCase): status = 'wrong-answer' # Invalid else: raise ValueError('invalid testcase: \n%s' % response.format()) return Feedback(response, answer_key, grade=grade, status=status)
def feedback(response: TestCase, answer_key: TestCase): """Return a feedback structure that represents the success/error for a single testcase.""" grade = decimal.Decimal(0) status = None # Error messages if isinstance(response, ErrorTestCase): status = response.type # Correct response elif list(response) == list(answer_key): status = 'ok' grade = decimal.Decimal(1.0) # Presentation errors elif presentation_equal(response, answer_key): status = 'wrong-presentation' grade = decimal.Decimal(0.5) # Wrong answer elif isinstance(response, SimpleTestCase): status = 'wrong-answer' # Invalid else: raise ValueError('invalid testcase: \n%s' % response.format()) return Feedback(response, answer_key, grade=grade, status=status)
def from_json(cls, data): kwargs = dict(data) testcase = TestCase.from_json(kwargs.pop('testcase')) answer_key = TestCase.from_json(kwargs.pop('answer_key')) return Feedback(testcase, answer_key, **kwargs)