Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
move unit test + fix an issue in docassert
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Jul 3, 2017
1 parent 0cf689a commit 852aeb9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import os
import unittest
import warnings
import logging

if sys.version_info[0] == 2:
from StringIO import StringIO
else:
from io import StringIO


try:
Expand All @@ -25,6 +31,7 @@
from src.pyquickhelper.loghelper.flog import fLOG
from src.pyquickhelper.sphinxext.sphinx_docassert_extension import import_object
from src.pyquickhelper.helpgen import rst2html
from sphinx.util.logging import getLogger


class TestDocAssert(unittest.TestCase):
Expand All @@ -49,6 +56,15 @@ def test_docassert_html(self):
self._testMethodName,
OutputPrint=__name__ == "__main__")

logger1 = getLogger("MockSphinxApp")
logger2 = getLogger("docassert")

log_capture_string = StringIO()
ch = logging.StreamHandler(log_capture_string)
ch.setLevel(logging.DEBUG)
logger1.logger.addHandler(ch)
logger2.logger.addHandler(ch)

this = os.path.abspath(os.path.dirname(__file__))
data = os.path.join(this, "datadoc")
sys.path.append(data)
Expand All @@ -58,12 +74,10 @@ def test_docassert_html(self):
html = rst2html(docstring)
if "if a and b have different" not in html:
raise Exception(html)
fLOG(len(ws))

newstring = ".. autofunction:: exdocassert.onefunction"
with warnings.catch_warnings(record=True) as ws:
html = rst2html(newstring)
fLOG("number of warnings", len(ws))
for i, w in enumerate(ws):
fLOG(i, ":", w)
if "if a and b have different" not in html:
Expand All @@ -76,9 +90,16 @@ def test_docassert_html(self):
from docutils.parsers.rst.directives import _directives
self.assertTrue("autofunction" in _directives)

fLOG(html)
sys.path.pop()

lines = log_capture_string.getvalue().split("\n")
if len(lines) > 0:
for line in lines:
if "'onefunction' has no parameter 'TypeError'" in line:
raise Exception(
"This warning should not happen.\n{0}".format("\n".join(lines)))
self.assertTrue("<strong>a</strong>" in html)


if __name__ == "__main__":
unittest.main()
12 changes: 10 additions & 2 deletions src/pyquickhelper/helpgen/mock_app_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from sphinx.config import Config
from sphinx.ext.autodoc import setup as setup_autodoc
# from sphinx.ext.imgmath import setup as setup_imgmath
from sphinxcontrib.images import setup as setup_images
from sphinxcontrib.imagesvg import setup as setup_imagesvg
# from sphinx.ext.autosummary import setup as setup_autosummary
from sphinx.ext import autodoc
Expand All @@ -32,6 +31,8 @@
# from sphinx.domains.python import setup as setup_python
from sphinx import __display_version__ as sphinx__display_version__
from sphinx.application import VersionRequirementError
from sphinx.util.logging import getLogger


try:
from sphinx.util.docutils import is_html5_writer_available
Expand Down Expand Up @@ -277,7 +278,14 @@ def create(writer="sphinx", directives=None, verbose=False, fLOG=None):
setup_todo(app)

setup_autodoc(app)
setup_images(app)
try:
from sphinxcontrib.images import setup as setup_images
setup_images(app)
except ImportError:
# Probably a mismatch between versions.
logger = getLogger("MockSphinxApp")
logger.warning(
"[MockSphinxApp] unable to import 'sphinxcontrib.images'.")
setup_imagesvg(app)

# don't move this import to the beginning of file
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/sphinxext/sphinx_docassert_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def override_transform(self, other_self, node):
by the function is the same the list of documented arguments.
"""
typemap = other_self.typemap

entries = []
groupindices = {} # type: Dict[unicode, int]
types = {} # type: Dict[unicode, Dict]
Expand All @@ -169,6 +168,8 @@ def override_transform(self, other_self, node):
except ValueError:
# maybe an argument-less field type?
fieldtype, fieldarg = fieldname.astext(), ''
if fieldtype != "param":
continue
typedesc, is_typefield = typemap.get(fieldtype, (None, None))

# sort out unknown fields
Expand Down

0 comments on commit 852aeb9

Please sign in to comment.