Debian Codegraph @

tests/_towncrier_test.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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
12
13 def test_towncrier_config_section_missing(
14 monkeypatch: pytest.MonkeyPatch,
15 tmp_path: Path,
16 ) -> None:
17 """Test config file without Towncrier section raises an error."""
18 tmp_working_dir_path = tmp_path / 'working-directory'
19 tmp_working_dir_path.mkdir()
20 empty_config_file = Path('arbitrary-config.toml')
21 (tmp_working_dir_path / empty_config_file).touch()
22 monkeypatch.chdir(tmp_working_dir_path)
23
24 expected_error_msg = r'^No \[tool\.towncrier\] section\.$'
25
26 with pytest.raises(TowncrierConfigError, match=expected_error_msg):
27 get_towncrier_config(tmp_path, empty_config_file)
28
29
30 @pytest.mark.parametrize(
31 'config_file_name',
32 (
33 None,
34 Path('pyproject.toml'),
35 Path('towncrier.toml'),
36 ),
37 )
38 def test_towncrier_config_file_missing(
39 config_file_name: Union[Path, None],
40 monkeypatch: pytest.MonkeyPatch,
41 tmp_path: Path,
42 ) -> None:
43 """Test missing Towncrier config file raises an error."""
44 tmp_working_dir_path = tmp_path / 'working-directory'
45 tmp_working_dir_path.mkdir()
46 monkeypatch.chdir(tmp_working_dir_path)
47
48 expected_error_msg = (
49 fr"^\[Errno 2\] No such file or directory: '{config_file_name}'$"
50 )
51
52 with pytest.raises(FileNotFoundError, match=expected_error_msg):
53 get_towncrier_config(tmp_path, config_file_name)