1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import sys
import pytest
from . import *
from ....tests import *
from ....utils import iteritems
pytest.importorskip('sphinx') # skips these tests if sphinx not present
class FakeEnv(object):
"""
Mocks up a sphinx env setting construct for automodapi tests
"""
def __init__(self, **kwargs):
for k, v in iteritems(kwargs):
setattr(self, k, v)
class FakeBuilder(object):
"""
Mocks up a sphinx builder setting construct for automodapi tests
"""
def __init__(self, **kwargs):
self.env = FakeEnv(**kwargs)
class FakeApp(object):
"""
Mocks up a `sphinx.application.Application` object for automodapi tests
"""
def __init__(self, srcdir, automodapipresent=True):
self.builder = FakeBuilder(srcdir=srcdir)
self.info = []
self.warnings = []
self._extensions = []
if automodapipresent:
self._extensions.append('astropy_helpers.sphinx.ext.automodapi')
def info(self, msg, loc):
self.info.append((msg, loc))
def warn(self, msg, loc):
self.warnings.append((msg, loc))
ams_to_asmry_str = """
Before
.. automodsumm:: astropy_helpers.sphinx.ext.automodsumm
:p:
And After
"""
ams_to_asmry_expected = """\
.. currentmodule:: astropy_helpers.sphinx.ext.automodsumm
.. autosummary::
:p:
Automoddiagram
Automodsumm
automodsumm_to_autosummary_lines
generate_automodsumm_docs
process_automodsumm_generation
setup"""
def test_ams_to_asmry(tmpdir):
from ..automodsumm import automodsumm_to_autosummary_lines
fi = tmpdir.join('automodsumm.rst')
fi.write(ams_to_asmry_str)
fakeapp = FakeApp(srcdir='')
resultlines = automodsumm_to_autosummary_lines(str(fi), fakeapp)
assert '\n'.join(resultlines) == ams_to_asmry_expected
ams_cython_str = """
Before
.. automodsumm:: _eva_.unit02
:functions-only:
:p:
And After
"""
ams_cython_expected = """\
.. currentmodule:: _eva_.unit02
.. autosummary::
:p:
pilot"""
def test_ams_cython(tmpdir, cython_testpackage):
from ..automodsumm import automodsumm_to_autosummary_lines
fi = tmpdir.join('automodsumm.rst')
fi.write(ams_cython_str)
fakeapp = FakeApp(srcdir='')
resultlines = automodsumm_to_autosummary_lines(str(fi), fakeapp)
assert '\n'.join(resultlines) == ams_cython_expected
|