| 1 |
"""Data transformation tests.""" |
| 2 |
import pytest |
| 3 |
|
| 4 |
from sphinxcontrib.towncrier._data_transformers import ( |
| 5 |
escape_project_version_rst_substitution, |
| 6 |
) |
| 7 |
|
| 8 |
|
| 9 |
@pytest.mark.parametrize( |
| 10 |
('test_input', 'escaped_input'), |
| 11 |
( |
| 12 |
(r'\ |release|', r'\ |release|'), |
| 13 |
('|release|', r'\ |release|'), |
| 14 |
('|release', '|release'), |
| 15 |
('v|release|', 'v|release|'), |
| 16 |
), |
| 17 |
ids=( |
| 18 |
'substitution already escaped', |
| 19 |
'correct substitution at the beginning', |
| 20 |
'unclosed substitution at the beginning', |
| 21 |
'correct substitution in the middle', |
| 22 |
), |
| 23 |
) |
| 24 |
def test_escape_version(test_input: str, escaped_input: str) -> None: |
| 25 |
"""Test that the version is escaped before RST substitutions. |
| 26 |
|
| 27 |
RST substitution as the first item should be escaped. Otherwise, |
| 28 |
the input is expected to remain unchanged. |
| 29 |
""" |
| 30 |
assert escape_project_version_rst_substitution(test_input) == escaped_input |