Debian Codegraph @

tests/_towncrier_test.py

raw ◀ ▶
1 Debian patch touch this file
1 """Towncrier config reader tests."""
2
3
4 from pathlib import Path
5 from typing import Union
6
7 import pytest
8
9 from sphinxcontrib.towncrier._towncrier import get_towncrier_config
10 from ._compat import TowncrierConfigError
•11 from importlib.metadata import version
12 from packaging.version import Version
13
•14 @pytest.mark.skipif(Version(version('towncrier')).release[0] > 24,
15 reason="this test is broken with towncrier v. 25.8.0")
16
17 def test_towncrier_config_section_missing(
18 monkeypatch: pytest.MonkeyPatch,
19 tmp_path: Path,
20 ) -> None:
21 """Test config file without Towncrier section raises an error."""
22 tmp_working_dir_path = tmp_path / 'working-directory'
23 tmp_working_dir_path.mkdir()
24 empty_config_file = Path('arbitrary-config.toml')
25 (tmp_working_dir_path / empty_config_file).touch()
26 monkeypatch.chdir(tmp_working_dir_path)
27
28 expected_error_msg = r'^No \[tool\.towncrier\] section\.$'
29
30 with pytest.raises(TowncrierConfigError, match=expected_error_msg):
31 get_towncrier_config(tmp_path, empty_config_file)
32
33
34 @pytest.mark.parametrize(
35 'config_file_name',
36 (
37 None,
38 Path('pyproject.toml'),
39 Path('towncrier.toml'),
40 ),
41 )
42 def test_towncrier_config_file_missing(
43 config_file_name: Union[Path, None],
44 monkeypatch: pytest.MonkeyPatch,
45 tmp_path: Path,
46 ) -> None:
47 """Test missing Towncrier config file raises an error."""
48 tmp_working_dir_path = tmp_path / 'working-directory'
49 tmp_working_dir_path.mkdir()
50 monkeypatch.chdir(tmp_working_dir_path)
51
52 expected_error_msg = (
53 fr"^\[Errno 2\] No such file or directory: '{config_file_name}'$"
54 )
55
56 with pytest.raises(FileNotFoundError, match=expected_error_msg):
57 get_towncrier_config(tmp_path, config_file_name)