test_example_syntax_error.py
1 from pathlib import Path 2 3 import pytest 4 from clint.config import Config 5 from clint.index import SymbolIndex 6 from clint.linter import Position, Range, lint_file 7 from clint.rules.example_syntax_error import ExampleSyntaxError 8 9 10 def test_example_syntax_error(index: SymbolIndex) -> None: 11 code = ''' 12 def bad(): 13 """ 14 .. code-block:: python 15 16 def f(): 17 18 """ 19 20 def good(): 21 """ 22 .. code-block:: python 23 24 def f(): 25 return "This is a good example" 26 """ 27 ''' 28 config = Config(select={ExampleSyntaxError.name}) 29 violations = lint_file(Path("test.py"), code, config, index) 30 assert len(violations) == 1 31 assert all(isinstance(v.rule, ExampleSyntaxError) for v in violations) 32 assert violations[0].range == Range(Position(5, 8)) 33 34 35 @pytest.mark.parametrize("suffix", [".md", ".mdx"]) 36 def test_example_syntax_error_markdown(index: SymbolIndex, suffix: str) -> None: 37 code = """ 38 ```python 39 def g(): 40 ``` 41 """ 42 config = Config(select={ExampleSyntaxError.name}) 43 violations = lint_file(Path("test").with_suffix(suffix), code, config, index) 44 assert len(violations) == 1 45 assert all(isinstance(v.rule, ExampleSyntaxError) for v in violations) 46 assert violations[0].range == Range(Position(2, 0))