| 1 |
"""Unit tests of the fragment discovery logic.""" |
| 2 |
|
| 3 |
|
| 4 |
from pathlib import Path |
| 5 |
from typing import Set |
| 6 |
|
| 7 |
import pytest |
| 8 |
|
| 9 |
from sphinxcontrib.towncrier._fragment_discovery import _find_config_file |
| 10 |
|
| 11 |
|
| 12 |
PYPROJECT_TOML_FILENAME = 'pyproject.toml' |
| 13 |
TOWNCRIER_TOML_FILENAME = 'towncrier.toml' |
| 14 |
|
| 15 |
|
| 16 |
@pytest.mark.parametrize( |
| 17 |
('config_file_names_on_disk', 'expected_config_file_name'), |
| 18 |
( |
| 19 |
pytest.param( |
| 20 |
set(), |
| 21 |
PYPROJECT_TOML_FILENAME, |
| 22 |
id='pyproject.toml-when-no-configs', |
| 23 |
), |
| 24 |
pytest.param( |
| 25 |
{PYPROJECT_TOML_FILENAME}, |
| 26 |
'pyproject.toml', |
| 27 |
id='pyproject.toml-only', |
| 28 |
), |
| 29 |
pytest.param( |
| 30 |
{TOWNCRIER_TOML_FILENAME}, |
| 31 |
TOWNCRIER_TOML_FILENAME, |
| 32 |
id='towncrier.toml-only', |
| 33 |
), |
| 34 |
pytest.param( |
| 35 |
{PYPROJECT_TOML_FILENAME, TOWNCRIER_TOML_FILENAME}, |
| 36 |
TOWNCRIER_TOML_FILENAME, |
| 37 |
id='towncrier.toml-over-pyproject.toml', |
| 38 |
), |
| 39 |
), |
| 40 |
) |
| 41 |
def test_find_config_file( |
| 42 |
config_file_names_on_disk: Set[str], |
| 43 |
expected_config_file_name: str, |
| 44 |
tmp_path: Path, |
| 45 |
) -> None: |
| 46 |
"""Verify that the correct Towncrier config is always preferred.""" |
| 47 |
for config_file_name_on_disk in config_file_names_on_disk: |
| 48 |
tmp_path.joinpath(config_file_name_on_disk).write_text( |
| 49 |
'', encoding='utf-8', |
| 50 |
) |
| 51 |
|
| 52 |
assert _find_config_file(tmp_path).name == expected_config_file_name |