Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
zope.interface / docs / _build / doctrees / verify.doctree
Size: Mime:
€cdocutils.nodes
document
q)q}q(UtagnameqUdocumentqUreporterqNU
attributesq}q(Udupnamesq	]Ubackrefsq
]UsourceX=/home/tseaver/projects/Zope/Z3/zope.interface/docs/verify.rstqUidsq]Uclassesq
]Unamesq]uUparse_messagesq]qU
decorationqNU	citationsq]qU	rawsourceqUU	nametypesq}q(Xverifying classesqNXtesting for attributesqNXverifying objectsqNX#verifying interface implementationsqNuUsettingsq(cdocutils.frontend
Values
qoq}q(Upep_referencesqNUoutput_encoding_error_handlerq Ustrictq!U
halt_levelq"KU
source_urlq#NU
dump_settingsq$NUdoctitle_xformq%‰Udump_pseudo_xmlq&NU	tab_widthq'KU	id_prefixq(UUtitleq)NUembed_stylesheetq*‰U
docinfo_xformq+KUfootnote_backlinksq,KUerror_encodingq-UUTF-8q.Uauto_id_prefixq/Uidq0U
language_codeq1Uenq2U	datestampq3NUdump_transformsq4NUoutput_encodingq5Uutf-8q6Uexit_status_levelq7KUstrict_visitorq8NU_disable_configq9NUfile_insertion_enabledq:ˆU	tracebackq;ˆUrecord_dependenciesq<NUstrip_commentsq=NUdebugq>NU	generatorq?NUgettext_compactq@ˆUenvqANU
strip_classesqBNUpep_file_url_templateqCUpep-%04dqDUinput_encoding_error_handlerqEh!Uexpose_internalsqFNUrfc_referencesqGNU
toc_backlinksqHUentryqIUtrim_footnote_reference_spaceqJ‰U_sourceqKhUwarning_streamqLNUinput_encodingqMU	utf-8-sigqNUsectsubtitle_xformqO‰Usource_linkqPNUconfigqQNU
sectnum_xformqRKUerror_encoding_error_handlerqSUbackslashreplaceqTU
_config_filesqU]Udump_internalsqVNUsmart_quotesqW‰Ucloak_email_addressesqXˆUraw_enabledqYKUstrip_elements_with_classesqZNUpep_base_urlq[U https://www.python.org/dev/peps/q\Ureport_levelq]KUrfc_base_urlq^Uhttps://tools.ietf.org/html/q_U_destinationq`NUsyntax_highlightqaUlongqbubUautofootnote_refsqc]qdU
footnote_refsqe}qfUid_startqgKU
citation_refsqh}qiUsymbol_footnote_refsqj]qkUtransform_messagesql]qmU	footnotesqn]qoUnameidsqp}qq(hUverifying-classesqrhUtesting-for-attributesqshUverifying-objectsqthU#verifying-interface-implementationsquuUrefnamesqv}qwUtransformerqxNUidsqy}qz(hscdocutils.nodes
section
q{)q|}q}(hhhUsectionq~h}q(h
]h	]h]q€hah]qhsah
]uUlineq‚K UsourceqƒhhUUparentq„h{)q…}q†(hhhh~h}q‡(h
]h	]h]qˆhah]q‰htah
]uh‚KhƒhhUh„h{)qŠ}q‹(hhhh~h}qŒ(h
]h	]h]qhah]qŽhuah
]uh‚KhƒhhUh„hUchildrenq]q(cdocutils.nodes
title
q‘)q’}q“(hhhh)h}q”(h
]h	]h]h]h
]uh‚KhƒhhX#Verifying interface implementationsq•h„hŠh]q–cdocutils.nodes
Text
q—X#Verifying interface implementationsq˜…q™}qš(hh•h„h’ubaubcdocutils.nodes
paragraph
q›)qœ}q(hhhU	paragraphqžh}qŸ(h
]h	]h]h]h
]uh‚KhƒhhX•The ``zope.interface.verify`` module provides functions that test whether a
given interface is implemented by a class or provided by an object, resp.h„hŠh]q (h—XThe q¡…q¢}q£(hXThe h„hœubcdocutils.nodes
literal
q¤)q¥}q¦(hX``zope.interface.verify``hUliteralq§h}q¨(h
]h	]h]h]h
]uh„hœh]q©h—Xzope.interface.verifyqª…q«}q¬(hUh„h¥ubaubh—Xx module provides functions that test whether a
given interface is implemented by a class or provided by an object, resp.q­…q®}q¯(hXx module provides functions that test whether a
given interface is implemented by a class or provided by an object, resp.h„hœubeubh{)q°}q±(hhhh~h}q²(h
]h	]h]q³hah]q´hrah
]uh‚K
hƒhhUh„hŠh]qµ(h‘)q¶}q·(hhhh)h}q¸(h
]h	]h]h]h
]uh‚K
hƒhhXVerifying classesq¹h„h°h]qºh—XVerifying classesq»…q¼}q½(hh¹h„h¶ubaubh›)q¾}q¿(hhhhžh}qÀ(h
]h	]h]h]h
]uh‚KhƒhhXNThis is covered by unit tests defined in ``zope.interface.tests.test_verify``.qÁh„h°h]qÂ(h—X)This is covered by unit tests defined in qŁqÄ}qÅ(hX)This is covered by unit tests defined in h„h¾ubh¤)qÆ}qÇ(hX$``zope.interface.tests.test_verify``hh§h}qÈ(h
]h	]h]h]h
]uh„h¾h]qÉh—X zope.interface.tests.test_verifyqʅqË}qÌ(hUh„hÆubaubh—X.…qÍ}qÎ(hX.h„h¾ubeubeubh…eubh]qÏ(h‘)qÐ}qÑ(hhhh)h}qÒ(h
]h	]h]h]h
]uh‚KhƒhhXVerifying objectsqÓh„h…h]qÔh—XVerifying objectsqՅqÖ}q×(hhÓh„hÐubaubh›)qØ}qÙ(hhhhžh}qÚ(h
]h	]h]h]h
]uh‚KhƒhhX"An object provides an interface ifqÛh„h…h]qÜh—X"An object provides an interface ifq݅qÞ}qß(hhÛh„hØubaubcdocutils.nodes
bullet_list
qà)qá}qâ(hhhUbullet_listqãh}qä(h	]h
]h
]h]UbulletqåX-h]uh‚KhƒhhUh„h…h]qæ(cdocutils.nodes
list_item
qç)qè}qé(hhhU	list_itemqêh}që(h
]h	]h]h]h
]uh‚NhƒhhX|either its class declares that it implements the interfaces, or the object
declares that it directly provides the interface
h„háh]qìh›)qí}qî(hhžh}qï(h
]h	]h]h]h
]uh‚KhƒhhX{either its class declares that it implements the interfaces, or the object
declares that it directly provides the interfaceqðh„hèh]qñh—X{either its class declares that it implements the interfaces, or the object
declares that it directly provides the interfaceqò…qó}qô(hhðh„híubaubaubhç)qõ}qö(hhhhêh}q÷(h
]h	]h]h]h
]uh‚NhƒhhX=the object defines all the methods required by the interface
h„háh]qøh›)qù}qú(hhžh}qû(h
]h	]h]h]h
]uh‚KhƒhhX<the object defines all the methods required by the interfaceqüh„hõh]qýh—X<the object defines all the methods required by the interfaceqþ…qÿ}r(hhüh„hùubaubaubhç)r}r(hhhhêh}r(h
]h	]h]h]h
]uh‚NhƒhhX+all the methods have the correct signature
h„háh]rh›)r}r(hhžh}r(h
]h	]h]h]h
]uh‚KhƒhhX*all the methods have the correct signaturerh„jh]r	h—X*all the methods have the correct signaturer
…r}r(hjh„jubaubaubhç)r
}r(hhhhêh}r(h
]h	]h]h]h
]uh‚NhƒhhXGthe object defines all non-method attributes required by the interface
h„háh]rh›)r}r(hhžh}r(h
]h	]h]h]h
]uh‚KhƒhhXFthe object defines all non-method attributes required by the interfacerh„j
h]rh—XFthe object defines all non-method attributes required by the interfacer…r}r(hjh„jubaubaubeubh›)r}r(hhhhžh}r(h
]h	]h]h]h
]uh‚KhƒhhX3This doctest currently covers only the latter item.rh„h…h]rh—X3This doctest currently covers only the latter item.r…r}r (hjh„jubaubh|eubh]r!(h‘)r"}r#(hhhh)h}r$(h
]h	]h]h]h
]uh‚K hƒhhXTesting for attributesr%h„h|h]r&h—XTesting for attributesr'…r(}r)(hj%h„j"ubaubh›)r*}r+(hhhhžh}r,(h
]h	]h]h]h
]uh‚K"hƒhhXoAttributes of the object, be they defined by its class or added by its
``__init__`` method, will be recognized:h„h|h]r-(h—XGAttributes of the object, be they defined by its class or added by its
r.…r/}r0(hXGAttributes of the object, be they defined by its class or added by its
h„j*ubh¤)r1}r2(hX``__init__``hh§h}r3(h
]h	]h]h]h
]uh„j*h]r4h—X__init__r5…r6}r7(hUh„j1ubaubh—X method, will be recognized:r8…r9}r:(hX method, will be recognized:h„j*ubeubcdocutils.nodes
literal_block
r;)r<}r=(hhhU
literal_blockr>h}r?(h	]U	xml:spacer@UpreserverAh
]UtestnodetypeXdoctesth
]Ugroups]rBUdefaultrCah]UoptionsrD}h]uh‚K%hƒhhX´>>> from zope.interface import Interface, Attribute, implements
>>> from zope.interface.exceptions import BrokenImplementation
>>> class IFoo(Interface):
...     x = Attribute("The X attribute")
...     y = Attribute("The Y attribute")

>>> class Foo(object):
...     implements(IFoo)
...     x = 1
...     def __init__(self):
...         self.y = 2

>>> from zope.interface.verify import verifyObject
>>> verifyObject(IFoo, Foo())
Trueh„h|h]rEh—X´>>> from zope.interface import Interface, Attribute, implements
>>> from zope.interface.exceptions import BrokenImplementation
>>> class IFoo(Interface):
...     x = Attribute("The X attribute")
...     y = Attribute("The Y attribute")

>>> class Foo(object):
...     implements(IFoo)
...     x = 1
...     def __init__(self):
...         self.y = 2

>>> from zope.interface.verify import verifyObject
>>> verifyObject(IFoo, Foo())
TruerF…rG}rH(hUh„j<ubaubh›)rI}rJ(hhhhžh}rK(h
]h	]h]h]h
]uh‚K7hƒhhX7If either attribute is missing, verification will fail:rLh„h|h]rMh—X7If either attribute is missing, verification will fail:rN…rO}rP(hjLh„jIubaubj;)rQ}rR(hhhj>h}rS(h	]j@jAh
]UtestnodetypeXdoctesth
]Ugroups]rTjCah]jD}UtestrUXÊ>>> class Foo(object):
...     implements(IFoo)
...     x = 1
>>> try: #doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
...     verifyObject(IFoo, Foo())
... except BrokenImplementation, e:
...     print str(e)
An object has failed to implement interface <InterfaceClass ...IFoo>
<BLANKLINE>
        The y attribute was not provided.
<BLANKLINE>
>>> class Foo(object):
...     implements(IFoo)
...     def __init__(self):
...         self.y = 2
>>> try: #doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
...     verifyObject(IFoo, Foo())
... except BrokenImplementation, e:
...     print str(e)
An object has failed to implement interface <InterfaceClass ...IFoo>
<BLANKLINE>
        The x attribute was not provided.
<BLANKLINE>h]uh‚K9hƒhhXL>>> class Foo(object):
...     implements(IFoo)
...     x = 1
>>> try: 
...     verifyObject(IFoo, Foo())
... except BrokenImplementation, e:
...     print str(e)
An object has failed to implement interface <InterfaceClass ...IFoo>

        The y attribute was not provided.

>>> class Foo(object):
...     implements(IFoo)
...     def __init__(self):
...         self.y = 2
>>> try: 
...     verifyObject(IFoo, Foo())
... except BrokenImplementation, e:
...     print str(e)
An object has failed to implement interface <InterfaceClass ...IFoo>

        The x attribute was not provided.
h„h|h]rVh—XL>>> class Foo(object):
...     implements(IFoo)
...     x = 1
>>> try: 
...     verifyObject(IFoo, Foo())
... except BrokenImplementation, e:
...     print str(e)
An object has failed to implement interface <InterfaceClass ...IFoo>

        The y attribute was not provided.

>>> class Foo(object):
...     implements(IFoo)
...     def __init__(self):
...         self.y = 2
>>> try: 
...     verifyObject(IFoo, Foo())
... except BrokenImplementation, e:
...     print str(e)
An object has failed to implement interface <InterfaceClass ...IFoo>

        The x attribute was not provided.
rW…rX}rY(hUh„jQubaubh›)rZ}r[(hhhhžh}r\(h
]h	]h]h]h
]uh‚KShƒhhXIf an attribute is implemented as a property that raises an AttributeError
when trying to get its value, the attribute is considered missing:r]h„h|h]r^h—XIf an attribute is implemented as a property that raises an AttributeError
when trying to get its value, the attribute is considered missing:r_…r`}ra(hj]h„jZubaubj;)rb}rc(hhhj>h}rd(h	]j@jAh
]UtestnodetypeXdoctesth
]Ugroups]rejCah]jD}jUXÐ>>> class IFoo(Interface):
...     x = Attribute('The X attribute')
>>> class Foo(object):
...     implements(IFoo)
...     @property
...     def x(self):
...         raise AttributeError
>>> try: #doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
...     verifyObject(IFoo, Foo())
... except BrokenImplementation, e:
...     print str(e)
An object has failed to implement interface <InterfaceClass ...IFoo>
<BLANKLINE>
        The x attribute was not provided.
<BLANKLINE>h]uh‚KVhƒhhX‘>>> class IFoo(Interface):
...     x = Attribute('The X attribute')
>>> class Foo(object):
...     implements(IFoo)
...     @property
...     def x(self):
...         raise AttributeError
>>> try: 
...     verifyObject(IFoo, Foo())
... except BrokenImplementation, e:
...     print str(e)
An object has failed to implement interface <InterfaceClass ...IFoo>

        The x attribute was not provided.
h„h|h]rfh—X‘>>> class IFoo(Interface):
...     x = Attribute('The X attribute')
>>> class Foo(object):
...     implements(IFoo)
...     @property
...     def x(self):
...         raise AttributeError
>>> try: 
...     verifyObject(IFoo, Foo())
... except BrokenImplementation, e:
...     print str(e)
An object has failed to implement interface <InterfaceClass ...IFoo>

        The x attribute was not provided.
rg…rh}ri(hUh„jbubaubh›)rj}rk(hhhhžh}rl(h
]h	]h]h]h
]uh‚KhhƒhhXZAny other exception raised by a property will propagate to the caller of
``verifyObject``:h„h|h]rm(h—XIAny other exception raised by a property will propagate to the caller of
rn…ro}rp(hXIAny other exception raised by a property will propagate to the caller of
h„jjubh¤)rq}rr(hX``verifyObject``hh§h}rs(h
]h	]h]h]h
]uh„jjh]rth—XverifyObjectru…rv}rw(hUh„jqubaubh—X:…rx}ry(hX:h„jjubeubj;)rz}r{(hhhj>h}r|(h	]j@jAh
]UtestnodetypeXdoctesth
]Ugroups]r}jCah]jD}h]uh‚KkhƒhhX½>>> class Foo(object):
...     implements(IFoo)
...     @property
...     def x(self):
...         raise Exception
>>> verifyObject(IFoo, Foo())
Traceback (most recent call last):
Exceptionh„h|h]r~h—X½>>> class Foo(object):
...     implements(IFoo)
...     @property
...     def x(self):
...         raise Exception
>>> verifyObject(IFoo, Foo())
Traceback (most recent call last):
Exceptionr…r€}r(hUh„jzubaubh›)r‚}rƒ(hhhhžh}r„(h
]h	]h]h]h
]uh‚KvhƒhhXVOf course, broken properties that are not required by the interface don't do
any harm:r…h„h|h]r†h—XVOf course, broken properties that are not required by the interface don't do
any harm:r‡…rˆ}r‰(hj…h„j‚ubaubj;)rŠ}r‹(hhhj>h}rŒ(h	]j@jAh
]UtestnodetypeXdoctesth
]Ugroups]rjCah]jD}h]uh‚KyhƒhhX£>>> class Foo(object):
...     implements(IFoo)
...     x = 1
...     @property
...     def y(self):
...         raise Exception
>>> verifyObject(IFoo, Foo())
Trueh„h|h]rŽh—X£>>> class Foo(object):
...     implements(IFoo)
...     x = 1
...     @property
...     def y(self):
...         raise Exception
>>> verifyObject(IFoo, Foo())
Truer…r}r‘(hUh„jŠubaubeubhth…huhŠhrh°uUsymbol_footnotesr’]r“hhUindirect_targetsr”]r•Usubstitution_namesr–}r—Ucurrent_liner˜NUsubstitution_defsr™}ršUsymbol_footnote_startr›KUautofootnote_startrœKU
autofootnotesr]ržh]rŸhŠaUcurrent_sourcer NUrefidsr¡}r¢ub.