/ dev / clint / tests / rules / test_missing_notebook_h1_header.py
test_missing_notebook_h1_header.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 import MissingNotebookH1Header
 8  
 9  
10  def test_missing_notebook_h1_header(index: SymbolIndex) -> None:
11      notebook = {
12          "cells": [
13              {
14                  "cell_type": "markdown",
15                  "source": ["## Some other header"],
16              },
17              {
18                  "cell_type": "code",
19                  "source": ["print('hello')"],
20              },
21          ]
22      }
23      code = json.dumps(notebook)
24      config = Config(select={MissingNotebookH1Header.name})
25      results = lint_file(Path("test.ipynb"), code, config, index)
26      assert len(results) == 1
27      assert isinstance(results[0].rule, MissingNotebookH1Header)
28  
29  
30  def test_missing_notebook_h1_header_positive(index: SymbolIndex) -> None:
31      notebook = {
32          "cells": [
33              {
34                  "cell_type": "markdown",
35                  "source": ["# This is a title"],
36              },
37              {
38                  "cell_type": "code",
39                  "source": ["print('hello')"],
40              },
41          ]
42      }
43      code = json.dumps(notebook)
44      config = Config(select={MissingNotebookH1Header.name})
45      results = lint_file(Path("test_positive.ipynb"), code, config, index)
46      assert len(results) == 0