Skip to content

Commit 3d87303

Browse files
committed
tests: Add tests for new coverage functionality
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 <[email protected]>
1 parent af89c17 commit 3d87303

File tree

7 files changed

+41
-16
lines changed

7 files changed

+41
-16
lines changed

tests/roots/test-ext-coverage/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

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

8+
coverage_modules = [
9+
'mypackage',
10+
]
811
coverage_ignore_pyobjects = [
9-
r'^coverage_ignored(\..*)?$',
12+
r'^mypackage\.coverage_ignored(\..*)?$',
1013
r'\.Ignored$',
1114
r'\.Documented\.ignored\d$',
1215
]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
.. automodule:: coverage_ignored
1+
.. automodule:: mypackage.coverage_ignored
22
:members:
33

44

5-
.. automodule:: coverage_not_ignored
5+
.. automodule:: mypackage.coverage_not_ignored
66
:members:

tests/roots/test-ext-coverage/mypackage/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""This module is intentionally not documented."""
2+
3+
class Missing:
4+
"""An undocumented class."""
5+
6+
def missing_a(self):
7+
"""An undocumented method."""
8+
pass

tests/test_ext_coverage.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ def test_build(app, status, warning):
1010
app.builder.build_all()
1111

1212
py_undoc = (app.outdir / 'python.txt').read_text(encoding='utf8')
13-
assert py_undoc.startswith('Undocumented Python objects\n'
14-
'===========================\n')
13+
assert py_undoc.startswith(
14+
'Undocumented Python objects\n'
15+
'===========================\n'
16+
)
1517
assert 'autodoc_target\n--------------\n' in py_undoc
1618
assert ' * Class -- missing methods:\n' in py_undoc
1719
assert ' * raises\n' in py_undoc
@@ -23,8 +25,10 @@ def test_build(app, status, warning):
2325
assert "undocumented py" not in status.getvalue()
2426

2527
c_undoc = (app.outdir / 'c.txt').read_text(encoding='utf8')
26-
assert c_undoc.startswith('Undocumented C API elements\n'
27-
'===========================\n')
28+
assert c_undoc.startswith(
29+
'Undocumented C API elements\n'
30+
'===========================\n'
31+
)
2832
assert 'api.h' in c_undoc
2933
assert ' * Py_SphinxTest' in c_undoc
3034

@@ -54,16 +58,26 @@ def test_coverage_ignore_pyobjects(app, status, warning):
5458
Statistics
5559
----------
5660
57-
+----------------------+----------+--------------+
58-
| Module | Coverage | Undocumented |
59-
+======================+==========+==============+
60-
| coverage_not_ignored | 0.00% | 2 |
61-
+----------------------+----------+--------------+
62-
| TOTAL | 0.00% | 2 |
63-
+----------------------+----------+--------------+
61+
+--------------------------------+----------+--------------+
62+
| Module | Coverage | Undocumented |
63+
+================================+==========+==============+
64+
| mypackage | 100.00% | 0 |
65+
+--------------------------------+----------+--------------+
66+
| mypackage.coverage_missing | 100.00% | 0 |
67+
+--------------------------------+----------+--------------+
68+
| mypackage.coverage_not_ignored | 0.00% | 2 |
69+
+--------------------------------+----------+--------------+
70+
| TOTAL | 0.00% | 2 |
71+
+--------------------------------+----------+--------------+
72+
73+
mypackage.coverage_missing
74+
--------------------------
6475
65-
coverage_not_ignored
66-
--------------------
76+
Classes:
77+
* Missing
78+
79+
mypackage.coverage_not_ignored
80+
------------------------------
6781
6882
Classes:
6983
* Documented -- missing methods:

0 commit comments

Comments
 (0)