Skip to content

Commit

Permalink
tests: Add tests for new coverage functionality
Browse files Browse the repository at this point in the history
We migrate the code we're measuring coverage for to a package so we can
validate the new module coverage functionality.

Signed-off-by: Stephen Finucane <stephen@that.guru>
  • Loading branch information
stephenfin committed Sep 5, 2023
1 parent af89c17 commit 4f1b283
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
5 changes: 4 additions & 1 deletion tests/roots/test-ext-coverage/conf.py
Expand Up @@ -5,8 +5,11 @@

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage']

coverage_modules = [
'grog',
]
coverage_ignore_pyobjects = [
r'^coverage_ignored(\..*)?$',
r'^grog\.coverage_ignored(\..*)?$',
r'\.Ignored$',
r'\.Documented\.ignored\d$',
]
Empty file.
8 changes: 8 additions & 0 deletions tests/roots/test-ext-coverage/grog/coverage_missing.py
@@ -0,0 +1,8 @@
"""This module is intentionally not documented."""

class Missing:
"""An undocumented class."""

def missing_a(self):
"""An undocumented method."""
pass
4 changes: 2 additions & 2 deletions tests/roots/test-ext-coverage/index.rst
@@ -1,6 +1,6 @@
.. automodule:: coverage_ignored
.. automodule:: grog.coverage_ignored
:members:


.. automodule:: coverage_not_ignored
.. automodule:: grog.coverage_not_ignored
:members:
40 changes: 27 additions & 13 deletions tests/test_ext_coverage.py
Expand Up @@ -10,8 +10,10 @@ def test_build(app, status, warning):
app.builder.build_all()

py_undoc = (app.outdir / 'python.txt').read_text(encoding='utf8')
assert py_undoc.startswith('Undocumented Python objects\n'
'===========================\n')
assert py_undoc.startswith(
'Undocumented Python objects\n'
'===========================\n',
)
assert 'autodoc_target\n--------------\n' in py_undoc
assert ' * Class -- missing methods:\n' in py_undoc
assert ' * raises\n' in py_undoc
Expand All @@ -23,8 +25,10 @@ def test_build(app, status, warning):
assert "undocumented py" not in status.getvalue()

c_undoc = (app.outdir / 'c.txt').read_text(encoding='utf8')
assert c_undoc.startswith('Undocumented C API elements\n'
'===========================\n')
assert c_undoc.startswith(
'Undocumented C API elements\n'
'===========================\n',
)
assert 'api.h' in c_undoc
assert ' * Py_SphinxTest' in c_undoc

Expand Down Expand Up @@ -54,16 +58,26 @@ def test_coverage_ignore_pyobjects(app, status, warning):
Statistics
----------
+----------------------+----------+--------------+
| Module | Coverage | Undocumented |
+======================+==========+==============+
| coverage_not_ignored | 0.00% | 2 |
+----------------------+----------+--------------+
| TOTAL | 0.00% | 2 |
+----------------------+----------+--------------+
+---------------------------+----------+--------------+
| Module | Coverage | Undocumented |
+===========================+==========+==============+
| grog | 100.00% | 0 |
+---------------------------+----------+--------------+
| grog.coverage_missing | 100.00% | 0 |
+---------------------------+----------+--------------+
| grog.coverage_not_ignored | 0.00% | 2 |
+---------------------------+----------+--------------+
| TOTAL | 0.00% | 2 |
+---------------------------+----------+--------------+
grog.coverage_missing
---------------------
coverage_not_ignored
--------------------
Classes:
* Missing
grog.coverage_not_ignored
-------------------------
Classes:
* Documented -- missing methods:
Expand Down

0 comments on commit 4f1b283

Please sign in to comment.