Coverage for tests/test_docs/test_docstrings.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-04-28 15:17 +0000

1import re 

2import inspect 

3from typing import Any 

4 

5import pytest 

6 

7from prisma.actions import PostActions 

8 

9METHODS = [member for name, member in inspect.getmembers(PostActions) if not name.startswith('_')] 

10 

11 

12@pytest.mark.parametrize('method', METHODS) 

13def test_headings(method: Any) -> None: 

14 """Ensure the Example, Parameters, Raises and Returns headings are present""" 

15 doc = inspect.getdoc(method) 

16 print(doc) 

17 assert doc is not None 

18 assert 'Raises\n------' in doc 

19 assert 'Example\n-------' in doc 

20 assert 'Returns\n-------' in doc 

21 assert 'Parameters\n----------' in doc 

22 assert 'prisma.errors.PrismaError' in doc 

23 

24 

25@pytest.mark.parametrize('method', METHODS) 

26def test_completeness(method: Any) -> None: 

27 """Ensure there aren't any incomplete docstrings""" 

28 doc = inspect.getdoc(method) 

29 print(doc) 

30 assert doc is not None 

31 

32 for name, param in inspect.signature(method).parameters.items(): 

33 if name == 'self': 

34 continue 

35 

36 if param.kind == param.VAR_POSITIONAL: 

37 qualified = f'\\*{name}' 

38 else: 

39 qualified = name 

40 

41 match = re.search( 

42 r'Parameters\n----------((.|\n)*)^{0}$((.|\n)*)Returns'.format(qualified), 

43 doc, 

44 re.MULTILINE, 

45 ) 

46 assert match is not None, f'Missing documentation for parameter: {qualified}' 

47 

48 assert 'TODO' not in doc 

49 assert method.__name__ in doc