-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 Add draft version fallback helper tests
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""The Sphinx extension interface module tests.""" | ||
|
||
import pytest | ||
|
||
from sphinx.config import Config as SphinxConfig | ||
|
||
from sphinxcontrib.towncrier.ext import _get_draft_version_fallback | ||
|
||
|
||
release_sentinel = object() | ||
version_sentinel = object() | ||
|
||
|
||
@pytest.fixture | ||
def sphinx_config() -> SphinxConfig: | ||
"""Initialize a Sphinx config stub for testing.""" | ||
return SphinxConfig( | ||
overrides={'release': release_sentinel, 'version': version_sentinel}, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
('autoversion_mode', 'expected_version'), | ||
( | ||
('sphinx-release', release_sentinel), | ||
('sphinx-version', version_sentinel), | ||
('draft', '[UNRELEASED DRAFT]'), | ||
), | ||
) | ||
def test__get_draft_version_fallback_known_strategy( # noqa: WPS116, WPS118 | ||
autoversion_mode: str, | ||
expected_version: object, | ||
sphinx_config: SphinxConfig, | ||
) -> None: | ||
"""Check that valid strategies source correct values.""" | ||
computed_version = _get_draft_version_fallback.__wrapped__( | ||
autoversion_mode, | ||
sphinx_config, | ||
) | ||
assert computed_version == expected_version | ||
|
||
|
||
@pytest.mark.parametrize('autoversion_mode', ('blah', '', 'v1.0')) | ||
def test__get_draft_version_fallback_invalid_strategy( # noqa: WPS116, WPS118 | ||
autoversion_mode: str, | ||
sphinx_config: SphinxConfig, | ||
) -> None: | ||
"""Ensure invalid strategy yields an exception.""" | ||
expected_error_msg = ( | ||
'^Expected "strategy" to be one of ' | ||
r"{'[\w,\s'-]+'} " | ||
fr'but got {autoversion_mode !r}$' | ||
) | ||
with pytest.raises(ValueError, match=expected_error_msg): | ||
_get_draft_version_fallback.__wrapped__( | ||
autoversion_mode, | ||
sphinx_config, | ||
) |