Ejemplo n.º 1
0
    def test_grader_from_conf(self):

        # Confs always produce a graders.WeightedSubsectionsGrader, so we test this by repeating the test
        # in test_graders.WeightedSubsectionsGrader, but generate the graders with confs.

        weighted_grader = graders.grader_from_conf(
            [
                {"type": "Homework", "min_count": 12, "drop_count": 2, "short_label": "HW", "weight": 0.25},
                {"type": "Lab", "min_count": 7, "drop_count": 3, "category": "Labs", "weight": 0.25},
                {"type": "Midterm", "name": "Midterm Exam", "short_label": "Midterm", "weight": 0.5},
            ]
        )

        empty_grader = graders.grader_from_conf([])

        graded = weighted_grader.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded["percent"], 0.5106547619047619)
        self.assertEqual(len(graded["section_breakdown"]), (12 + 1) + (7 + 1) + 1)
        self.assertEqual(len(graded["grade_breakdown"]), 3)

        graded = empty_grader.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded["percent"], 0.0)
        self.assertEqual(len(graded["section_breakdown"]), 0)
        self.assertEqual(len(graded["grade_breakdown"]), 0)

        # Test that graders can also be used instead of lists of dictionaries
        homework_grader = graders.AssignmentFormatGrader("Homework", 12, 2)
        homework_grader2 = graders.grader_from_conf(homework_grader)

        graded = homework_grader2.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded["percent"], 0.11)
        self.assertEqual(len(graded["section_breakdown"]), 12 + 1)
Ejemplo n.º 2
0
    def test_grader_from_conf(self):

        # Confs always produce a graders.WeightedSubsectionsGrader, so we test this by repeating the test
        # in test_graders.WeightedSubsectionsGrader, but generate the graders with confs.

        weighted_grader = graders.grader_from_conf([
            {
                'type': "Homework",
                'min_count': 12,
                'drop_count': 2,
                'short_label': "HW",
                'weight': 0.25,
            },
            {
                'type': "Lab",
                'min_count': 7,
                'drop_count': 3,
                'category': "Labs",
                'weight': 0.25
            },
            {
                'type': "Midterm",
                'min_count': 0,
                'drop_count': 0,
                'name': "Midterm Exam",
                'short_label': "Midterm",
                'weight': 0.5,
            },
        ])

        empty_grader = graders.grader_from_conf([])

        graded = weighted_grader.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded['percent'], 0.50812499999999994)
        self.assertEqual(len(graded['section_breakdown']),
                         (12 + 1) + (7 + 1) + 1)
        self.assertEqual(len(graded['grade_breakdown']), 3)

        graded = empty_grader.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded['percent'], 0.0)
        self.assertEqual(len(graded['section_breakdown']), 0)
        self.assertEqual(len(graded['grade_breakdown']), 0)

        # Test that graders can also be used instead of lists of dictionaries
        homework_grader = graders.AssignmentFormatGrader("Homework", 12, 2)
        homework_grader2 = graders.grader_from_conf(homework_grader)

        graded = homework_grader2.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded['percent'], 0.11)
        self.assertEqual(len(graded['section_breakdown']), 12 + 1)
Ejemplo n.º 3
0
    def test_grader_from_conf(self):

        # Confs always produce a graders.WeightedSubsectionsGrader, so we test this by repeating the test
        # in test_graders.WeightedSubsectionsGrader, but generate the graders with confs.

        weighted_grader = graders.grader_from_conf([
            {
                'type': "Homework",
                'min_count': 12,
                'drop_count': 2,
                'short_label': "HW",
                'weight': 0.25,
            },
            {
                'type': "Lab",
                'min_count': 7,
                'drop_count': 3,
                'category': "Labs",
                'weight': 0.25
            },
            {
                'type': "Midterm",
                'min_count': 0,
                'drop_count': 0,
                'name': "Midterm Exam",
                'short_label': "Midterm",
                'weight': 0.5,
            },
        ])

        empty_grader = graders.grader_from_conf([])

        graded = weighted_grader.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded['percent'], 0.50812499999999994)
        self.assertEqual(len(graded['section_breakdown']), (12 + 1) + (7 + 1) + 1)
        self.assertEqual(len(graded['grade_breakdown']), 3)

        graded = empty_grader.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded['percent'], 0.0)
        self.assertEqual(len(graded['section_breakdown']), 0)
        self.assertEqual(len(graded['grade_breakdown']), 0)

        # Test that graders can also be used instead of lists of dictionaries
        homework_grader = graders.AssignmentFormatGrader("Homework", 12, 2)
        homework_grader2 = graders.grader_from_conf(homework_grader)

        graded = homework_grader2.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded['percent'], 0.11)
        self.assertEqual(len(graded['section_breakdown']), 12 + 1)
Ejemplo n.º 4
0
    def test_grade_with_string_min_count(self):
        """
        Test that the grading succeeds in case the min_count is set to a string
        """
        weighted_grader = graders.grader_from_conf([
            {
                'type': "Homework",
                'min_count': '12',
                'drop_count': 2,
                'short_label': "HW",
                'weight': 0.25,
            },
            {
                'type': "Lab",
                'min_count': '7',
                'drop_count': 3,
                'category': "Labs",
                'weight': 0.25
            },
            {
                'type': "Midterm",
                'min_count': '0',
                'drop_count': 0,
                'name': "Midterm Exam",
                'short_label': "Midterm",
                'weight': 0.5,
            },
        ])

        graded = weighted_grader.grade(self.test_gradesheet)
        assert round(graded['percent'] - 0.50812499999999994, 7) >= 0
        assert len(graded['section_breakdown']) == (((12 + 1) + (7 + 1)) + 1)
        assert len(graded['grade_breakdown']) == 3
Ejemplo n.º 5
0
    def test_grade_with_string_min_count(self):
        """
        Test that the grading succeeds in case the min_count is set to a string
        """
        weighted_grader = graders.grader_from_conf([
            {
                'type': "Homework",
                'min_count': '12',
                'drop_count': 2,
                'short_label': "HW",
                'weight': 0.25,
            },
            {
                'type': "Lab",
                'min_count': '7',
                'drop_count': 3,
                'category': "Labs",
                'weight': 0.25
            },
            {
                'type': "Midterm",
                'min_count': '0',
                'drop_count': 0,
                'name': "Midterm Exam",
                'short_label': "Midterm",
                'weight': 0.5,
            },
        ])

        graded = weighted_grader.grade(self.test_gradesheet)
        self.assertAlmostEqual(graded['percent'], 0.5106547619047619)
        self.assertEqual(len(graded['section_breakdown']), (12 + 1) + (7 + 1) + 1)
        self.assertEqual(len(graded['grade_breakdown']), 3)
Ejemplo n.º 6
0
 def grader(self):
     return grader_from_conf(self.raw_grader)
Ejemplo n.º 7
0
 def grader(self):
     return grader_from_conf(self.raw_grader)
Ejemplo n.º 8
0
 def test_grader_with_invalid_conf(self, invalid_conf,
                                   expected_error_message):
     with self.assertRaises(ValueError) as error:
         graders.grader_from_conf([invalid_conf])
     self.assertIn(expected_error_message, text_type(error.exception))
Ejemplo n.º 9
0
 def test_grader_with_invalid_conf(self, invalid_conf,
                                   expected_error_message):
     with pytest.raises(ValueError) as error:
         graders.grader_from_conf([invalid_conf])
     assert expected_error_message in text_type(error.exception)
Ejemplo n.º 10
0
 def test_grader_with_invalid_conf(self, invalid_conf, expected_error_message):
     with self.assertRaises(ValueError) as error:
         graders.grader_from_conf([invalid_conf])
     self.assertIn(expected_error_message, error.exception.message)