Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def preprocess_cell(self,
cell: NotebookNode,
resources: ResourcesDict,
cell_index: int
) -> Tuple[NotebookNode, ResourcesDict]:
# remove hidden test regions
removed_test = self._remove_hidden_test_region(cell)
# determine whether the cell is a grade cell
is_grade = utils.is_grade(cell)
# check that it is marked as a grade cell if we remove a test
# region -- if it's not, then this is a problem, because the cell needs
# to be given an id
if not is_grade and removed_test:
if self.enforce_metadata:
raise RuntimeError(
"Hidden test region detected in a non-grade cell; "
"please make sure all solution regions are within "
"'Autograder tests' cells."
)
return cell, resources
def preprocess_cell(self,
cell: NotebookNode,
resources: ResourcesDict,
cell_index: int
) -> Tuple[NotebookNode, ResourcesDict]:
if (self.lock_solution_cells or self.lock_grade_cells) and utils.is_solution(cell) and utils.is_grade(cell):
cell.metadata['deletable'] = False
elif self.lock_solution_cells and utils.is_solution(cell):
cell.metadata['deletable'] = False
elif self.lock_grade_cells and utils.is_grade(cell):
cell.metadata['deletable'] = False
cell.metadata['editable'] = False
elif self.lock_readonly_cells and utils.is_locked(cell):
cell.metadata['deletable'] = False
cell.metadata['editable'] = False
elif self.lock_all_cells:
cell.metadata['deletable'] = False
cell.metadata['editable'] = False
return cell, resources
def preprocess_cell(self,
cell: NotebookNode,
resources: ResourcesDict, cell_index: int,
) -> Tuple[NotebookNode, ResourcesDict]:
# if it's a solution cell, then add a comment
if utils.is_solution(cell):
self._get_comment(cell, resources)
# if it's a grade cell, the add a grade
if utils.is_grade(cell):
self._get_score(cell, resources)
# if it's a task cell, then add a comment and a score
if utils.is_task(cell):
self._get_comment(cell, resources)
self._get_score(cell, resources)
return cell, resources
def _get_failed_cells(self, nb: NotebookNode) -> typing.List[NotebookNode]:
failed = []
for cell in nb.cells:
if not (self.validate_all or utils.is_grade(cell) or utils.is_locked(cell)):
continue
# if it's a grade cell, the check the grade
if utils.is_grade(cell):
score, max_score = utils.determine_grade(cell, self.log)
# it's a markdown cell, so we can't do anything
if score is None:
pass
elif score < max_score:
failed.append(cell)
elif self.validate_all and cell.cell_type == 'code':
for output in cell.outputs:
if output.output_type == 'error':
failed.append(cell)
break
def _extract_error(self, cell: NotebookNode) -> str:
errors = []
# possibilities:
# 1. the cell returned an error in cell.outputs
# 2. grade cell returned score < max_points (i.e. partial credit)
# 3. the student did not provide a response
if cell.cell_type == "code":
for output in cell.outputs:
if output.output_type == "error":
errors.append("\n".join(output.traceback))
if len(errors) == 0:
if utils.is_grade(cell):
score, max_score = utils.determine_grade(cell, self.log)
if (score < max_score):
errors.append("Partial credit; passed some but not all of the tests")
else:
errors.append("You did not provide a response.")
else:
errors.append("You did not provide a response.")
return "\n".join(errors)