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

1"""The client pytest vulture configuration."""

2

3 from configparser import ConfigParser

4 from contextlib import suppress

5 from typing import ClassVar, List

6

7 from pytest_vulture.conf.base import Configuration

8

9

10 class VultureConfiguration(Configuration):

11 """The vulture configuration (setup.py options)

12 Examples::

13 >>> from pathlib import Path

14 >>> config_file = Path("/tmp/test.ini")

15 >>> config_file.write_text("[vulture]\\nignore-decorators = @test")

16 35

17 >>> config = ConfigParser()

18 >>> config.read(Path(config_file))

19 ['/tmp/test.ini']

20 >>> package_config = VultureConfiguration(is_pyproject=False)

21 >>> package_config.read_ini(config)

22 >>> package_config.ignore_decorators

23 ['@test']

24 """

25

26 EXCLUDE_DEFAULT: ClassVar[List[str]] = [

27 "*/.tox/*",

28 "*/.git/*",

29 "*/.cache/*",

30 "*/.idea/*",

31 "*/.eggs/*",

32 ]

33 _exclude: List[str] = EXCLUDE_DEFAULT

34 CONFIG_NAME: str = "vulture"

35 CONFIG_PYPROJECT_NAME: str = "tool.vulture"

36 _ignore_names: List[str]

37 _ignore_decorators: List[str]

38 _ignore: List[str]

39 _ignore_types: List[str]

40

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

42 super().__init__(is_pyproject=is_pyproject)

43 self._ignore_names: List[str] = []

44 self._ignore_decorators: List[str] = []

45 self._ignore: List[str] = []

46 self._ignore_types: List[str] = []

47

48 @property

49 def ignore_types(self) -> List[str]:

50 return self._ignore_types

51

52 @property

53 def ignore(self) -> List[str]:

54 return self._ignore

55

56 @property

57 def ignore_decorators(self) -> List[str]:

58 return self._ignore_decorators

59

60 @property

61 def ignore_names(self) -> List[str]:

62 return self._ignore_names

63

64 @property

65 def exclude(self) -> List[str]:

66 return self._exclude

67

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

69 parameters = self._get_parameters(data)

70 if not parameters: # pragma: no cover

71 return

72

73 self._exclude = self.EXCLUDE_DEFAULT + parameters.get("exclude", [])

74 self._ignore_names = parameters.get("ignore-names", [])

75 self._ignore_decorators = parameters.get("ignore-decorators", [])

76 self._ignore = parameters.get("ignore", [])

77 self._ignore_types = parameters.get("ignore-types", [])

78

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

80 """Read the ini file."""

81 with suppress(KeyError):

82 self._exclude = self.EXCLUDE_DEFAULT + self._to_list(config[self.CONFIG_NAME]["exclude"])

83

84 self.__read_ignore(config)

85

86 def __read_ignore(self, config: ConfigParser) -> None:

87 with suppress(KeyError):

88 self._ignore_names = self._to_list(config[self.CONFIG_NAME]["ignore-names"])

89 with suppress(KeyError):

90 self._ignore_decorators = self._to_list(config[self.CONFIG_NAME]["ignore-decorators"])

91

92 with suppress(KeyError):

93 self._ignore = self._to_list(config[self.CONFIG_NAME]["ignore"])

94

95 with suppress(KeyError):

96 self._ignore_types = self._to_list(config[self.CONFIG_NAME]["ignore-types"])