File: test_autointerface.py

package info (click to toggle)
python-repoze.sphinx.autointerface 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192 kB
  • sloc: python: 312; makefile: 4
file content (121 lines) | stat: -rw-r--r-- 3,141 bytes parent folder | download
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
import unittest

from .util import TestApp

from .. import autointerface
from sphinx.ext.autodoc import ALL

from docutils.statemachine import ViewList

from zope import interface

class IPlumbusMaker(interface.Interface):

    grumbo = interface.Attribute("The dinglebop is fed through here")
    fleeb = interface.Attribute("The dinglebop is polished with this")

    def smoothTheDinglebop(schleem):
        """
        Smooth it out.

        The schleem is then repurposed.
        """

class Options(dict):
    inherited_members = False
    undoc_members = False
    private_members = False
    special_members = False
    imported_members = False
    show_inheritance = False
    noindex = False
    no_index = False
    annotation = None
    synopsis = ''
    platform = ''
    deprecated = False
    members = ()
    member_order = 'alphabetic'
    exclude_members = ()

    def __init__(self):
        super(Options, self).__init__()
        self.exclude_members = set()
        self.members = []
        self.__dict__ = self

class Settings(object):

    tab_width = 4


class Document(object):

    def __init__(self, settings):
        self.settings = settings


class State(object):

    def __init__(self, document):
        self.document = document


class Directive(object):
    env = None
    genopt = None
    result = None
    record_dependencies = None

    def __init__(self):
        self._warnings = []
        self.filename_set = set()
        self.result = ViewList()
        self.record_dependencies = set()
        self.state = State(Document(Settings()))

    def warn(self, msg):
        self._warnings.append(msg)

class TestAutoInterface(unittest.TestCase):

    def setUp(self):
        app = self.app = TestApp()
        app.builder.env.app = app
        app.builder.env.temp_data['docname'] = 'dummy'

        autointerface.setup(app)

        opt = self.options = Options()
        d = self.directive = Directive()
        d.env = app.builder.env
        d.genopt = opt


    def tearDown(self):
        self.app.cleanup()
        self.app = None

    def assertResultContains(self, item,
                             objtype='interface', name='repoze.sphinx.tests.test_autointerface.IPlumbusMaker',
                             **kw):
        directive = self.directive
        inst = self.app.registry.documenters['interface'](directive, name)
        inst.generate(**kw)
        # print '\n'.join(directive.result)
        self.assertEqual([], directive._warnings)
        self.assertIn(item, directive.result)
        results = directive.result[:]
        del directive.result[:]
        return '\n'.join(results)

    def test_restricted_members(self):
        self.options.members = ['smoothTheDinglebop']
        all_results = self.assertResultContains('   .. method:: smoothTheDinglebop(schleem)')
        self.assertNotIn('grumbo', all_results)

    def test_all_members(self):
        self.options.members = ALL
        all_results = self.assertResultContains('   .. method:: smoothTheDinglebop(schleem)')
        self.assertIn('grumbo', all_results)
        self.assertIn('fleeb', all_results)