Пример #1
0
def test_plot_examples():
    cfg = dict(use_plots=True)

    doc = SphinxDocString("""
    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> plt.plot([1,2,3],[4,5,6])
    >>> plt.show()
    """,
                          config=cfg)
    assert 'plot::' in str(doc), str(doc)

    doc = SphinxDocString("""
    Examples
    --------
    >>> from matplotlib import pyplot as plt
    >>> plt.plot([1,2,3],[4,5,6])
    >>> plt.show()
    """,
                          config=cfg)
    assert 'plot::' in str(doc), str(doc)

    doc = SphinxDocString("""
    Examples
    --------
    .. plot::

       import matplotlib.pyplot as plt
       plt.plot([1,2,3],[4,5,6])
       plt.show()
    """,
                          config=cfg)
    assert str(doc).count('plot::') == 1, str(doc)
Пример #2
0
def test_args_and_kwargs():
    cfg = dict()
    doc = SphinxDocString("""
    Parameters
    ----------
    param1 : int
        First parameter
    *args : tuple
        Arguments
    **kwargs : dict
        Keyword arguments
    """,
                          config=cfg)
    line_by_line_compare(
        str(doc), r"""
:Parameters:

    **param1** : int
        First parameter

    **\*args** : tuple
        Arguments

    **\*\*kwargs** : dict
        Keyword arguments
    """)
Пример #3
0
def test_xref():
    xref_aliases = {
        'sequence': ':obj:`python:sequence`',
    }

    class Config():
        def __init__(self, a, b):
            self.numpydoc_xref_aliases = a
            self.numpydoc_xref_aliases_complete = b

    xref_aliases_complete = deepcopy(DEFAULT_LINKS)
    for key in xref_aliases:
        xref_aliases_complete[key] = xref_aliases[key]
    config = Config(xref_aliases, xref_aliases_complete)
    app = namedtuple('config', 'config')(config)
    update_config(app)

    xref_ignore = {'of', 'default', 'optional'}

    doc = SphinxDocString(xref_doc_txt,
                          config=dict(xref_param_type=True,
                                      xref_aliases=xref_aliases_complete,
                                      xref_ignore=xref_ignore))

    line_by_line_compare(str(doc), xref_doc_txt_expected)
Пример #4
0
def test_sphinx_yields_str():
    sphinx_doc = SphinxDocString(doc_yields_txt)
    line_by_line_compare(
        str(sphinx_doc), """Test generator

:Yields:

    a : int
        The number of apples.

    b : int
        The number of bananas.

    int
        The number of unknowns.
""")
Пример #5
0
def test_xref():
    xref_aliases = {
        'sequence': ':obj:`python:sequence`',
    }
    config = namedtuple('numpydoc_xref_aliases',
                        'numpydoc_xref_aliases')(xref_aliases)
    app = namedtuple('config', 'config')(config)
    update_config(app)

    xref_ignore = {'of', 'default', 'optional'}

    doc = SphinxDocString(xref_doc_txt,
                          config=dict(xref_param_type=True,
                                      xref_aliases=xref_aliases,
                                      xref_ignore=xref_ignore))

    line_by_line_compare(str(doc), xref_doc_txt_expected)
Пример #6
0
def test_unicode():
    doc = SphinxDocString("""
    öäöäöäöäöåååå

    öäöäöäööäååå

    Parameters
    ----------
    ååå : äää
        ööö

    Returns
    -------
    ååå : ööö
        äää

    """)
    assert isinstance(doc['Summary'][0], str)
    assert doc['Summary'][0] == 'öäöäöäöäöåååå'
Пример #7
0
def test_use_blockquotes():
    cfg = dict(use_blockquotes=True)
    doc = SphinxDocString("""
    Parameters
    ----------
    abc : def
        ghi
    jkl
        mno

    Returns
    -------
    ABC : DEF
        GHI
    JKL
        MNO
    """,
                          config=cfg)
    line_by_line_compare(
        str(doc), '''
    :Parameters:

        **abc** : def

            ghi

        **jkl**

            mno

    :Returns:

        **ABC** : DEF

            GHI

        **JKL**

            MNO
    ''')
Пример #8
0
def test_unicode():
    doc = SphinxDocString("""
    öäöäöäöäöåååå

    öäöäöäööäååå

    Parameters
    ----------
    ååå : äää
        ööö

    Returns
    -------
    ååå : ööö
        äää

    """)
    assert isinstance(doc['Summary'][0], str)
    if sys.version_info[0] >= 3:
        assert doc['Summary'][0] == u'öäöäöäöäöåååå'
    else:
        assert doc['Summary'][0] == u'öäöäöäöäöåååå'.encode('utf-8')
Пример #9
0
def test_no_summary():
    str(SphinxDocString("""
    Parameters
    ----------"""))
Пример #10
0
def test_sphinx_str():
    sphinx_doc = SphinxDocString(doc_txt)
    line_by_line_compare(
        str(sphinx_doc), """
.. index:: random
   single: random;distributions, random;gauss

Draw values from a multivariate normal distribution with specified
mean and covariance.

The multivariate normal or Gaussian distribution is a generalisation
of the one-dimensional normal distribution to higher dimensions.

:Parameters:

    mean : (N,) ndarray
        Mean of the N-dimensional distribution.

        .. math::

           (1+2+3)/3

    cov : (N, N) ndarray
        Covariance matrix of the distribution.

    shape : tuple of ints
        Given a shape of, for example, (m,n,k), m*n*k samples are
        generated, and packed in an m-by-n-by-k arrangement.  Because
        each sample is N-dimensional, the output shape is (m,n,k,N).

:Returns:

    out : ndarray
        The drawn samples, arranged according to `shape`.  If the
        shape given is (m,n,...), then the shape of `out` is
        (m,n,...,N).

        In other words, each entry ``out[i,j,...,:]`` is an N-dimensional
        value drawn from the distribution.

    list of str
        This is not a real return value.  It exists to test
        anonymous return values.

    no_description
        ..

:Other Parameters:

    spam : parrot
        A parrot off its mortal coil.

:Raises:

    RuntimeError
        Some error

:Warns:

    RuntimeWarning
        Some warning

.. warning::

    Certain warnings apply.

.. seealso::

    :obj:`some`, :obj:`other`, :obj:`funcs`

    :obj:`otherfunc`
        relationship

.. rubric:: Notes

Instead of specifying the full covariance matrix, popular
approximations include:

  - Spherical covariance (`cov` is a multiple of the identity matrix)
  - Diagonal covariance (`cov` has non-negative elements only on the diagonal)

This geometrical property can be seen in two dimensions by plotting
generated data-points:

>>> mean = [0,0]
>>> cov = [[1,0],[0,100]] # diagonal covariance, points lie on x or y-axis

>>> x,y = multivariate_normal(mean,cov,5000).T
>>> plt.plot(x,y,'x'); plt.axis('equal'); plt.show()

Note that the covariance matrix must be symmetric and non-negative
definite.

.. rubric:: References

.. [1] A. Papoulis, "Probability, Random Variables, and Stochastic
       Processes," 3rd ed., McGraw-Hill Companies, 1991
.. [2] R.O. Duda, P.E. Hart, and D.G. Stork, "Pattern Classification,"
       2nd ed., Wiley, 2001.

.. only:: latex

   [1]_, [2]_

.. rubric:: Examples

>>> mean = (1,2)
>>> cov = [[1,0],[1,0]]
>>> x = multivariate_normal(mean,cov,(3,3))
>>> print x.shape
(3, 3, 2)

The following is probably true, given that 0.6 is roughly twice the
standard deviation:

>>> print list( (x[0,0,:] - mean) < 0.6 )
[True, True]
""")