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

1"""The package configuration."""

2

3 from configparser import ConfigParser

4 from contextlib import suppress

5 from pathlib import Path

6

7 from pytest_vulture.conf.base import Configuration

8

9

10 class PackageConfiguration(Configuration):

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

12 Examples::

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

14 >>> config_file.write_text("[package]\\nsetup_path = setup.py\\ncheck_entry_points = true")

15 57

16 >>> config = ConfigParser()

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

18 ['/tmp/test.ini']

19 >>> package_config = PackageConfiguration(is_pyproject=False)

20 >>> package_config.read_ini(config)

21 >>> package_config.setup_path

22 PosixPath('setup.py')

23 >>> package_config.check_entry_points

24 True

25 """

26

27 _setup_path: Path = Path("setup.py")

28 _source_path: Path = Path()

29 _check_entry_points: bool = True

30 _NAME = "package"

31

32 @property

33 def setup_path(self) -> Path:

34 return self._setup_path

35

36 @setup_path.setter

37 def setup_path(self, setup_path: Path) -> None:

38 self._setup_path = setup_path

39

40 @property

41 def source_path(self) -> Path:

42 return self._source_path

43

44 @property

45 def check_entry_points(self) -> bool:

46 return self._check_entry_points

47

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

49 parameters = self._get_parameters(data)

50 if not parameters: # pragma: no cover

51 return

52

53 str_source = parameters.get("source-path")

54 self._source_path = Path(str_source) if str_source else Path()

55 self._check_entry_points = data.get("check-entry-points", True)

56

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

58 """Read the ini file."""

59 if self._is_pyproject: # pragma: no cover

60 return

61 with suppress(KeyError):

62 self._setup_path = Path(config[self._NAME]["setup_path"])

63 with suppress(KeyError):

64 self._source_path = Path(config[self._NAME]["source_path"])

65 with suppress(KeyError):

66 self._check_entry_points = self._to_bool(config[self._NAME]["check_entry_points"])