예제 #1
0
    def test_modify_cell_with_submissions(self, preprocessor, resources):
        nb = new_notebook()
        nb.cells.append(
            create_grade_and_solution_cell("hello", "markdown", "foo", 2))
        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        notebook = gb.find_notebook("test", "ps0")
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        solution_cell = gb.find_solution_cell("foo", "test", "ps0")
        source_cell = gb.find_source_cell("foo", "test", "ps0")
        assert grade_cell.max_score == 2
        assert source_cell.source == "hello"

        gb.add_student("hacker123")
        submission = gb.add_submission("ps0", "hacker123").notebooks[0]
        assert len(notebook.submissions) == 1

        nb.cells[-1] = create_grade_and_solution_cell("goodbye", "markdown",
                                                      "foo", 1)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb.db.refresh(notebook)
        gb.db.refresh(submission)
        gb.db.refresh(grade_cell)
        gb.db.refresh(solution_cell)
        gb.db.refresh(source_cell)
        assert len(notebook.submissions) == 1
        assert grade_cell.max_score == 1
        assert source_cell.source == "goodbye"
예제 #2
0
    def test_modify_cell_with_submissions(self, preprocessor, resources):
        nb = new_notebook()
        nb.cells.append(create_grade_and_solution_cell("hello", "markdown", "foo", 2))
        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        notebook = gb.find_notebook("test", "ps0")
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        solution_cell = gb.find_solution_cell("foo", "test", "ps0")
        source_cell = gb.find_source_cell("foo", "test", "ps0")
        assert grade_cell.max_score == 2
        assert source_cell.source == "hello"

        gb.add_student("hacker123")
        submission = gb.add_submission("ps0", "hacker123").notebooks[0]
        assert len(notebook.submissions) == 1

        nb.cells[-1] = create_grade_and_solution_cell("goodbye", "markdown", "foo", 1)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb.db.refresh(notebook)
        gb.db.refresh(submission)
        gb.db.refresh(grade_cell)
        gb.db.refresh(solution_cell)
        gb.db.refresh(source_cell)
        assert len(notebook.submissions) == 1
        assert grade_cell.max_score == 1
        assert source_cell.source == "goodbye"
예제 #3
0
def test_determine_grade_markdown_grade_and_solution():
    cell = create_grade_and_solution_cell('test', "markdown", "foo", 10)
    cell.metadata.nbgrader['checksum'] = utils.compute_checksum(cell)
    assert utils.determine_grade(cell) == (0, 10)

    cell = create_grade_and_solution_cell('test', "markdown", "foo", 10)
    cell.source = 'test!'
    assert utils.determine_grade(cell) == (None, 10)
예제 #4
0
def test_determine_grade_markdown_grade_and_solution():
    cell = create_grade_and_solution_cell('test', "markdown", "foo", 10)
    cell.metadata.nbgrader['checksum'] = utils.compute_checksum(cell)
    assert utils.determine_grade(cell) == (0, 10)

    cell = create_grade_and_solution_cell('test', "markdown", "foo", 10)
    cell.source = 'test!'
    assert utils.determine_grade(cell) == (None, 10)
예제 #5
0
    def test_grade_existing_manual_grade(self, preprocessors, gradebook,
                                         resources):
        """Is a failing code cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        cell.source = "hello!"
        preprocessors[1].preprocess(nb, resources)

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

        grade_cell.manual_score = 1
        grade_cell.needs_manual_grade = False
        gradebook.db.commit()

        preprocessors[1].preprocess(nb, resources)

        grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
        assert grade_cell.score == 1
        assert grade_cell.max_score == 1
        assert grade_cell.auto_score == None
        assert grade_cell.manual_score == 1
        assert grade_cell.needs_manual_grade
예제 #6
0
    def test_grade_existing_manual_grade(self, preprocessors, gradebook, resources):
        """Is a failing code cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        cell.source = "hello!"
        preprocessors[1].preprocess(nb, resources)

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

        grade_cell.manual_score = 1
        grade_cell.needs_manual_grade = False
        gradebook.db.commit()

        preprocessors[1].preprocess(nb, resources)

        grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
        assert grade_cell.score == 1
        assert grade_cell.max_score == 1
        assert grade_cell.auto_score == None
        assert grade_cell.manual_score == 1
        assert grade_cell.needs_manual_grade
예제 #7
0
def test_determine_grade_code_grade_and_solution():
    cell = create_grade_and_solution_cell('test', "code", "foo", 10)
    cell.metadata.nbgrader['checksum'] = utils.compute_checksum(cell)
    cell.outputs = []
    assert utils.determine_grade(cell) == (0, 10)

    cell.outputs = [new_output('error', ename="NotImplementedError", evalue="", traceback=["error"])]
    cell.source = 'test!'
    assert utils.determine_grade(cell) == (None, 10)
예제 #8
0
def test_determine_grade_code_grade_and_solution():
    cell = create_grade_and_solution_cell('test', "code", "foo", 10)
    cell.metadata.nbgrader['checksum'] = utils.compute_checksum(cell)
    cell.outputs = []
    assert utils.determine_grade(cell) == (0, 10)

    cell.outputs = [new_output('error', ename="NotImplementedError", evalue="", traceback=["error"])]
    cell.source = 'test!'
    assert utils.determine_grade(cell) == (None, 10)
예제 #9
0
    def test_save_new_cell_with_submissions(self, preprocessor, resources):
        cell1 = create_grade_and_solution_cell("hello", "markdown", "foo", 2)
        cell2 = create_grade_and_solution_cell("hello", "markdown", "bar", 1)

        nb = new_notebook()
        nb.cells.append(cell1)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        notebook = gb.find_notebook("test", "ps0")
        assert len(notebook.grade_cells) == 1
        assert len(notebook.solution_cells) == 1
        assert len(notebook.source_cells) == 1

        gb.add_student("hacker123")
        gb.add_submission("ps0", "hacker123")
        nb.cells.append(cell2)

        with pytest.raises(RuntimeError):
            nb, resources = preprocessor.preprocess(nb, resources)
예제 #10
0
    def test_save_new_cell_with_submissions(self, preprocessor, resources):
        cell1 = create_grade_and_solution_cell("hello", "markdown", "foo", 2)
        cell2 = create_grade_and_solution_cell("hello", "markdown", "bar", 1)

        nb = new_notebook()
        nb.cells.append(cell1)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        notebook = gb.find_notebook("test", "ps0")
        assert len(notebook.grade_cells) == 1
        assert len(notebook.solution_cells) == 1
        assert len(notebook.source_cells) == 1

        gb.add_student("hacker123")
        gb.add_submission("ps0", "hacker123")
        nb.cells.append(cell2)

        with pytest.raises(RuntimeError):
            nb, resources = preprocessor.preprocess(nb, resources)
예제 #11
0
    def test_comment_unchanged_markdown(self, preprocessors, gradebook, resources):
        """Is an unchanged markdown cell given the correct comment?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)

        comment = gradebook.find_comment(0, "test", "ps0", "bar")
        assert comment.comment == "No response."
예제 #12
0
    def test_dont_overwrite_grade_and_solution_source(self, preprocessors, resources):
        """Is the source not overwritten for grade+solution cells?"""
        cell = create_grade_and_solution_cell("hello", "code", "foo", 1)
        cell.metadata.nbgrader["checksum"] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        nb, resources = preprocessors[0].preprocess(nb, resources)

        cell.source = "hello!"
        nb, resources = preprocessors[1].preprocess(nb, resources)

        assert cell.source == "hello!"
예제 #13
0
    def test_save_new_cell(self, preprocessor, resources):
        cell1 = create_grade_and_solution_cell("hello", "markdown", "foo", 2)
        cell2 = create_grade_and_solution_cell("hello", "markdown", "bar", 1)

        nb = new_notebook()
        nb.cells.append(cell1)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        notebook = gb.find_notebook("test", "ps0")
        assert len(notebook.grade_cells) == 1
        assert len(notebook.solution_cells) == 1
        assert len(notebook.source_cells) == 1

        nb.cells.append(cell2)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb.db.refresh(notebook)
        assert len(notebook.grade_cells) == 2
        assert len(notebook.solution_cells) == 2
        assert len(notebook.source_cells) == 2
예제 #14
0
    def test_save_new_cell(self, preprocessor, resources):
        cell1 = create_grade_and_solution_cell("hello", "markdown", "foo", 2)
        cell2 = create_grade_and_solution_cell("hello", "markdown", "bar", 1)

        nb = new_notebook()
        nb.cells.append(cell1)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        notebook = gb.find_notebook("test", "ps0")
        assert len(notebook.grade_cells) == 1
        assert len(notebook.solution_cells) == 1
        assert len(notebook.source_cells) == 1

        nb.cells.append(cell2)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb.db.refresh(notebook)
        assert len(notebook.grade_cells) == 2
        assert len(notebook.solution_cells) == 2
        assert len(notebook.source_cells) == 2
예제 #15
0
    def test_comment_unchanged_markdown(self, preprocessors, gradebook,
                                        resources):
        """Is an unchanged markdown cell given the correct comment?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)

        comment = gradebook.find_comment("foo", "test", "ps0", "bar")
        assert comment.auto_comment == "No response."
예제 #16
0
    def test_comment_changed_markdown(self, preprocessors, gradebook, resources):
        """Is a changed markdown cell given the correct comment?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        cell.source = "hello!"
        preprocessors[1].preprocess(nb, resources)

        comment = gradebook.find_comment("foo", "test", "ps0", "bar")
        assert comment.auto_comment is None
예제 #17
0
    def test_modify_cell(self, preprocessor, resources):
        nb = new_notebook()
        nb.cells.append(create_grade_and_solution_cell("hello", "markdown", "foo", 2))
        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        notebook = gb.find_notebook("test", "ps0")
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        solution_cell = gb.find_solution_cell("foo", "test", "ps0")
        source_cell = gb.find_source_cell("foo", "test", "ps0")
        assert grade_cell.max_score == 2
        assert source_cell.source == "hello"

        nb.cells[-1] = create_grade_and_solution_cell("goodbye", "markdown", "foo", 1)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb.db.refresh(notebook)
        gb.db.refresh(grade_cell)
        gb.db.refresh(solution_cell)
        gb.db.refresh(source_cell)
        assert grade_cell.max_score == 1
        assert source_cell.source == "goodbye"
예제 #18
0
    def test_dont_overwrite_grade_and_solution_source(self, preprocessors,
                                                      resources):
        """Is the source not overwritten for grade+solution cells?"""
        cell = create_grade_and_solution_cell("hello", "code", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        nb, resources = preprocessors[0].preprocess(nb, resources)

        cell.source = "hello!"
        nb, resources = preprocessors[1].preprocess(nb, resources)

        assert cell.source == "hello!"
예제 #19
0
    def test_save_unchanged_markdown(self, preprocessors, gradebook, resources):
        """Is an unchanged markdown cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)
        preprocessors[2].preprocess(nb, resources)

        assert cell.metadata.nbgrader['score'] == 0
        assert cell.metadata.nbgrader['points'] == 1
        assert cell.metadata.nbgrader['comment'] == "No response."
예제 #20
0
    def test_save_unchanged_markdown(self, preprocessors, gradebook, resources):
        """Is an unchanged markdown cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)
        preprocessors[2].preprocess(nb, resources)

        assert cell.metadata.nbgrader['score'] == 0
        assert cell.metadata.nbgrader['points'] == 1
        assert cell.metadata.nbgrader['comment'] == "No response."
예제 #21
0
    def test_grade_unchanged_markdown(self, preprocessors, gradebook, resources):
        """Is an unchanged markdown cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)

        grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
        assert grade_cell.score == 0
        assert grade_cell.max_score == 1
        assert grade_cell.auto_score == 0
        assert grade_cell.manual_score == None
        assert not grade_cell.needs_manual_grade
예제 #22
0
    def test_modify_cell(self, preprocessor, resources):
        nb = new_notebook()
        nb.cells.append(
            create_grade_and_solution_cell("hello", "markdown", "foo", 2))
        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        notebook = gb.find_notebook("test", "ps0")
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        solution_cell = gb.find_solution_cell("foo", "test", "ps0")
        source_cell = gb.find_source_cell("foo", "test", "ps0")
        assert grade_cell.max_score == 2
        assert source_cell.source == "hello"

        nb.cells[-1] = create_grade_and_solution_cell("goodbye", "markdown",
                                                      "foo", 1)
        nb, resources = preprocessor.preprocess(nb, resources)

        gb.db.refresh(notebook)
        gb.db.refresh(grade_cell)
        gb.db.refresh(solution_cell)
        gb.db.refresh(source_cell)
        assert grade_cell.max_score == 1
        assert source_cell.source == "goodbye"
예제 #23
0
    def test_save_changed_markdown(self, preprocessors, gradebook, resources):
        """Is a changed markdown cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader["checksum"] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        cell.source = "hello!"
        preprocessors[1].preprocess(nb, resources)
        preprocessors[2].preprocess(nb, resources)

        assert cell.metadata.nbgrader["score"] == 0
        assert cell.metadata.nbgrader["points"] == 1

        assert cell.metadata.nbgrader["comment"] is None
예제 #24
0
    def test_save_changed_markdown(self, preprocessors, gradebook, resources):
        """Is a changed markdown cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        cell.source = "hello!"
        preprocessors[1].preprocess(nb, resources)
        preprocessors[2].preprocess(nb, resources)

        assert cell.metadata.nbgrader['score'] == 0
        assert cell.metadata.nbgrader['points'] == 1

        comment = gradebook.find_comment(0, "test", "ps0", "bar")
        assert cell.metadata.nbgrader['comment'] == comment.to_dict()
        assert cell.metadata.nbgrader['comment']['comment'] == None
예제 #25
0
    def test_grade_changed_markdown(self, preprocessors, gradebook, resources):
        """Is a changed markdown cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        cell.source = "hello!"
        preprocessors[1].preprocess(nb, resources)

        grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
        assert grade_cell.score == 0
        assert grade_cell.max_score == 1
        assert grade_cell.auto_score == None
        assert grade_cell.manual_score == None
        assert grade_cell.needs_manual_grade
예제 #26
0
    def test_save_code_grade_and_solution_cell(self, preprocessor, resources):
        cell = create_grade_and_solution_cell("hello", "code", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        assert grade_cell.max_score == 1
        assert grade_cell.source == "hello"
        assert grade_cell.checksum == cell.metadata.nbgrader["checksum"]
        assert grade_cell.cell_type == "code"

        solution_cell = gb.find_solution_cell(0, "test", "ps0")
        assert solution_cell.source == "hello"
        assert solution_cell.checksum == cell.metadata.nbgrader["checksum"]
        assert solution_cell.cell_type == "code"
예제 #27
0
    def test_grade_existing_auto_comment(self, preprocessors, gradebook, resources):
        """Is a failing code cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)

        comment = gradebook.find_comment("foo", "test", "ps0", "bar")
        assert comment.auto_comment == "No response."

        nb.cells[-1].source = 'goodbye'
        preprocessors[1].preprocess(nb, resources)

        gradebook.db.refresh(comment)
        assert comment.auto_comment is None
예제 #28
0
    def test_grade_existing_auto_comment(self, preprocessors, gradebook,
                                         resources):
        """Is a failing code cell correctly graded?"""
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)
        preprocessors[0].preprocess(nb, resources)
        gradebook.add_submission("ps0", "bar")
        preprocessors[1].preprocess(nb, resources)

        comment = gradebook.find_comment("foo", "test", "ps0", "bar")
        assert comment.auto_comment == "No response."

        nb.cells[-1].source = 'goodbye'
        preprocessors[1].preprocess(nb, resources)

        gradebook.db.refresh(comment)
        assert comment.auto_comment is None
예제 #29
0
    def test_save_code_grade_and_solution_cell(self, preprocessor, resources):
        cell = create_grade_and_solution_cell("hello", "code", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        assert grade_cell.max_score == 1
        assert grade_cell.cell_type == "code"

        gb.find_solution_cell("foo", "test", "ps0")

        source_cell = gb.find_source_cell("foo", "test", "ps0")
        assert source_cell.source == "hello"
        assert source_cell.checksum == cell.metadata.nbgrader["checksum"]
        assert source_cell.cell_type == "code"
        assert not source_cell.locked
예제 #30
0
    def test_save_markdown_grade_and_solution_cell(self, preprocessor, resources):
        cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        cell.metadata.nbgrader['checksum'] = compute_checksum(cell)
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = preprocessor.preprocess(nb, resources)

        gb = preprocessor.gradebook
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        assert grade_cell.max_score == 1
        assert grade_cell.cell_type == "markdown"

        gb.find_solution_cell("foo", "test", "ps0")

        source_cell = gb.find_source_cell("foo", "test", "ps0")
        assert source_cell.source == "hello"
        assert source_cell.checksum == cell.metadata.nbgrader["checksum"]
        assert source_cell.cell_type == "markdown"
        assert not source_cell.locked