File: test_doccer.py

package info (click to toggle)
python-scipy 0.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 75,464 kB
  • ctags: 79,406
  • sloc: python: 143,495; cpp: 89,357; fortran: 81,650; ansic: 79,778; makefile: 364; sh: 265
file content (124 lines) | stat: -rw-r--r-- 3,146 bytes parent folder | download | duplicates (2)
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
114
115
116
117
118
119
120
121
122
123
124
''' Some tests for the documenting decorator and support functions '''

from __future__ import division, print_function, absolute_import

import sys
from numpy.testing import assert_equal, dec

from scipy.misc import doccer

# python -OO strips docstrings
DOCSTRINGS_STRIPPED = sys.flags.optimize > 1

docstring = \
"""Docstring
    %(strtest1)s
        %(strtest2)s
     %(strtest3)s
"""
param_doc1 = \
"""Another test
   with some indent"""

param_doc2 = \
"""Another test, one line"""

param_doc3 = \
"""    Another test
       with some indent"""

doc_dict = {'strtest1':param_doc1,
            'strtest2':param_doc2,
            'strtest3':param_doc3}

filled_docstring = \
"""Docstring
    Another test
       with some indent
        Another test, one line
     Another test
       with some indent
"""


def test_unindent():
    yield assert_equal, doccer.unindent_string(param_doc1), param_doc1
    yield assert_equal, doccer.unindent_string(param_doc2), param_doc2
    yield assert_equal, doccer.unindent_string(param_doc3), param_doc1


def test_unindent_dict():
    d2 = doccer.unindent_dict(doc_dict)
    yield assert_equal, d2['strtest1'], doc_dict['strtest1']
    yield assert_equal, d2['strtest2'], doc_dict['strtest2']
    yield assert_equal, d2['strtest3'], doc_dict['strtest1']


def test_docformat():
    udd = doccer.unindent_dict(doc_dict)
    formatted = doccer.docformat(docstring, udd)
    yield assert_equal, formatted, filled_docstring
    single_doc = 'Single line doc %(strtest1)s'
    formatted = doccer.docformat(single_doc, doc_dict)
    # Note - initial indent of format string does not
    # affect subsequent indent of inserted parameter
    yield assert_equal, formatted, """Single line doc Another test
   with some indent"""


@dec.skipif(DOCSTRINGS_STRIPPED)
def test_decorator():
    # with unindentation of parameters
    decorator = doccer.filldoc(doc_dict, True)

    @decorator
    def func():
        """ Docstring
        %(strtest3)s
        """
    yield assert_equal, func.__doc__, """ Docstring
        Another test
           with some indent
        """

    # without unindentation of parameters
    decorator = doccer.filldoc(doc_dict, False)

    @decorator
    def func():
        """ Docstring
        %(strtest3)s
        """
    yield assert_equal, func.__doc__, """ Docstring
            Another test
               with some indent
        """


@dec.skipif(DOCSTRINGS_STRIPPED)
def test_inherit_docstring_from():

    class Foo(object):
        def func(self):
            '''Do something useful.'''
            return

        def func2(self):
            '''Something else.'''

    class Bar(Foo):
        @doccer.inherit_docstring_from(Foo)
        def func(self):
            '''%(super)sABC'''
            return

        @doccer.inherit_docstring_from(Foo)
        def func2(self):
            # No docstring.
            return

    assert_equal(Bar.func.__doc__, Foo.func.__doc__ + 'ABC')
    assert_equal(Bar.func2.__doc__, Foo.func2.__doc__)
    bar = Bar()
    assert_equal(bar.func.__doc__, Foo.func.__doc__ + 'ABC')
    assert_equal(bar.func2.__doc__, Foo.func2.__doc__)