Coverage for e2xgrader/preprocessors/filtertests.py: 100%
13 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 NbGraderPreprocessor
6from nbgrader.utils import is_grade, is_solution
7from traitlets import Bool, Unicode
10class FilterTests(NbGraderPreprocessor):
11 hide_cells = Bool(
12 False, help="Hide test cells in the feedback generated for students."
13 ).tag(config=True)
15 test_case_stub = Unicode(
16 "# This test case is hidden #",
17 help="The message the test case source is replaced with",
18 ).tag(config=True)
20 def preprocess_cell(
21 self, cell: NotebookNode, resources: ResourcesDict, cell_index: int
22 ) -> Tuple[NotebookNode, ResourcesDict]:
23 if self.hide_cells and is_grade(cell) and not is_solution(cell):
24 cell.source = self.test_case_stub
25 return cell, resources