def test_save_score(self): auth.login_user(db.auth_user(11)) # the db contains a pre-existing answer of 0.0 percent correct db.useinfo.insert(sid='user_11', timestamp=datetime.datetime.now(), event='unittest', course_id='testcourse', div_id='ex_5_8', act='percent:0.5:passed:2:failed:2') sc = _autograde_one_q(course_name='testcourse', sid='user_11', question_name='ex_5_8', points=10, question_type='actex', deadline=None, autograde='pct_correct', which_to_grade='first_answer', save_score=True, db=db) self.assertEqual(sc, 0) res = db((db.question_grades.sid=='user_11') & (db.question_grades.div_id == 'ex_5_8')).select().first() self.assertEqual(0.0, res.score) sc = _autograde_one_q(course_name='testcourse', sid='user_11', question_name='ex_5_8', points=10, question_type='actex', deadline=None, autograde='pct_correct', which_to_grade='last_answer', save_score=True, db=db) self.assertEqual(5,sc) sc = _autograde_one_q(course_name='testcourse', sid='user_11', question_name='ex_5_8', points=10, question_type='actex', deadline=None, autograde='pct_correct', which_to_grade='best_answer', save_score=True, db=db) self.assertEqual(5,sc) res = db((db.question_grades.sid=='user_11') & (db.question_grades.div_id == 'ex_5_8')).select().first() self.assertEqual(5.0, res.score) sc = _autograde_one_q(course_name='testcourse', sid='user_11', question_name='ex_5_8', points=10, question_type='actex', deadline=datetime.datetime.now() - datetime.timedelta(days=1), autograde='pct_correct', which_to_grade='best_answer', save_score=True, db=db) self.assertEqual(0,sc)
def test_reproduce_scores(self): # fetch all of the autograded questions_grades # with all the info about them graded = db((db.question_grades.comment == 'autograded') & (db.question_grades.div_id == db.questions.name) & (db.questions.id == db.assignment_questions.question_id) & (db.assignment_questions.assignment_id == db.assignments.id)).select( db.question_grades.id, db.question_grades.course_name, db.question_grades.sid, db.question_grades.div_id, db.question_grades.comment, db.question_grades.deadline, db.assignment_questions.id, db.assignment_questions.points, db.questions.id, db.questions.question_type, db.assignments.id, db.assignments.duedate, db.assignment_questions.autograde, db.assignment_questions.which_to_grade, db.question_grades.score) # for each one, see if the computed score matches the recorded one bad_count = 0 for g in graded: sc = _autograde_one_q( course_name=g.question_grades.course_name, sid=g.question_grades.sid, question_name=g.question_grades.div_id, points=g.assignment_questions.points, question_type=g.questions.question_type, deadline=g.question_grades.deadline, autograde=g.assignment_questions.autograde, which_to_grade=g.assignment_questions.which_to_grade, save_score=False, db=db) if sc != g.question_grades.score: print("got {} expected {}".format(sc, g.question_grades.score), g) bad_count += 1 # self.assertEqual(sc, # g.question_grades.score, # "Failed for graded question {} got a score of {}".format(g,sc)) # except: # bad_count += 1 self.assertEqual(bad_count, 0)
def test_reproduce_scores(self): # fetch all of the autograded questions_grades # with all the info about them graded = db((db.question_grades.comment == 'autograded') & (db.question_grades.div_id == db.questions.name) & (db.questions.id == db.assignment_questions.question_id) & (db.assignment_questions.assignment_id == db.assignments.id)).select( db.question_grades.id, db.question_grades.course_name, db.question_grades.sid, db.question_grades.div_id, db.question_grades.comment, db.question_grades.deadline, db.assignment_questions.id, db.assignment_questions.points, db.questions.id, db.questions.question_type, db.assignments.id, db.assignments.duedate, db.assignment_questions.autograde, db.assignment_questions.which_to_grade, db.question_grades.score) # for each one, see if the computed score matches the recorded one bad_count = 0 for g in graded: sc = _autograde_one_q(course_name=g.question_grades.course_name, sid=g.question_grades.sid, question_name=g.question_grades.div_id, points=g.assignment_questions.points, question_type=g.questions.question_type, deadline=g.question_grades.deadline, autograde=g.assignment_questions.autograde, which_to_grade=g.assignment_questions.which_to_grade, save_score=False, db=db) if sc != g.question_grades.score: print("got {} expected {}".format(sc, g.question_grades.score), g) bad_count += 1 # self.assertEqual(sc, # g.question_grades.score, # "Failed for graded question {} got a score of {}".format(g,sc)) # except: # bad_count += 1 self.assertEqual(bad_count, 0)
def test_save_score(self): auth.login_user(db.auth_user(11)) # the db contains a pre-existing answer of 0.0 percent correct db.useinfo.insert(sid='user_11', timestamp=datetime.datetime.now(), event='unittest', course_id='testcourse', div_id='ex_5_8', act='percent:0.5:passed:2:failed:2') sc = _autograde_one_q(course_name='testcourse', sid='user_11', question_name='ex_5_8', points=10, question_type='actex', deadline=None, autograde='pct_correct', which_to_grade='first_answer', save_score=True, db=db) self.assertEqual(sc, 0) res = db((db.question_grades.sid == 'user_11') & (db.question_grades.div_id == 'ex_5_8')).select().first() self.assertEqual(0.0, res.score) sc = _autograde_one_q(course_name='testcourse', sid='user_11', question_name='ex_5_8', points=10, question_type='actex', deadline=None, autograde='pct_correct', which_to_grade='last_answer', save_score=True, db=db) self.assertEqual(5, sc) sc = _autograde_one_q(course_name='testcourse', sid='user_11', question_name='ex_5_8', points=10, question_type='actex', deadline=None, autograde='pct_correct', which_to_grade='best_answer', save_score=True, db=db) self.assertEqual(5, sc) res = db((db.question_grades.sid == 'user_11') & (db.question_grades.div_id == 'ex_5_8')).select().first() self.assertEqual(5.0, res.score) sc = _autograde_one_q(course_name='testcourse', sid='user_11', question_name='ex_5_8', points=10, question_type='actex', deadline=datetime.datetime.now() - datetime.timedelta(days=1), autograde='pct_correct', which_to_grade='best_answer', save_score=True, db=db) self.assertEqual(0, sc)