2022-02-19 21:05:56 -06:00
|
|
|
"""Test the coverage builder."""
|
2008-09-13 04:45:59 -05:00
|
|
|
|
|
|
|
import pickle
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
import pytest
|
2008-09-13 04:45:59 -05:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('coverage')
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_build(app, status, warning):
|
2024-01-16 20:38:46 -06:00
|
|
|
app.build(force_all=True)
|
2008-09-13 04:45:59 -05:00
|
|
|
|
2022-04-26 21:04:19 -05:00
|
|
|
py_undoc = (app.outdir / 'python.txt').read_text(encoding='utf8')
|
2008-09-13 04:45:59 -05:00
|
|
|
assert py_undoc.startswith('Undocumented Python objects\n'
|
|
|
|
'===========================\n')
|
2017-12-16 19:35:51 -06:00
|
|
|
assert 'autodoc_target\n--------------\n' in py_undoc
|
2008-09-13 04:45:59 -05:00
|
|
|
assert ' * Class -- missing methods:\n' in py_undoc
|
2017-12-16 19:35:51 -06:00
|
|
|
assert ' * raises\n' in py_undoc
|
2008-09-13 04:45:59 -05:00
|
|
|
assert ' * function\n' not in py_undoc # these two are documented
|
|
|
|
assert ' * Class\n' not in py_undoc # in autodoc.txt
|
|
|
|
|
2023-03-23 16:58:38 -05:00
|
|
|
assert " * mod -- No module named 'mod'" in py_undoc # in the "failed import" section
|
2011-01-04 15:50:13 -06:00
|
|
|
|
2020-05-31 11:38:21 -05:00
|
|
|
assert "undocumented py" not in status.getvalue()
|
|
|
|
|
2022-04-26 21:04:19 -05:00
|
|
|
c_undoc = (app.outdir / 'c.txt').read_text(encoding='utf8')
|
2008-09-13 04:45:59 -05:00
|
|
|
assert c_undoc.startswith('Undocumented C API elements\n'
|
|
|
|
'===========================\n')
|
|
|
|
assert 'api.h' in c_undoc
|
|
|
|
assert ' * Py_SphinxTest' in c_undoc
|
|
|
|
|
2023-07-27 20:33:42 -05:00
|
|
|
undoc_py, undoc_c, py_undocumented, py_documented = pickle.loads((app.outdir / 'undoc.pickle').read_bytes())
|
2008-09-13 04:45:59 -05:00
|
|
|
assert len(undoc_c) == 1
|
|
|
|
# the key is the full path to the header file, which isn't testable
|
2019-03-17 14:49:36 -05:00
|
|
|
assert list(undoc_c.values())[0] == {('function', 'Py_SphinxTest')}
|
2008-09-13 04:45:59 -05:00
|
|
|
|
2017-12-16 19:35:51 -06:00
|
|
|
assert 'autodoc_target' in undoc_py
|
|
|
|
assert 'funcs' in undoc_py['autodoc_target']
|
|
|
|
assert 'raises' in undoc_py['autodoc_target']['funcs']
|
|
|
|
assert 'classes' in undoc_py['autodoc_target']
|
|
|
|
assert 'Class' in undoc_py['autodoc_target']['classes']
|
|
|
|
assert 'undocmeth' in undoc_py['autodoc_target']['classes']['Class']
|
2019-05-14 07:48:52 -05:00
|
|
|
|
2020-05-31 11:38:21 -05:00
|
|
|
assert "undocumented c" not in status.getvalue()
|
|
|
|
|
2019-05-14 07:48:52 -05:00
|
|
|
|
|
|
|
@pytest.mark.sphinx('coverage', testroot='ext-coverage')
|
|
|
|
def test_coverage_ignore_pyobjects(app, status, warning):
|
2024-01-16 20:38:46 -06:00
|
|
|
app.build(force_all=True)
|
2022-04-26 21:04:19 -05:00
|
|
|
actual = (app.outdir / 'python.txt').read_text(encoding='utf8')
|
2023-07-27 20:33:42 -05:00
|
|
|
expected = '''\
|
|
|
|
Undocumented Python objects
|
2019-05-14 07:48:52 -05:00
|
|
|
===========================
|
2023-07-27 20:33:42 -05:00
|
|
|
|
|
|
|
Statistics
|
|
|
|
----------
|
|
|
|
|
|
|
|
+----------------------+----------+--------------+
|
|
|
|
| Module | Coverage | Undocumented |
|
|
|
|
+======================+==========+==============+
|
|
|
|
| coverage_not_ignored | 0.00% | 2 |
|
|
|
|
+----------------------+----------+--------------+
|
|
|
|
| TOTAL | 0.00% | 2 |
|
|
|
|
+----------------------+----------+--------------+
|
|
|
|
|
2019-05-14 07:48:52 -05:00
|
|
|
coverage_not_ignored
|
|
|
|
--------------------
|
2023-07-27 20:33:42 -05:00
|
|
|
|
2019-05-14 07:48:52 -05:00
|
|
|
Classes:
|
|
|
|
* Documented -- missing methods:
|
|
|
|
|
|
|
|
- not_ignored1
|
|
|
|
- not_ignored2
|
|
|
|
* NotIgnored
|
|
|
|
|
|
|
|
'''
|
|
|
|
assert actual == expected
|
2020-05-31 11:38:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('coverage', confoverrides={'coverage_show_missing_items': True})
|
|
|
|
def test_show_missing_items(app, status, warning):
|
2024-01-16 20:38:46 -06:00
|
|
|
app.build(force_all=True)
|
2020-05-31 11:38:21 -05:00
|
|
|
|
|
|
|
assert "undocumented" in status.getvalue()
|
|
|
|
|
|
|
|
assert "py function raises" in status.getvalue()
|
|
|
|
assert "py class Base" in status.getvalue()
|
|
|
|
assert "py method Class.roger" in status.getvalue()
|
|
|
|
|
|
|
|
assert "c api Py_SphinxTest [ function]" in status.getvalue()
|
2020-06-05 02:26:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('coverage', confoverrides={'coverage_show_missing_items': True})
|
|
|
|
def test_show_missing_items_quiet(app, status, warning):
|
|
|
|
app.quiet = True
|
2024-01-16 20:38:46 -06:00
|
|
|
app.build(force_all=True)
|
2020-06-05 02:26:53 -05:00
|
|
|
|
|
|
|
assert "undocumented python function: autodoc_target :: raises" in warning.getvalue()
|
|
|
|
assert "undocumented python class: autodoc_target :: Base" in warning.getvalue()
|
|
|
|
assert "undocumented python method: autodoc_target :: Class :: roger" in warning.getvalue()
|
|
|
|
|
|
|
|
assert "undocumented c api: Py_SphinxTest [function]" in warning.getvalue()
|