~ubuntu-branches/debian/sid/pydoctor/sid

« back to all changes in this revision

Viewing changes to pydoctor/test/test_zopeinterface.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2013-09-15 13:58:49 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130915135849-g206zbvqwvz0ptdg
Tags: 0.5b1+bzr603-1
* New upstream snapshot.
* Switch from cdbs to dh.
* Bump standards version to 3.9.4 (no changes).
* Update Vcs header.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    '''
45
45
    implements_test(src)
46
46
 
 
47
def test_implementer():
 
48
    src = '''
 
49
    import zope.interface
 
50
 
 
51
    class IFoo(zope.interface.Interface):
 
52
        pass
 
53
    class IBar(zope.interface.Interface):
 
54
        pass
 
55
 
 
56
    @zope.interface.implementer(IFoo)
 
57
    class Foo:
 
58
        pass
 
59
    @zope.interface.implementer(IBar)
 
60
    class FooBar(Foo):
 
61
        pass
 
62
    class OnlyBar(Foo):
 
63
        zope.interface.implementsOnly(IBar)
 
64
    '''
 
65
    implements_test(src)
47
66
 
48
67
def implements_test(src):
49
68
    mod = fromText(src, 'zi', systemcls=ZopeInterfaceSystem)
79
98
    class A(A):
80
99
        pass
81
100
    '''
82
 
    mod = fromText(src, 'zi', systemcls=ZopeInterfaceSystem)
 
101
    fromText(src, 'zi', systemcls=ZopeInterfaceSystem)
83
102
 
84
103
def test_multiply_inheriting_interfaces():
85
104
    src = '''
104
123
    assert len(mod.contents['C'].contents) == 1
105
124
 
106
125
def test_interfaceclass():
107
 
    src = '''
108
 
    import zope.interface as zi
109
 
    class MyInterfaceClass(zi.interface.InterfaceClass):
110
 
        pass
111
 
    MyInterface = MyInterfaceClass("MyInterface")
112
 
    class AnInterface(MyInterface):
113
 
        pass
114
 
    '''
115
126
    system = processPackage('interfaceclass', systemcls=ZopeInterfaceSystem)
116
127
    mod = system.allobjects['interfaceclass.mod']
117
128
    assert mod.contents['AnInterface'].isinterface
130
141
    src = '''
131
142
    from zope import schema, interface
132
143
    class IMyInterface(interface.Interface):
133
 
        text = zope.schema.TextLine(description="fun in a bun")
 
144
        text = schema.TextLine(description="fun in a bun")
134
145
    '''
135
146
    mod = fromText(src, systemcls=ZopeInterfaceSystem)
136
147
    text = mod.contents['IMyInterface'].contents['text']
141
152
    src = '''
142
153
    from zope import schema, interface
143
154
    class IMyInterface(interface.Interface):
144
 
        attribute = zope.interface.Attribute(_("fun in a bun"))
145
 
        text = zope.schema.TextLine(description=_("fun in a bap"))
 
155
        attribute = interface.Attribute(_("fun in a bun"))
 
156
        text = schema.TextLine(description=_("fun in a bap"))
146
157
    '''
147
158
    mod = fromText(src, systemcls=ZopeInterfaceSystem)
148
159
    text = mod.contents['IMyInterface'].contents['attribute']
157
168
    src = '''
158
169
    from zope import schema, interface
159
170
    from zope.schema import Int as INTEGERSCHMEMAFIELD
160
 
    class MyTextLine(zope.schema.TextLine):
 
171
    class MyTextLine(schema.TextLine):
161
172
        pass
162
173
    class MyOtherTextLine(MyTextLine):
163
174
        pass
175
186
    assert myothertext.kind == "MyOtherTextLine"
176
187
    myint = mod.contents['IMyInterface'].contents['myint']
177
188
    assert myint.kind == "Int"
 
189
 
 
190
def test_docsources_includes_interface():
 
191
    src = '''
 
192
    from zope import interface
 
193
    class IInterface(interface.Interface):
 
194
        def method(self):
 
195
            """documentation"""
 
196
    class Implementation:
 
197
        interface.implements(IInterface)
 
198
        def method(self):
 
199
            pass
 
200
    '''
 
201
    mod = fromText(src, systemcls=ZopeInterfaceSystem)
 
202
    imethod = mod.contents['IInterface'].contents['method']
 
203
    method = mod.contents['Implementation'].contents['method']
 
204
    assert imethod in method.docsources(), list(method.docsources())
 
205
 
 
206
def test_docsources_includes_baseinterface():
 
207
    src = '''
 
208
    from zope import interface
 
209
    class IBase(interface.Interface):
 
210
        def method(self):
 
211
            """documentation"""
 
212
    class IExtended(IBase):
 
213
        pass
 
214
    class Implementation:
 
215
        interface.implements(IExtended)
 
216
        def method(self):
 
217
            pass
 
218
    '''
 
219
    mod = fromText(src, systemcls=ZopeInterfaceSystem)
 
220
    imethod = mod.contents['IBase'].contents['method']
 
221
    method = mod.contents['Implementation'].contents['method']
 
222
    assert imethod in method.docsources(), list(method.docsources())
 
223
 
 
224
def test_docsources_from_moduleprovides():
 
225
    src = '''
 
226
    from zope import interface
 
227
 
 
228
    class IBase(interface.Interface):
 
229
        def bar():
 
230
            """documentation"""
 
231
 
 
232
    interface.moduleProvides(IBase)
 
233
 
 
234
    def bar():
 
235
        pass
 
236
    '''
 
237
    mod = fromText(src, systemcls=ZopeInterfaceSystem)
 
238
    imethod = mod.contents['IBase'].contents['bar']
 
239
    function = mod.contents['bar']
 
240
    assert imethod in function.docsources(), list(function.docsources())