Skip to content

Commit

Permalink
implement test for exception documenter
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilipp committed Oct 21, 2024
1 parent ec89d70 commit 4e51644
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test-root/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ class InnerClass(object):
small_data = 'Should be skipped'


class TestException(Exception):
"""Exception test for autosummary"""

def __init__(self):
#: This is an exception attribute
self.exception_instance_attribute = 1

def test_exception_method(self):
"""Test if the method is included"""
pass


class InheritedTestClass(TestClass):
"""Class test for inherited attributes"""

Expand Down
4 changes: 4 additions & 0 deletions tests/test-root/test_autoexceptionsumm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Autoexceptionsumm of Dummy Exception
====================================

.. autoexceptionsumm:: dummy.TestException
4 changes: 4 additions & 0 deletions tests/test-root/test_exception.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dummy Exception Doc
===================

.. autoexception:: dummy.TestException
24 changes: 24 additions & 0 deletions tests/test_autodocsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ def test_class(self, app):
'DummySection'
)

def test_exception(self, app):
app.build()
html = get_html(app, 'test_exception.html')

if sphinx_version[:2] > [3, 1]:
assert in_autosummary("exception_instance_attribute", html)
elif sphinx_version[:2] < [3, 1]:
assert in_autosummary("TestException.exception_instance_attribute", html)

assert in_autosummary("test_exception_method", html)

@pytest.mark.skipif(
sphinx_version[:2] < [3, 1], reason="Only available for sphinx>=3"
)
Expand Down Expand Up @@ -412,6 +423,19 @@ def test_autoclasssumm(self, app):
assert in_autosummary("test_method", html)
assert in_autosummary("test_attr", html)

def test_autoexceptionsumm(self, app):
"""Test building the autosummary of a class."""
app.build()

html = get_html(app, 'test_autoexceptionsumm.html')

# the class docstring must not be in the html
assert "Class exception for autosummary" not in html

# test if the methods and attributes are there in a table
assert in_autosummary("test_exception_method", html)
assert in_autosummary("exception_instance_attribute", html)

def test_autoclasssumm_no_titles(self, app):
"""Test building the autosummary of a class."""
app.build()
Expand Down

0 comments on commit 4e51644

Please sign in to comment.