[Checkins] SVN: zope.configuration/branches/tseaver-test_cleanup/ Move 'conditionalizing directives' example to narrative docs.

Tres Seaver cvs-admin at zope.org
Tue May 8 01:18:20 UTC 2012


Log message for revision 125712:
  Move 'conditionalizing directives' example to narrative docs.

Changed:
  U   zope.configuration/branches/tseaver-test_cleanup/docs/narr.rst
  U   zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_conditions.py

-=-
Modified: zope.configuration/branches/tseaver-test_cleanup/docs/narr.rst
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/docs/narr.rst	2012-05-08 01:18:12 UTC (rev 125711)
+++ zope.configuration/branches/tseaver-test_cleanup/docs/narr.rst	2012-05-08 01:18:17 UTC (rev 125712)
@@ -77,6 +77,94 @@
 .. todo::
    Flesh out narrative docs.
 
+
+Making specific directives conditional
+======================================
+
+There is a ``condition`` attribute in the
+"http://namespaces.zope.org/zcml" namespace which is honored on all
+elements in ZCML.  The value of the attribute is an expression
+which is used to determine if that element and its descendents are
+used.  If the condition is true, processing continues normally,
+otherwise that element and its descendents are ignored.
+
+Currently the expression is always of the form "have featurename", and it
+checks for the presence of a ``<meta:provides feature="featurename" />``.
+
+Our demonstration uses a trivial registry; each registration consists
+of a simple id inserted in the global `registry` in this module.  We
+can checked that a registration was made by checking whether the id is
+present in `registry`.
+
+.. doctest::
+
+   >>> from zope.configuration.tests.test_conditions import registry
+   >>> registry
+   []
+
+We start by loading the example ZCML file, *conditions.zcml*:
+
+.. doctest::
+
+  >>> import zope.configuration.tests
+  >>> from zope.configuration.xmlconfig import file
+  >>> context = file("conditions.zcml", zope.configuration.tests)
+
+To show that our sample directive works, we see that the unqualified
+registration was successful:
+
+.. doctest::
+
+  >>> "unqualified.registration" in registry
+  True
+
+When the expression specified with ``zcml:condition`` evaluates to
+true, the element it is attached to and all contained elements (not
+otherwise conditioned) should be processed normally:
+
+.. doctest::
+
+  >>> "direct.true.condition" in registry
+  True
+  >>> "nested.true.condition" in registry
+  True
+
+However, when the expression evaluates to false, the conditioned
+element and all contained elements should be ignored:
+
+.. doctest::
+
+  >>> "direct.false.condition" in registry
+  False
+  >>> "nested.false.condition" in registry
+  False
+
+Conditions on container elements affect the conditions in nested
+elements in a reasonable way.  If an "outer" condition is true, nested
+conditions are processed normally:
+
+.. doctest::
+
+  >>> "true.condition.nested.in.true" in registry
+  True
+  >>> "false.condition.nested.in.true" in registry
+  False
+
+If the outer condition is false, inner conditions are not even
+evaluated, and the nested elements are ignored:
+
+.. doctest::
+
+  >>> "true.condition.nested.in.false" in registry
+  False
+  >>> "false.condition.nested.in.false" in registry
+  False
+
+.. testcleanup::
+
+  del registry[:]
+
+
 Filtering and Inhibiting Configuration
 ======================================
 

Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_conditions.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_conditions.py	2012-05-08 01:18:12 UTC (rev 125711)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_conditions.py	2012-05-08 01:18:17 UTC (rev 125712)
@@ -11,87 +11,18 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-r'''How to conditionalize specific directives
+""" Enable "Making specific directives condition" section of narrative docs.
+"""
+import unittest
 
-There is a "condition" attribute in the
-"http://namespaces.zope.org/zcml" namespace which is honored on all
-elements in ZCML.  The value of the attribute is an expression
-which is used to determine if that element and its descendents are
-used.  If the condition is true, processing continues normally,
-otherwise that element and its descendents are ignored.
+from zope.interface import Interface
+from zope.schema import Id
 
-Currently the expression is always of the form "have featurename", and it
-checks for the presence of a <meta:provides feature="featurename" />.
 
-Our demonstration uses a trivial registry; each registration consists
-of a simple id inserted in the global `registry` in this module.  We
-can checked that a registration was made by checking whether the id is
-present in `registry`.
-
-We start by loading the example ZCML file, *conditions.zcml*::
-
-  >>> import zope.configuration.tests
-  >>> import zope.configuration.xmlconfig
-
-  >>> context = zope.configuration.xmlconfig.file("conditions.zcml",
-  ...                                             zope.configuration.tests)
-
-To show that our sample directive works, we see that the unqualified
-registration was successful::
-
-  >>> "unqualified.registration" in registry
-  True
-
-When the expression specified with ``zcml:condition`` evaluates to
-true, the element it is attached to and all contained elements (not
-otherwise conditioned) should be processed normally::
-
-  >>> "direct.true.condition" in registry
-  True
-  >>> "nested.true.condition" in registry
-  True
-
-However, when the expression evaluates to false, the conditioned
-element and all contained elements should be ignored::
-
-  >>> "direct.false.condition" in registry
-  False
-  >>> "nested.false.condition" in registry
-  False
-
-Conditions on container elements affect the conditions in nested
-elements in a reasonable way.  If an "outer" condition is true, nested
-conditions are processed normally::
-
-  >>> "true.condition.nested.in.true" in registry
-  True
-  >>> "false.condition.nested.in.true" in registry
-  False
-
-If the outer condition is false, inner conditions are not even
-evaluated, and the nested elements are ignored::
-
-  >>> "true.condition.nested.in.false" in registry
-  False
-  >>> "false.condition.nested.in.false" in registry
-  False
-
-Now we need to clean up after ourselves::
-
-  >>> del registry[:]
-
-'''
-__docformat__ = "reStructuredText"
-
-import doctest
-import zope.interface
-import zope.schema
-
-
-class IRegister(zope.interface.Interface):
+class IRegister(Interface):
     """Trivial sample registry."""
 
-    id = zope.schema.Id(
+    id = Id(
         title=u"Identifier",
         description=u"Some identifier that can be checked.",
         required=True,
@@ -106,4 +37,5 @@
                    )
 
 def test_suite():
-    return doctest.DocTestSuite()
+    # dead chicken for the test finder
+    return unittest.TestSuite()



More information about the checkins mailing list