def test_mandatory_property(self): (mark, reasons) = grade([CheckResult(True, '', '', '')]) self.assertEqual(mark, 2, 'if all tests are passed, the grade should be 2') (mark, reasons) = grade( [CheckResult(False, '', '', '', should_succeed=False)]) self.assertEqual( mark, 5, 'no positive grade without passing one positive test') (mark, reasons) = grade([ CheckResult(False, '', '', '', should_succeed=False), CheckResult(True, '', '', '', should_succeed=True) ]) self.assertEqual(mark, 2, 'postive grade with at least one positive test') (mark, reasons) = grade([ CheckResult(True, '', '', '', should_succeed=True), CheckResult(True, '', '', '', should_succeed=True), CheckResult(True, '', '', '', should_succeed=True), CheckResult(True, '', '', '', should_succeed=True), CheckResult(False, '', '', '', should_succeed=True, mandatory=True) ]) self.assertEqual(mark, 5, 'can not pass when failing a mandatory test')
def check_assignment(assignment, base_test): if assignment[3] != base_test: base_test(mandatory=True) set_assignment_name(assignment[2]) print_message('executing test \'{}\''.format(assignment[0])) assignment[3]() set_assignment_name('') grade()
def test_mandatory_property(self, mock): mock.side_effect = self.save_grade enter_quiet_mode() record_result(True, '', '', '') grade() self.assertEqual(self.grade, 2, 'if all tests are passed, the grade should be 2') record_result(False, '', '', '', should_succeed=False) grade() self.assertEqual( self.grade, 5, 'no positive grade without passing one positive test') record_result(False, '', '', '', should_succeed=False) record_result(True, '', '', '', should_succeed=True) grade() self.assertEqual(self.grade, 2, 'postive grade with at least one positive test') record_result(True, '', '', '', should_succeed=True) record_result(True, '', '', '', should_succeed=True) record_result(True, '', '', '', should_succeed=True) record_result(True, '', '', '', should_succeed=True) record_result(False, '', '', '', should_succeed=True, mandatory=True) grade() self.assertEqual(self.grade, 5, 'can not pass when failing a mandatory test')
def check_assignment(assignment, base_test): global assignment_path if assignment[3] != base_test: base_test(mandatory=True) assignment_path = assignment[2] print('executing test \'{}\''.format(assignment[0])) assignment[3]() assignment_path = '' grade()
def check_assignment(assignment: Assignment, baseline: Assignment) -> Tuple[int, List[str]]: def check(a: Assignment): return list(map(execute_with_output, a.create_checks())) def change_result_to_mandatory(r: CheckResult): return CheckResult(r.result, r.msg, r.output, r.warning, r.should_succeed, r.command, True) if assignment != baseline: baseline_results = list( map(change_result_to_mandatory, check(baseline))) else: baseline_results = [] set_assignment_name(assignment.category) print_message('executing test \'{}\''.format(assignment.name)) results = baseline_results + check(assignment) set_assignment_name('') (grade_value, reasons) = grade(results) for reason in reasons: print_warning(reason) print_grade(grade_value)