Coverage for src/pytest_vulture/conf/base.py: 0.00%
23 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-22 10:23 +0100
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-22 10:23 +0100
1"""A pytest vulture configuration."""
3import re
4from abc import (
5 ABC,
6 abstractmethod,
7)
8from configparser import ConfigParser
9from typing import ClassVar, List
12class Configuration(ABC):
13 """The abstract class of a pytest vulture configuration."""
15 _TRUE_VALUES: ClassVar[List[str]] = ["true", "True", "1", "yes"]
16 _is_pyproject: bool
18 def __init__(self, *, is_pyproject: bool) -> None:
19 self._is_pyproject = is_pyproject
21 @abstractmethod
22 def read_ini(self, config: ConfigParser) -> None:
23 """Read the ini file."""
25 @abstractmethod
26 def read_tomli(self, data: dict) -> None:
27 """Read a toml file."""
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()]
39 @classmethod
40 def _to_bool(cls, config_string: str) -> bool:
41 return config_string in cls._TRUE_VALUES
43 def _get_parameters(self, data: dict) -> dict:
44 answer = data.get("tool", {}).get("vulture", {})
45 return answer if isinstance(answer, dict) else {}