Skip to content

Commit

Permalink
🧪 Add draft version fallback helper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Dec 27, 2024
1 parent 4e6f87e commit 7f57120
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/ext_test.py
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,
)

0 comments on commit 7f57120

Please sign in to comment.