Skip to content

Commit

Permalink
get sphinx tests working - fixture parametisation needs more work.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacemanPaul committed Jul 23, 2024
1 parent 5be7175 commit 0278a54
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions tests/test_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def sphinx_directive(directive):
return mapping[directive]



# noinspection PyShadowingNames
@pytest.mark.parametrize(
"reason, version, remove_version, expected",
Expand All @@ -52,7 +51,7 @@ def sphinx_directive(directive):
),
),
(
None,
'',
'1.2.0',
None,
textwrap.dedent(
Expand All @@ -74,11 +73,18 @@ def foo(x, y):

# is decorated with:
decorator_factory = getattr(deprecat.sphinx, directive)
decorator = decorator_factory(reason=reason, version=version)
if directive in ("versionadded", "versionchanged") and remove_version is not None:
return

if directive in ("versionadded", "versionchanged"):
decorator = decorator_factory(reason=reason, version=version)
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=None)
else:
decorator = decorator_factory(reason=reason, version=version, remove_version=remove_version)
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=remove_version)
foo = decorator(foo)

# The function must contain this Sphinx docstring:
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=remove_version)

current = textwrap.dedent(foo.__doc__)
assert current.endswith(expected)
Expand Down Expand Up @@ -116,16 +122,16 @@ def foo(x, y):
textwrap.dedent(
"""\
.. {directive}:: {version}
{reason}
{reason}
Warning: This deprecated feature will be removed in version {remove_version}
Warning: This deprecated feature will be removed in version {remove_version}
"""
),
),
(
None,
"",
'1.2.0',
None,
"",
textwrap.dedent(
"""\
.. {directive}:: {version}
Expand All @@ -136,6 +142,8 @@ def foo(x, y):
ids=["reason&version", "version"],
)
def test_cls_has_sphinx_docstring(docstring, directive, sphinx_directive, reason, version, remove_version, expected):
if directive in ("versionadded", "versionchanged") and remove_version is not None:
return
# The class:
class Foo(object):
pass
Expand All @@ -145,9 +153,16 @@ class Foo(object):

# is decorated with:
decorator_factory = getattr(deprecat.sphinx, directive)
decorator = decorator_factory(reason=reason, version=version)

if directive in ("versionadded", "versionchanged"):
decorator = decorator_factory(reason=reason, version=version, line_length=85)
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=None, line_length=85)
else:
decorator = decorator_factory(reason=reason, version=version, remove_version=remove_version, line_length=85)
expected = expected.format(directive=sphinx_directive, version=version, reason=reason, remove_version=remove_version, line_length=85)
Foo = decorator(Foo)


# The class must contain this Sphinx docstring:
expected = expected.format(directive=sphinx_directive, version=version, remove_version=remove_version, reason=reason)

Expand Down

0 comments on commit 0278a54

Please sign in to comment.