Coverage for e2xgrader/preprocessors/clearsolutions.py: 100%
14 statements
« prev ^ index » next coverage.py v7.4.2, created at 2024-03-14 13:22 +0100
« prev ^ index » next coverage.py v7.4.2, created at 2024-03-14 13:22 +0100
1from typing import Tuple
3from nbconvert.exporters.exporter import ResourcesDict
4from nbformat.notebooknode import NotebookNode
5from nbgrader.preprocessors import ClearSolutions as NbgraderClearSolutions
7from ..utils.extra_cells import get_options, is_diagram, is_extra_cell
10class ClearSolutions(NbgraderClearSolutions):
11 def preprocess_cell(
12 self, cell: NotebookNode, resources: ResourcesDict, cell_index: int
13 ) -> Tuple[NotebookNode, ResourcesDict]:
14 if is_extra_cell(cell):
15 if is_diagram(cell):
16 # Check whether we want to remove the diagram
17 options = get_options(cell)
18 if options.get("replace_diagram", True):
19 del cell.attachments["diagram.png"]
21 return cell, resources
22 else:
23 return super().preprocess_cell(cell, resources, cell_index)