test_empty_notebook_cell.py
1 import json 2 from pathlib import Path 3 4 from clint.config import Config 5 from clint.index import SymbolIndex 6 from clint.linter import lint_file 7 from clint.rules.empty_notebook_cell import EmptyNotebookCell 8 9 10 def test_empty_notebook_cell(index: SymbolIndex) -> None: 11 notebook_content = { 12 "cells": [ 13 { 14 "cell_type": "code", 15 "source": [], # Empty cell 16 "metadata": {}, 17 "execution_count": None, 18 "outputs": [], 19 }, 20 { 21 "cell_type": "code", 22 "source": ["x = 5"], 23 "metadata": {}, 24 "execution_count": None, 25 "outputs": [], 26 }, 27 { 28 "cell_type": "code", 29 "source": [], # Another empty cell 30 "metadata": {}, 31 "execution_count": None, 32 "outputs": [], 33 }, 34 ], 35 "metadata": { 36 "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"} 37 }, 38 "nbformat": 4, 39 "nbformat_minor": 4, 40 } 41 code = json.dumps(notebook_content) 42 config = Config(select={EmptyNotebookCell.name}) 43 violations = lint_file(Path("test_notebook.ipynb"), code, config, index) 44 assert len(violations) == 2 45 assert all(isinstance(v.rule, EmptyNotebookCell) for v in violations) 46 assert violations[0].cell == 1 47 assert violations[1].cell == 3