Back to index

plone3  3.1.7
Functions | Variables
kss.demo.configfeature.tests.test_directive Namespace Reference

Functions

def test_module_level
def test_objectlevel
def test_dict_level
def test_errors
def test_suite

Variables

tuple configfeature = __parent__(__name__, 2)

Function Documentation

Dictionary level access.

>>> import zope.configuration.tests
>>> import zope.configuration.xmlconfig
>>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)

>>> import tempfile
>>> fn = tempfile.mktemp('.zcml')
>>> zcml = open(fn, 'w')
>>> zcml.write('''
... <configure xmlns:meta="http://namespaces.zope.org/meta"
...            xmlns:five="http://namespaces.zope.org/five">
...     <five:configfeature
...         feature="conf5"
...         instance=".configtest.dobj"
...         attribute="conf5"
...     />
...     <five:configfeature
...         feature="conf6"
...         instance=".configtest.dobj"
...         attribute="conf6"
...     />
...     <five:configfeature
...         feature="conf6n"
...         instance=".configtest.dobj"
...         attribute="conf6"
...         negate="True"
...     />
... </configure>
... ''')
>>> zcml.close()

>>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context)

>>> context.hasFeature('conf5')
True
>>> context.hasFeature('conf6')
False
>>> context.hasFeature('conf6n')
True

Definition at line 100 of file test_directive.py.

00100 
00101 def test_dict_level():
00102     """
00103     Dictionary level access.
00104 
00105     >>> import zope.configuration.tests
00106     >>> import zope.configuration.xmlconfig
00107     >>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)
00108 
00109     >>> import tempfile
00110     >>> fn = tempfile.mktemp('.zcml')
00111     >>> zcml = open(fn, 'w')
00112     >>> zcml.write('''
00113     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00114     ...            xmlns:five="http://namespaces.zope.org/five">
00115     ...     <five:configfeature
00116     ...         feature="conf5"
00117     ...         instance=".configtest.dobj"
00118     ...         attribute="conf5"
00119     ...     />
00120     ...     <five:configfeature
00121     ...         feature="conf6"
00122     ...         instance=".configtest.dobj"
00123     ...         attribute="conf6"
00124     ...     />
00125     ...     <five:configfeature
00126     ...         feature="conf6n"
00127     ...         instance=".configtest.dobj"
00128     ...         attribute="conf6"
00129     ...         negate="True"
00130     ...     />
00131     ... </configure>
00132     ... ''')
00133     >>> zcml.close()
00134 
00135     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context)
00136 
00137     >>> context.hasFeature('conf5')
00138     True
00139     >>> context.hasFeature('conf6')
00140     False
00141     >>> context.hasFeature('conf6n')
00142     True
00143 
00144     """
00145 

Testing errors.

>>> import zope.configuration.tests
>>> import zope.configuration.xmlconfig
>>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)

No such instance: raises an error.

>>> import tempfile
>>> fn = tempfile.mktemp('.zcml')
>>> zcml = open(fn, 'w')
>>> zcml.write('''
... <configure xmlns:meta="http://namespaces.zope.org/meta"
...            xmlns:five="http://namespaces.zope.org/five">
...     <five:configfeature
...         feature="conf1"
...         instance=".configtest.nosuch"
...         attribute="conf1"
...     />
... </configure>
... ''')
>>> zcml.close()

>>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
ZopeXMLConfigurationError: ...
    ConfigurationError: ...

No such attribute: an error too

>>> fn = tempfile.mktemp('.zcml')
>>> zcml = open(fn, 'w')
>>> zcml.write('''
... <configure xmlns:meta="http://namespaces.zope.org/meta"
...            xmlns:five="http://namespaces.zope.org/five">
...     <five:configfeature
...         feature="conf1"
...         instance=".configtest.cobj"
...         attribute="nosuch"
...     />
... </configure>
... ''')
>>> zcml.close()

>>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
ZopeXMLConfigurationError: ...
    ConfigurationError: Object ... does not have attribute or key "nosuch"

No such key: an error too 

>>> fn = tempfile.mktemp('.zcml')
>>> zcml = open(fn, 'w')
>>> zcml.write('''
... <configure xmlns:meta="http://namespaces.zope.org/meta"
...            xmlns:five="http://namespaces.zope.org/five">
...     <five:configfeature
...         feature="conf1"
...         instance=".configtest.dobj"
...         attribute="nosuch"
...     />
... </configure>
... ''')
>>> zcml.close()

>>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
ZopeXMLConfigurationError: ...
    ConfigurationError: Object ... does not have attribute or key "nosuch"

Definition at line 146 of file test_directive.py.

00146 
00147 def test_errors():
00148     """
00149     Testing errors.
00150 
00151     >>> import zope.configuration.tests
00152     >>> import zope.configuration.xmlconfig
00153     >>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)
00154 
00155     No such instance: raises an error.
00156 
00157     >>> import tempfile
00158     >>> fn = tempfile.mktemp('.zcml')
00159     >>> zcml = open(fn, 'w')
00160     >>> zcml.write('''
00161     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00162     ...            xmlns:five="http://namespaces.zope.org/five">
00163     ...     <five:configfeature
00164     ...         feature="conf1"
00165     ...         instance=".configtest.nosuch"
00166     ...         attribute="conf1"
00167     ...     />
00168     ... </configure>
00169     ... ''')
00170     >>> zcml.close()
00171 
00172     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context) #doctest: +ELLIPSIS
00173     Traceback (most recent call last):
00174     ...
00175     ZopeXMLConfigurationError: ...
00176         ConfigurationError: ...
00177 
00178     No such attribute: an error too
00179 
00180     >>> fn = tempfile.mktemp('.zcml')
00181     >>> zcml = open(fn, 'w')
00182     >>> zcml.write('''
00183     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00184     ...            xmlns:five="http://namespaces.zope.org/five">
00185     ...     <five:configfeature
00186     ...         feature="conf1"
00187     ...         instance=".configtest.cobj"
00188     ...         attribute="nosuch"
00189     ...     />
00190     ... </configure>
00191     ... ''')
00192     >>> zcml.close()
00193 
00194     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context) #doctest: +ELLIPSIS
00195     Traceback (most recent call last):
00196     ...
00197     ZopeXMLConfigurationError: ...
00198         ConfigurationError: Object ... does not have attribute or key "nosuch"
00199 
00200     No such key: an error too 
00201 
00202     >>> fn = tempfile.mktemp('.zcml')
00203     >>> zcml = open(fn, 'w')
00204     >>> zcml.write('''
00205     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00206     ...            xmlns:five="http://namespaces.zope.org/five">
00207     ...     <five:configfeature
00208     ...         feature="conf1"
00209     ...         instance=".configtest.dobj"
00210     ...         attribute="nosuch"
00211     ...     />
00212     ... </configure>
00213     ... ''')
00214     >>> zcml.close()
00215 
00216     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context) #doctest: +ELLIPSIS
00217     Traceback (most recent call last):
00218     ...
00219     ZopeXMLConfigurationError: ...
00220         ConfigurationError: Object ... does not have attribute or key "nosuch"
00221     
00222     """
00223 

Module level access.

>>> import zope.configuration.tests
>>> import zope.configuration.xmlconfig
>>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)

>>> import tempfile
>>> fn = tempfile.mktemp('.zcml')
>>> zcml = open(fn, 'w')
>>> zcml.write('''
... <configure xmlns:meta="http://namespaces.zope.org/meta"
...            xmlns:five="http://namespaces.zope.org/five">
...     <five:configfeature
...         feature="conf1"
...         instance=".configtest"
...         attribute="conf1"
...     />
...     <five:configfeature
...         feature="conf2"
...         instance=".configtest"
...         attribute="conf2"
...     />
...     <five:configfeature
...         feature="conf2n"
...         instance=".configtest"
...         attribute="conf2"
...         negate="True"
...     />
... </configure>
... ''')
>>> zcml.close()

>>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context)

>>> context.hasFeature('conf1')
True
>>> context.hasFeature('conf2')
False
>>> context.hasFeature('conf2n')
True

Definition at line 8 of file test_directive.py.

00008 
00009 def test_module_level():
00010     """
00011     Module level access.
00012 
00013     >>> import zope.configuration.tests
00014     >>> import zope.configuration.xmlconfig
00015     >>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)
00016 
00017     >>> import tempfile
00018     >>> fn = tempfile.mktemp('.zcml')
00019     >>> zcml = open(fn, 'w')
00020     >>> zcml.write('''
00021     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00022     ...            xmlns:five="http://namespaces.zope.org/five">
00023     ...     <five:configfeature
00024     ...         feature="conf1"
00025     ...         instance=".configtest"
00026     ...         attribute="conf1"
00027     ...     />
00028     ...     <five:configfeature
00029     ...         feature="conf2"
00030     ...         instance=".configtest"
00031     ...         attribute="conf2"
00032     ...     />
00033     ...     <five:configfeature
00034     ...         feature="conf2n"
00035     ...         instance=".configtest"
00036     ...         attribute="conf2"
00037     ...         negate="True"
00038     ...     />
00039     ... </configure>
00040     ... ''')
00041     >>> zcml.close()
00042 
00043     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context)
00044 
00045     >>> context.hasFeature('conf1')
00046     True
00047     >>> context.hasFeature('conf2')
00048     False
00049     >>> context.hasFeature('conf2n')
00050     True
00051 
00052     """
00053 

Object level access.

>>> import zope.configuration.tests
>>> import zope.configuration.xmlconfig
>>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)

>>> import tempfile
>>> fn = tempfile.mktemp('.zcml')
>>> zcml = open(fn, 'w')
>>> zcml.write('''
... <configure xmlns:meta="http://namespaces.zope.org/meta"
...            xmlns:five="http://namespaces.zope.org/five">
...     <five:configfeature
...         feature="conf3"
...         instance=".configtest.cobj"
...         attribute="conf3"
...     />
...     <five:configfeature
...         feature="conf4"
...         instance=".configtest.cobj"
...         attribute="conf4"
...     />
...     <five:configfeature
...         feature="conf4n"
...         instance=".configtest.cobj"
...         attribute="conf4"
...         negate="True"
...     />
... </configure>
... ''')
>>> zcml.close()

>>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context)

>>> context.hasFeature('conf3')
True
>>> context.hasFeature('conf4')
False
>>> context.hasFeature('conf4n')
True

Definition at line 54 of file test_directive.py.

00054 
00055 def test_objectlevel():
00056     """
00057     Object level access.
00058 
00059     >>> import zope.configuration.tests
00060     >>> import zope.configuration.xmlconfig
00061     >>> context = zope.configuration.xmlconfig.file('metacore.zcml', configfeature)
00062 
00063     >>> import tempfile
00064     >>> fn = tempfile.mktemp('.zcml')
00065     >>> zcml = open(fn, 'w')
00066     >>> zcml.write('''
00067     ... <configure xmlns:meta="http://namespaces.zope.org/meta"
00068     ...            xmlns:five="http://namespaces.zope.org/five">
00069     ...     <five:configfeature
00070     ...         feature="conf3"
00071     ...         instance=".configtest.cobj"
00072     ...         attribute="conf3"
00073     ...     />
00074     ...     <five:configfeature
00075     ...         feature="conf4"
00076     ...         instance=".configtest.cobj"
00077     ...         attribute="conf4"
00078     ...     />
00079     ...     <five:configfeature
00080     ...         feature="conf4n"
00081     ...         instance=".configtest.cobj"
00082     ...         attribute="conf4"
00083     ...         negate="True"
00084     ...     />
00085     ... </configure>
00086     ... ''')
00087     >>> zcml.close()
00088 
00089     >>> context = zope.configuration.xmlconfig.file(fn, configfeature.tests, context)
00090 
00091     >>> context.hasFeature('conf3')
00092     True
00093     >>> context.hasFeature('conf4')
00094     False
00095     >>> context.hasFeature('conf4n')
00096     True
00097 
00098     """
00099 

Definition at line 224 of file test_directive.py.

00224 
00225 def test_suite():
00226     return unittest.TestSuite((
00227         DocTestSuite(configfeature.__name__ + '.meta'),
00228         DocTestSuite(),
00229         ))

Variable Documentation

Definition at line 6 of file test_directive.py.