Back to index

plone3  3.1.7
test_directive.py
Go to the documentation of this file.
00001 
00002 import sys
00003 import unittest
00004 from zope.testing.doctestunit import DocTestSuite
00005 from __parent__ import __parent__
00006 configfeature = __parent__(__name__, 2)
00007 
00008 def test_module_level():
00009     """
00010     Module level access.
00011 
00012     >>> import zope.configuration.tests
00013     >>> import zope.configuration.xmlconfig
00014     >>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)
00015 
00016     >>> import tempfile
00017     >>> fn = tempfile.mktemp('.zcml')
00018     >>> zcml = open(fn, 'w')
00019     >>> zcml.write('''
00020     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00021     ...            xmlns:five="http://namespaces.zope.org/five">
00022     ...     <five:configfeature
00023     ...         feature="conf1"
00024     ...         instance=".configtest"
00025     ...         attribute="conf1"
00026     ...     />
00027     ...     <five:configfeature
00028     ...         feature="conf2"
00029     ...         instance=".configtest"
00030     ...         attribute="conf2"
00031     ...     />
00032     ...     <five:configfeature
00033     ...         feature="conf2n"
00034     ...         instance=".configtest"
00035     ...         attribute="conf2"
00036     ...         negate="True"
00037     ...     />
00038     ... </configure>
00039     ... ''')
00040     >>> zcml.close()
00041 
00042     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context)
00043 
00044     >>> context.hasFeature('conf1')
00045     True
00046     >>> context.hasFeature('conf2')
00047     False
00048     >>> context.hasFeature('conf2n')
00049     True
00050 
00051     """
00052 
00053 
00054 def test_objectlevel():
00055     """
00056     Object level access.
00057 
00058     >>> import zope.configuration.tests
00059     >>> import zope.configuration.xmlconfig
00060     >>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)
00061 
00062     >>> import tempfile
00063     >>> fn = tempfile.mktemp('.zcml')
00064     >>> zcml = open(fn, 'w')
00065     >>> zcml.write('''
00066     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00067     ...            xmlns:five="http://namespaces.zope.org/five">
00068     ...     <five:configfeature
00069     ...         feature="conf3"
00070     ...         instance=".configtest.cobj"
00071     ...         attribute="conf3"
00072     ...     />
00073     ...     <five:configfeature
00074     ...         feature="conf4"
00075     ...         instance=".configtest.cobj"
00076     ...         attribute="conf4"
00077     ...     />
00078     ...     <five:configfeature
00079     ...         feature="conf4n"
00080     ...         instance=".configtest.cobj"
00081     ...         attribute="conf4"
00082     ...         negate="True"
00083     ...     />
00084     ... </configure>
00085     ... ''')
00086     >>> zcml.close()
00087 
00088     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context)
00089 
00090     >>> context.hasFeature('conf3')
00091     True
00092     >>> context.hasFeature('conf4')
00093     False
00094     >>> context.hasFeature('conf4n')
00095     True
00096 
00097     """
00098 
00099 
00100 def test_dict_level():
00101     """
00102     Dictionary level access.
00103 
00104     >>> import zope.configuration.tests
00105     >>> import zope.configuration.xmlconfig
00106     >>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)
00107 
00108     >>> import tempfile
00109     >>> fn = tempfile.mktemp('.zcml')
00110     >>> zcml = open(fn, 'w')
00111     >>> zcml.write('''
00112     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00113     ...            xmlns:five="http://namespaces.zope.org/five">
00114     ...     <five:configfeature
00115     ...         feature="conf5"
00116     ...         instance=".configtest.dobj"
00117     ...         attribute="conf5"
00118     ...     />
00119     ...     <five:configfeature
00120     ...         feature="conf6"
00121     ...         instance=".configtest.dobj"
00122     ...         attribute="conf6"
00123     ...     />
00124     ...     <five:configfeature
00125     ...         feature="conf6n"
00126     ...         instance=".configtest.dobj"
00127     ...         attribute="conf6"
00128     ...         negate="True"
00129     ...     />
00130     ... </configure>
00131     ... ''')
00132     >>> zcml.close()
00133 
00134     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context)
00135 
00136     >>> context.hasFeature('conf5')
00137     True
00138     >>> context.hasFeature('conf6')
00139     False
00140     >>> context.hasFeature('conf6n')
00141     True
00142 
00143     """
00144 
00145 
00146 def test_errors():
00147     """
00148     Testing errors.
00149 
00150     >>> import zope.configuration.tests
00151     >>> import zope.configuration.xmlconfig
00152     >>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)
00153 
00154     No such instance: raises an error.
00155 
00156     >>> import tempfile
00157     >>> fn = tempfile.mktemp('.zcml')
00158     >>> zcml = open(fn, 'w')
00159     >>> zcml.write('''
00160     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00161     ...            xmlns:five="http://namespaces.zope.org/five">
00162     ...     <five:configfeature
00163     ...         feature="conf1"
00164     ...         instance=".configtest.nosuch"
00165     ...         attribute="conf1"
00166     ...     />
00167     ... </configure>
00168     ... ''')
00169     >>> zcml.close()
00170 
00171     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context) #doctest: +ELLIPSIS
00172     Traceback (most recent call last):
00173     ...
00174     ZopeXMLConfigurationError: ...
00175         ConfigurationError: ...
00176 
00177     No such attribute: an error too
00178 
00179     >>> fn = tempfile.mktemp('.zcml')
00180     >>> zcml = open(fn, 'w')
00181     >>> zcml.write('''
00182     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00183     ...            xmlns:five="http://namespaces.zope.org/five">
00184     ...     <five:configfeature
00185     ...         feature="conf1"
00186     ...         instance=".configtest.cobj"
00187     ...         attribute="nosuch"
00188     ...     />
00189     ... </configure>
00190     ... ''')
00191     >>> zcml.close()
00192 
00193     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context) #doctest: +ELLIPSIS
00194     Traceback (most recent call last):
00195     ...
00196     ZopeXMLConfigurationError: ...
00197         ConfigurationError: Object ... does not have attribute or key "nosuch"
00198 
00199     No such key: an error too 
00200 
00201     >>> fn = tempfile.mktemp('.zcml')
00202     >>> zcml = open(fn, 'w')
00203     >>> zcml.write('''
00204     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00205     ...            xmlns:five="http://namespaces.zope.org/five">
00206     ...     <five:configfeature
00207     ...         feature="conf1"
00208     ...         instance=".configtest.dobj"
00209     ...         attribute="nosuch"
00210     ...     />
00211     ... </configure>
00212     ... ''')
00213     >>> zcml.close()
00214 
00215     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context) #doctest: +ELLIPSIS
00216     Traceback (most recent call last):
00217     ...
00218     ZopeXMLConfigurationError: ...
00219         ConfigurationError: Object ... does not have attribute or key "nosuch"
00220     
00221     """
00222 
00223 
00224 def test_suite():
00225     return unittest.TestSuite((
00226         DocTestSuite(configfeature.__name__ + '.meta'),
00227         DocTestSuite(),
00228         ))