def test_preprocess_code_cell_no_region(self, preprocessor): """Is a code cell not cleared when there is no solution region?""" cell = create_code_cell() cell.source = """print("the answer!")""" cell.metadata['nbgrader'] = dict() cell = preprocessor.preprocess_cell(cell, {}, 1)[0] assert cell.source == """print("the answer!")""" assert not cell.metadata.nbgrader.get('solution', False)
def test_is_solution(): cell = create_code_cell() assert not utils.is_solution(cell) cell.metadata['nbgrader'] = {} assert not utils.is_solution(cell) cell.metadata['nbgrader']['solution'] = False assert not utils.is_solution(cell) cell.metadata['nbgrader']['solution'] = True assert utils.is_solution(cell)
def test_cell_unchanged(self, preprocessor): """Do normal cells remain unchanged?""" preprocessor.lock_solution_cells = False preprocessor.lock_grade_cells = False preprocessor.lock_all_cells = False cell = create_code_cell() cell.metadata['nbgrader'] = {} assert self.deletable(cell) new_cell = preprocessor.preprocess_cell(cell, {}, 0)[0] assert self.deletable(new_cell)
def test_cell_undeletable(self, preprocessor): """Do normal cells become undeletable?""" preprocessor.lock_solution_cells = False preprocessor.lock_grade_cells = False preprocessor.lock_all_cells = True cell = create_code_cell() cell.metadata['nbgrader'] = {} assert self.deletable(cell) new_cell = preprocessor.preprocess_cell(cell, {}, 0)[0] assert not self.deletable(new_cell)
def test_cell_unchanged(self, preprocessor): """Do normal cells remain unchanged?""" preprocessor.lock_solution_cells = False preprocessor.lock_grade_cells = False preprocessor.lock_all_cells = False preprocessor.lock_readonly_cells = False cell = create_code_cell() cell.metadata['nbgrader'] = {} assert self.deletable(cell) new_cell = preprocessor.preprocess_cell(cell, {}, 0)[0] assert self.deletable(new_cell)
def test_grade_cell_undeletable(self, preprocessor): """Do grade cells become undeletable?""" preprocessor.lock_solution_cells = False preprocessor.lock_grade_cells = True preprocessor.lock_all_cells = False preprocessor.lock_readonly_cells = False cell = create_code_cell() cell.metadata['nbgrader'] = {} cell.metadata['nbgrader']['grade'] = True assert self.deletable(cell) new_cell = preprocessor.preprocess_cell(cell, {}, 0)[0] assert not self.deletable(new_cell)
def test_replace_solution_region_code(self, preprocessor): """Are solution regions in code cells correctly replaced?""" cell = create_code_cell() replaced_solution = preprocessor._replace_solution_region(cell) assert replaced_solution assert cell.source == dedent( """ print("something") # YOUR CODE HERE raise NotImplementedError() """ ).strip()
def test_preprocess_code_cell_student(self, preprocessor): """Is the student version of a code cell correctly preprocessed?""" cell = create_code_cell() cell = preprocessor.preprocess_cell(cell, {}, 1)[0] assert cell.source == dedent( """ print("something") # YOUR CODE HERE raise NotImplementedError() """ ).strip()
def test_preprocess_code_cell_solution_region(self, preprocessor): """Is a code cell correctly cleared when there is a solution region?""" cell = create_code_cell() cell = preprocessor.preprocess_cell(cell, {}, 1)[0] assert cell.source == dedent( """ print("something") # YOUR CODE HERE raise NotImplementedError() """ ).strip() assert cell.metadata.nbgrader['solution']
def test_preprocess_code_solution_cell_solution_region(self, preprocessor): """Is a code solution cell correctly cleared when there is a solution region?""" cell = create_code_cell() cell.metadata['nbgrader'] = dict(solution=True) cell = preprocessor.preprocess_cell(cell, {}, 1)[0] assert cell.source == dedent( """ print("something") # YOUR CODE HERE raise NotImplementedError() """ ).strip() assert cell.metadata.nbgrader['solution']
def test_preprocess_code_solution_cell_no_region(self, preprocessor): """Is a code solution cell correctly cleared when there is no solution region?""" cell = create_code_cell() cell.source = """print("the answer!")""" cell.metadata['nbgrader'] = dict(solution=True) cell = preprocessor.preprocess_cell(cell, {}, 1)[0] assert cell.source == dedent( """ # YOUR CODE HERE raise NotImplementedError() """ ).strip() assert cell.metadata.nbgrader['solution']
def test_print_changed(self, preprocessor, stream): cell = create_code_cell() preprocessor.stream = stream preprocessor.width = 20 preprocessor._print_changed(cell) expected = dedent(""" ==================== The following cell has changed: print("someth... ### BEGIN SOL... print("hello"... ### END SOLUT... """) assert stream.getvalue() == expected
def test_is_locked(): cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=True, grade=False, locked=False) assert not utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=True, grade=True, locked=False) assert not utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=True, grade=False, locked=True) assert not utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=True, grade=True, locked=True) assert not utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=False, grade=True, locked=False) assert utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=False, grade=True, locked=True) assert utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=False, grade=False, locked=True) assert utils.is_locked(cell) assert utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=False, grade=False, locked=False) assert not utils.is_locked(cell)
def test_print_changed(self, preprocessor, stream): cell = create_code_cell() preprocessor.stream = stream preprocessor.width = 20 preprocessor._print_changed(cell) expected = dedent( """ ==================== The following cell has changed: print("someth... ### BEGIN SOL... print("hello"... ### END SOLUT... """ ) assert stream.getvalue() == expected
def test_print_error_code_cell_error(self, preprocessor, stream): cell = self._add_error(create_code_cell()) preprocessor.stream = stream preprocessor.width = 20 preprocessor._print_error(cell) expected = dedent(""" ==================== The following cell failed: print("someth... ### BEGIN SOL... print("hello"... ### END SOLUT... The error was: oh noes, an e... """) assert stream.getvalue() == expected
def test_print_error_code_cell_error(self, preprocessor, stream): cell = self._add_error(create_code_cell()) preprocessor.stream = stream preprocessor.width = 20 preprocessor._print_error(cell) expected = dedent( """ ==================== The following cell failed: print("someth... ### BEGIN SOL... print("hello"... ### END SOLUT... The error was: oh noes, an e... """ ) assert stream.getvalue() == expected
def test_preprocess_code_cell_solution_region(self, preprocessor): """Is an error thrown when there is a solution region but it's not a solution cell?""" cell = create_code_cell() with pytest.raises(RuntimeError): preprocessor.preprocess_cell(cell, {}, 1)
def test_code_cell_no_checksum(self, preprocessor): """Test that no checksum is computed for a regular code cell""" cell, _ = preprocessor.preprocess_cell(create_code_cell(), {}, 0) assert "nbgrader" not in cell.metadata or "checksum" not in cell.metadata.nbgrader
def test_code_cell_no_checksum(self, preprocessor): """Test that no checksum is computed for a regular code cell""" cell, _ = preprocessor.preprocess_cell( create_code_cell(), {}, 0) assert "nbgrader" not in cell.metadata or "checksum" not in cell.metadata.nbgrader