def test_preprocess_text_solution_cell_no_region(self, preprocessor):
        """Is a text grade cell correctly cleared when there is no solution region?"""
        cell = create_text_cell()
        cell.metadata['nbgrader'] = dict(solution=True)
        cell = preprocessor.preprocess_cell(cell, {}, 1)[0]

        assert cell.source == "YOUR ANSWER HERE"
        assert cell.metadata.nbgrader['solution']
Beispiel #2
0
    def test_preprocess_text_cell_no_region(self, preprocessor):
        """Is a text grade cell not cleared when there is no solution region?"""
        cell = create_text_cell()
        cell.metadata['nbgrader'] = dict()
        cell = preprocessor.preprocess_cell(cell, {}, 1)[0]

        assert cell.source == "this is the answer!\n"
        assert not cell.metadata.nbgrader.get('solution', False)
    def test_preprocess_text_cell_no_region(self, preprocessor):
        """Is a text grade cell correctly cleared when there is no solution region?"""
        cell = create_text_cell()
        cell.metadata['nbgrader'] = dict()
        cell = preprocessor.preprocess_cell(cell, {}, 1)[0]

        assert cell.source == "this is the answer!\n"
        assert not cell.metadata.nbgrader.get('solution', False)
Beispiel #4
0
    def test_preprocess_text_solution_cell_no_region(self, preprocessor):
        """Is a text grade cell correctly cleared when there is no solution region?"""
        cell = create_text_cell()
        cell.metadata['nbgrader'] = dict(solution=True)
        cell = preprocessor.preprocess_cell(cell, {}, 1)[0]

        assert cell.source == "YOUR ANSWER HERE"
        assert cell.metadata.nbgrader['solution']
    def test_replace_solution_region_no_end(self, preprocessor):
        """Is an error thrown when there is no end solution statement?"""
        cell = create_text_cell()
        cell.source = dedent(
            """
            something something
            ### BEGIN SOLUTION
            this is the answer!
            """
        ).strip()

        with pytest.raises(RuntimeError):
            preprocessor._replace_solution_region(cell)
Beispiel #6
0
    def test_replace_solution_region_no_end(self, preprocessor):
        """Is an error thrown when there is no end solution statement?"""
        cell = create_text_cell()
        cell.source = dedent(
            """
            something something
            ### BEGIN SOLUTION
            this is the answer!
            """
        ).strip()

        with pytest.raises(RuntimeError):
            preprocessor._replace_solution_region(cell)
 def test_replace_solution_region_text(self, preprocessor):
     """Are solution regions in text cells correctly replaced?"""
     cell = create_text_cell()
     cell.source = dedent(
         """
         something something
         ### BEGIN SOLUTION
         this is the answer!
         ### END SOLUTION
         """
     ).strip()
     replaced_solution = preprocessor._replace_solution_region(cell)
     assert replaced_solution
     assert cell.source == "something something\nYOUR ANSWER HERE"
Beispiel #8
0
    def test_preprocess_text_cell_region(self, preprocessor):
        """Is an error thrown when a solution region exists in a non-solution text cell?"""
        cell = create_text_cell()
        cell.source = dedent(
            """
            something something
            ### BEGIN SOLUTION
            this is the answer!
            ### END SOLUTION
            """
        ).strip()

        with pytest.raises(RuntimeError):
            preprocessor.preprocess_cell(cell, {}, 1)
    def test_preprocess_text_cell_region(self, preprocessor):
        """Is an error thrown when a solution region exists in a non-solution text cell?"""
        cell = create_text_cell()
        cell.source = dedent(
            """
            something something
            ### BEGIN SOLUTION
            this is the answer!
            ### END SOLUTION
            """
        ).strip()

        with pytest.raises(RuntimeError):
            preprocessor.preprocess_cell(cell, {}, 1)
Beispiel #10
0
 def test_replace_solution_region_text(self, preprocessor):
     """Are solution regions in text cells correctly replaced?"""
     cell = create_text_cell()
     cell.source = dedent(
         """
         something something
         ### BEGIN SOLUTION
         this is the answer!
         ### END SOLUTION
         """
     ).strip()
     replaced_solution = preprocessor._replace_solution_region(cell)
     assert replaced_solution
     assert cell.source == "something something\nYOUR ANSWER HERE"
    def test_preprocess_text_cell_region(self, preprocessor):
        """Is a text grade cell correctly cleared when there is a solution region?"""
        cell = create_text_cell()
        cell.source = dedent(
            """
            something something
            ### BEGIN SOLUTION
            this is the answer!
            ### END SOLUTION
            """
        ).strip()

        cell = preprocessor.preprocess_cell(cell, {}, 1)[0]
        assert cell.source == "something something\nYOUR ANSWER HERE"
        assert cell.metadata.nbgrader['solution']
Beispiel #12
0
    def test_preprocess_text_solution_cell_region(self, preprocessor):
        """Is a text grade cell correctly cleared when there is a solution region?"""
        cell = create_text_cell()
        cell.source = dedent(
            """
            something something
            ### BEGIN SOLUTION
            this is the answer!
            ### END SOLUTION
            """
        ).strip()
        cell.metadata['nbgrader'] = dict(solution=True)

        cell = preprocessor.preprocess_cell(cell, {}, 1)[0]
        assert cell.source == "something something\nYOUR ANSWER HERE"
        assert cell.metadata.nbgrader['solution']
Beispiel #13
0
    def test_print_error_markdown_cell(self, preprocessor, stream):
        cell = create_text_cell()
        preprocessor.stream = stream
        preprocessor.width = 20
        preprocessor._print_error(cell)

        expected = dedent("""
            ====================
            The following cell failed:

                this is the a...

            The error was:

                You did not p...

            """)

        assert stream.getvalue() == expected
    def test_print_error_markdown_cell(self, preprocessor, stream):
        cell = create_text_cell()
        preprocessor.stream = stream
        preprocessor.width = 20
        preprocessor._print_error(cell)

        expected = dedent(
            """
            ====================
            The following cell failed:

                this is the a...

            The error was:

                You did not p...

            """
        )

        assert stream.getvalue() == expected
 def test_text_cell_no_checksum(self, preprocessor):
     """Test that no checksum is computed for a regular text cell"""
     cell, _ = preprocessor.preprocess_cell(
         create_text_cell(), {}, 0)
     assert "nbgrader" not in cell.metadata or "checksum" not in cell.metadata.nbgrader
 def test_dont_replace_solution_region(self, preprocessor):
     """Is false returned when there is no solution region?"""
     cell = create_text_cell()
     replaced_solution = preprocessor._replace_solution_region(cell)
     assert not replaced_solution
Beispiel #17
0
 def test_text_cell_no_checksum(self, preprocessor):
     """Test that no checksum is computed for a regular text cell"""
     cell, _ = preprocessor.preprocess_cell(create_text_cell(), {}, 0)
     assert "nbgrader" not in cell.metadata or "checksum" not in cell.metadata.nbgrader
Beispiel #18
0
 def test_dont_replace_solution_region(self, preprocessor):
     """Is false returned when there is no solution region?"""
     cell = create_text_cell()
     replaced_solution = preprocessor._replace_solution_region(cell)
     assert not replaced_solution