Coverage for src/pytest_vulture/conf/base.py: 0.00%

1"""A pytest vulture configuration."""

2

3 import re

4 from abc import (

5 ABC,

6 abstractmethod,

7)

8 from configparser import ConfigParser

9 from typing import ClassVar, List

10

11

12 class Configuration(ABC):

13 """The abstract class of a pytest vulture configuration."""

14

15 _TRUE_VALUES: ClassVar[List[str]] = ["true", "True", "1", "yes"]

16 _is_pyproject: bool

17

18 def __init__(self, *, is_pyproject: bool) -> None:

19 self._is_pyproject = is_pyproject

20

21 @abstractmethod

22 def read_ini(self, config: ConfigParser) -> None:

23 """Read the ini file."""

24

25 @abstractmethod

26 def read_tomli(self, data: dict) -> None:

27 """Read a toml file."""

28

29 @staticmethod

30 def _to_list(config_string: str) -> List[str]:

31 """Convert a string config element to a list

32 Examples::

33 >>> Configuration._to_list(" */test/*\\n */test_2/*")

34 ['*/test/*', '*/test_2/*']

35 """

36 list_elements = re.split("[,\n]", config_string)

37 return [element.lstrip().rstrip() for element in list_elements if element.lstrip().rstrip()]

38

39 @classmethod

40 def _to_bool(cls, config_string: str) -> bool:

41 return config_string in cls._TRUE_VALUES

42

43 def _get_parameters(self, data: dict) -> dict:

44 answer = data.get("tool", {}).get("vulture", {})

45 return answer if isinstance(answer, dict) else {}