mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add test for coverage builder and fix an AttributeError in it.
This commit is contained in:
@@ -73,10 +73,9 @@ class CoverageBuilder(Builder):
|
||||
self.build_py_coverage()
|
||||
self.write_py_coverage()
|
||||
|
||||
if self.c_sourcefiles:
|
||||
self.c_undoc = {}
|
||||
self.build_c_coverage()
|
||||
self.write_c_coverage()
|
||||
self.c_undoc = {}
|
||||
self.build_c_coverage()
|
||||
self.write_c_coverage()
|
||||
|
||||
def build_c_coverage(self):
|
||||
# Fetch all the info from the header files
|
||||
@@ -216,8 +215,9 @@ class CoverageBuilder(Builder):
|
||||
op.writelines(' - %s\n' % x for x in methods)
|
||||
op.write('\n')
|
||||
|
||||
write_header(op, 'Modules that failed to import')
|
||||
op.writelines(' * %s -- %s\n' % x for x in failed)
|
||||
if failed:
|
||||
write_header(op, 'Modules that failed to import')
|
||||
op.writelines(' * %s -- %s\n' % x for x in failed)
|
||||
finally:
|
||||
op.close()
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ sys.path.append(os.path.abspath('.'))
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = ['ext', 'sphinx.ext.autodoc', 'sphinx.ext.jsmath']
|
||||
extensions = ['ext', 'sphinx.ext.autodoc', 'sphinx.ext.jsmath', 'sphinx.ext.coverage']
|
||||
jsmath_path = 'dummy.js'
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
@@ -172,6 +172,9 @@ latex_documents = [
|
||||
|
||||
value_from_conf_py = 84
|
||||
|
||||
coverage_c_path = ['special/*.h']
|
||||
coverage_c_regexes = {'cfunction': r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)'}
|
||||
|
||||
|
||||
def setup(app):
|
||||
app.add_config_value('value_from_conf_py', 42, False)
|
||||
|
||||
1
tests/root/special/api.h
Normal file
1
tests/root/special/api.h
Normal file
@@ -0,0 +1 @@
|
||||
PyAPI_FUNC(PyObject *) Py_SphinxTest();
|
||||
46
tests/test_coverage.py
Normal file
46
tests/test_coverage.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
test_coverage
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Test the coverage builder.
|
||||
|
||||
:copyright: 2008 by Georg Brandl.
|
||||
:license: BSD.
|
||||
"""
|
||||
|
||||
import pickle
|
||||
|
||||
from util import *
|
||||
|
||||
|
||||
@with_app(buildername='coverage')
|
||||
def test_build(app):
|
||||
app.builder.build_all()
|
||||
|
||||
py_undoc = (app.outdir / 'python.txt').text()
|
||||
assert py_undoc.startswith('Undocumented Python objects\n'
|
||||
'===========================\n')
|
||||
assert 'test_autodoc\n------------\n' in py_undoc
|
||||
assert ' * Class -- missing methods:\n' in py_undoc
|
||||
assert ' * process_docstring\n' in py_undoc
|
||||
assert ' * function\n' not in py_undoc # these two are documented
|
||||
assert ' * Class\n' not in py_undoc # in autodoc.txt
|
||||
|
||||
c_undoc = (app.outdir / 'c.txt').text()
|
||||
assert c_undoc.startswith('Undocumented C API elements\n'
|
||||
'===========================\n')
|
||||
assert 'api.h' in c_undoc
|
||||
assert ' * Py_SphinxTest' in c_undoc
|
||||
|
||||
undoc_py, undoc_c = pickle.loads((app.outdir / 'undoc.pickle').text())
|
||||
assert len(undoc_c) == 1
|
||||
# the key is the full path to the header file, which isn't testable
|
||||
assert undoc_c.values()[0] == [('cfunction', 'Py_SphinxTest')]
|
||||
|
||||
assert 'test_autodoc' in undoc_py
|
||||
assert 'funcs' in undoc_py['test_autodoc']
|
||||
assert 'process_docstring' in undoc_py['test_autodoc']['funcs']
|
||||
assert 'classes' in undoc_py['test_autodoc']
|
||||
assert 'Class' in undoc_py['test_autodoc']['classes']
|
||||
assert 'undocmeth' in undoc_py['test_autodoc']['classes']['Class']
|
||||
Reference in New Issue
Block a user