예제 #1
0
def run_doctests(skip_if=False):
    """Run all doctests in the current module.

    For ``skip_if=True``, the tests in the module are skipped.
    """
    from doctest import testmod, NORMALIZE_WHITESPACE, SKIP
    optionflags = NORMALIZE_WHITESPACE
    if skip_if:
        optionflags |= SKIP

    import odl
    import numpy as np

    if run_from_ipython():
        try:
            import spyder
        except ImportError:
            pass
        else:
            if parse_version(spyder.__version__) < parse_version('3.1.4'):
                warnings.warn(
                    'A bug with IPython and Spyder < 3.1.4 '
                    'sometimes cause doctests to fail to run. '
                    'Please upgrade Spyder or use another '
                    'interpreter if the doctests do not work.', RuntimeWarning)

    testmod(optionflags=optionflags, extraglobs={'odl': odl, 'np': np})
예제 #2
0
def run_doctests(skip_if=False, **kwargs):
    """Run all doctests in the current module.

    This function calls ``doctest.testmod()``, by default with the options
    ``optionflags=doctest.NORMALIZE_WHITESPACE`` and
    ``extraglobs={'odl': odl, 'np': np}``. This can be changed with
    keyword arguments.

    Parameters
    ----------
    skip_if : bool
        For ``True``, skip the doctests in this module.
    kwargs :
        Extra keyword arguments passed on to the ``doctest.testmod``
        function.
    """
    from doctest import testmod, NORMALIZE_WHITESPACE, SKIP
    from pkg_resources import parse_version
    import odl
    import numpy as np

    optionflags = kwargs.pop('optionflags', NORMALIZE_WHITESPACE)
    if skip_if:
        optionflags |= SKIP

    extraglobs = kwargs.pop('extraglobs', {'odl': odl, 'np': np})

    if run_from_ipython():
        try:
            import spyder
        except ImportError:
            pass
        else:
            if parse_version(spyder.__version__) < parse_version('3.1.4'):
                warnings.warn(
                    'A bug with IPython and Spyder < 3.1.4 '
                    'sometimes causes doctests to fail to run. '
                    'Please upgrade Spyder or use another '
                    'interpreter if the doctests do not work.', RuntimeWarning)

    testmod(optionflags=optionflags, extraglobs=extraglobs, **kwargs)