Ejemplo n.º 1
0
def test_average_notebook_score(assignment: Gradebook) -> None:
    assert assignment.average_notebook_score('p1', 'foo') == 0
    assert assignment.average_notebook_code_score('p1', 'foo') == 0
    assert assignment.average_notebook_written_score('p1', 'foo') == 0

    assignment.add_student('hacker123')
    assignment.add_student('bitdiddle')
    assignment.add_submission('foo', 'hacker123')
    assignment.add_submission('foo', 'bitdiddle')

    assert assignment.average_notebook_score('p1', 'foo') == 0.0
    assert assignment.average_notebook_code_score('p1', 'foo') == 0.0
    assert assignment.average_notebook_written_score('p1', 'foo') == 0.0

    g1 = assignment.find_grade("test1", "p1", "foo", "hacker123")
    g2 = assignment.find_grade("test2", "p1", "foo", "hacker123")
    g3 = assignment.find_grade("test1", "p1", "foo", "bitdiddle")
    g4 = assignment.find_grade("test2", "p1", "foo", "bitdiddle")

    g1.manual_score = 0.5
    g2.manual_score = 2
    g3.manual_score = 1
    g4.manual_score = 1
    assignment.db.commit()

    assert assignment.average_notebook_score('p1', 'foo') == 2.25
    assert assignment.average_notebook_code_score('p1', 'foo') == 0.75
    assert assignment.average_notebook_written_score('p1', 'foo') == 1.5
Ejemplo n.º 2
0
    def test_add_extra_notebooks_with_submissions(self, db):
        """Is an error thrown when new notebooks are added and there are existing submissions?"""
        gb = Gradebook(db)
        assignment = gb.add_assignment("ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")
        run_command('nbgrader assign ps1 --db="{}"'.format(db))

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1

        gb.add_student("hacker123")
        gb.add_submission("ps1", "hacker123")

        self._copy_file("files/test.ipynb", "source/ps1/test2.ipynb")
        run_command('nbgrader assign ps1 --db="{}" --force'.format(db), retcode=1)
Ejemplo n.º 3
0
    def test_remove_extra_notebooks_with_submissions(self, db):
        """Is an error thrown when notebooks are removed and there are existing submissions?"""
        gb = Gradebook(db)
        assignment = gb.add_assignment("ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")
        self._copy_file("files/test.ipynb", "source/ps1/test2.ipynb")
        run_command(["nbgrader", "assign", "ps1", "--db", db])

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 2

        gb.add_student("hacker123")
        gb.add_submission("ps1", "hacker123")

        os.remove("source/ps1/test2.ipynb")
        run_command(["nbgrader", "assign", "ps1", "--db", db, "--force"], retcode=1)
    def test_add_extra_notebooks_with_submissions(self, db):
        """Is an error thrown when new notebooks are added and there are existing submissions?"""
        gb = Gradebook(db)
        assignment = gb.add_assignment("ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")
        run_command(["nbgrader", "assign", "ps1", "--db", db])

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1

        gb.add_student("hacker123")
        gb.add_submission("ps1", "hacker123")

        self._copy_file("files/test.ipynb", "source/ps1/test2.ipynb")
        run_command(["nbgrader", "assign", "ps1", "--db", db, "--force"],
                    retcode=1)
Ejemplo n.º 5
0
def assignmentWithSubmissionNoMarks(assignmentWithTask: Gradebook) -> Gradebook:
    assignmentWithTask.add_student('hacker123')
    assignmentWithTask.add_student('bitdiddle')
    assignmentWithTask.add_student('louisreasoner')
    s1 = assignmentWithTask.add_submission('foo', 'hacker123')
    s2 = assignmentWithTask.add_submission('foo', 'bitdiddle')
    s1.flagged = True
    s2.flagged = False
    assignmentWithTask.db.commit()
    return assignmentWithTask
Ejemplo n.º 6
0
    def test_same_notebooks_with_submissions(self, db):
        """Is it ok to run nbgrader assign with the same notebooks and existing submissions?"""
        gb = Gradebook(db)
        assignment = gb.add_assignment("ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")
        run_command('nbgrader assign ps1 --db="{}"'.format(db))

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1
        notebook = assignment.notebooks[0]

        gb.add_student("hacker123")
        submission = gb.add_submission("ps1", "hacker123")
        submission_notebook = submission.notebooks[0]

        run_command('nbgrader assign ps1 --db="{}" --force'.format(db))

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1
        gb.db.refresh(notebook)
        gb.db.refresh(submission)
        gb.db.refresh(submission_notebook)
    def test_same_notebooks_with_submissions(self, db):
        """Is it ok to run nbgrader assign with the same notebooks and existing submissions?"""
        gb = Gradebook(db)
        assignment = gb.add_assignment("ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")
        run_command(["nbgrader", "assign", "ps1", "--db", db])

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1
        notebook = assignment.notebooks[0]

        gb.add_student("hacker123")
        submission = gb.add_submission("ps1", "hacker123")
        submission_notebook = submission.notebooks[0]

        run_command(["nbgrader", "assign", "ps1", "--db", db, "--force"])

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1
        gb.db.refresh(notebook)
        gb.db.refresh(submission)
        gb.db.refresh(submission_notebook)
Ejemplo n.º 8
0
class TestSaveAutoGrades(TestBase):

    def setup(self):
        super(TestSaveAutoGrades, self).setup()
        db_url = self._init_db()
        self.gb = Gradebook(db_url)
        self.gb.add_assignment("ps0")
        self.gb.add_student("bar")

        self.preprocessor1 = SaveCells()
        self.preprocessor2 = SaveAutoGrades()
        self.resources = {
            "nbgrader": {
                "db_url": db_url,
                "assignment": "ps0",
                "notebook": "test",
                "student": "bar"
            }
        }

    def test_grade_correct_code(self):
        """Is a passing code cell correctly graded?"""
        cell = self._create_grade_cell("hello", "code", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 1)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, 1)
        assert_equal(grade_cell.manual_score, None)
        assert not grade_cell.needs_manual_grade

    def test_grade_incorrect_code(self):
        """Is a failing code cell correctly graded?"""
        cell = self._create_grade_cell("hello", "code", "foo", 1)
        cell.outputs = [new_output('error', ename="NotImplementedError", evalue="", traceback=["error"])]
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 0)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, 0)
        assert_equal(grade_cell.manual_score, None)
        assert not grade_cell.needs_manual_grade

    def test_grade_unchanged_markdown(self):
        """Is an unchanged markdown cell correctly graded?"""
        cell = self._create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 0)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, 0)
        assert_equal(grade_cell.manual_score, None)
        assert not grade_cell.needs_manual_grade

    def test_grade_changed_markdown(self):
        """Is a changed markdown cell correctly graded?"""
        cell = self._create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        cell.source = "hello!"
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 0)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, None)
        assert_equal(grade_cell.manual_score, None)
        assert grade_cell.needs_manual_grade

    def test_comment_unchanged_code(self):
        """Is an unchanged code cell given the correct comment?"""
        cell = self._create_solution_cell("hello", "code")
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        comment = self.gb.find_comment(0, "test", "ps0", "bar")
        assert_equal(comment.comment, "No response.")

    def test_comment_changed_code(self):
        """Is a changed code cell given the correct comment?"""
        cell = self._create_solution_cell("hello", "code")
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        cell.source = "hello!"
        self.preprocessor2.preprocess(nb, self.resources)

        comment = self.gb.find_comment(0, "test", "ps0", "bar")
        assert_equal(comment.comment, None)

    def test_comment_unchanged_markdown(self):
        """Is an unchanged markdown cell given the correct comment?"""
        cell = self._create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        comment = self.gb.find_comment(0, "test", "ps0", "bar")
        assert_equal(comment.comment, "No response.")

    def test_comment_changed_markdown(self):
        """Is a changed markdown cell given the correct comment?"""
        cell = self._create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        cell.source = "hello!"
        self.preprocessor2.preprocess(nb, self.resources)

        comment = self.gb.find_comment(0, "test", "ps0", "bar")
        assert_equal(comment.comment, None)