[Checkins] SVN: z3c.unconfigure/trunk/src/z3c/unconfigure/ More tests

Philipp von Weitershausen philikon at philikon.de
Wed Aug 6 05:17:58 EDT 2008


Log message for revision 89430:
  More tests
  

Changed:
  U   z3c.unconfigure/trunk/src/z3c/unconfigure/README.txt
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/__init__.py
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/lolcat.zcml
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/overrides.zcml
  U   z3c.unconfigure/trunk/src/z3c/unconfigure/testing.py
  U   z3c.unconfigure/trunk/src/z3c/unconfigure/tests.py

-=-
Modified: z3c.unconfigure/trunk/src/z3c/unconfigure/README.txt
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/README.txt	2008-08-06 09:11:15 UTC (rev 89429)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/README.txt	2008-08-06 09:17:57 UTC (rev 89430)
@@ -16,12 +16,12 @@
   >>> zcml("""
   ... <configure>
   ...   <print msg="Hello World!" />
-  ...   <print msg="I can has cheezburger?" />
+  ...   <lolcat who="I" canhas="cheezburger" />
   ...   <print msg="Goodbye World!" />
   ...   <print msg="LOL!" />
   ...
   ...   <unconfigure>
-  ...     <print msg="I can has cheezburger?" />
+  ...     <lolcat who="I" canhas="cheezburger?" />
   ...     <print msg="LOL!" />
   ...   </unconfigure>
   ... </configure>
@@ -39,3 +39,47 @@
   ...   </unconfigure>
   ... </configure>
   ... """)
+
+What's a good place to add the ``unconfigure`` directives, you may
+ask.  Certainly, the example from above is a not very realistic
+because both the original directives and the filters are in one file.
+What typically happens is that you have some third party package that
+has much configuration of which you'd like to disable just one or two
+directives.  Like this file, for instance:
+
+  >>> cat('lolcat.zcml')
+  <configure>
+    <print msg="Hello World!" />
+    <print msg="Important configuration here." />
+    <lolcat who="I" canhas="cheezburger" />
+    <print msg="Goodbye World!" />
+    <print msg="LOL!" />
+    <print msg="This is the last directive" />
+  </configure>
+
+What you can do now is write a separate ZCML file in *your* package.
+A good name for it would be ``overrides.zcml`` (which is the
+convention for overriding ZCML directives, a technique not far from
+what ``unconfigure`` does).  For example:
+
+  >>> cat('overrides.zcml')
+  <unconfigure>
+    <lolcat who="I" canhas="cheezburger" />
+    <print msg="LOL!" />
+  </unconfigure>
+
+What you would do now is include first that third party package's
+configuration and then load your overrides (which is typically done
+using ``includeOverrides``, either explicitly by you or for you by
+``site.zcml``):
+
+  >>> zcml("""
+  ... <configure>
+  ...   <include file="lolcat.zcml" />
+  ...   <includeOverrides file="overrides.zcml" />
+  ... </configure>
+  ... """)
+  Hello World!
+  Important configuration here.
+  Goodbye World!
+  This is the last directive

Added: z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/__init__.py
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/__init__.py	                        (rev 0)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/__init__.py	2008-08-06 09:17:57 UTC (rev 89430)
@@ -0,0 +1,2 @@
+# make this directory a package
+


Property changes on: z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/lolcat.zcml
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/lolcat.zcml	                        (rev 0)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/lolcat.zcml	2008-08-06 09:17:57 UTC (rev 89430)
@@ -0,0 +1,8 @@
+<configure>
+  <print msg="Hello World!" />
+  <print msg="Important configuration here." />
+  <lolcat who="I" canhas="cheezburger" />
+  <print msg="Goodbye World!" />
+  <print msg="LOL!" />
+  <print msg="This is the last directive" />
+</configure>


Property changes on: z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/lolcat.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/overrides.zcml
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/overrides.zcml	                        (rev 0)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/overrides.zcml	2008-08-06 09:17:57 UTC (rev 89430)
@@ -0,0 +1,4 @@
+<unconfigure>
+  <lolcat who="I" canhas="cheezburger" />
+  <print msg="LOL!" />
+</unconfigure>


Property changes on: z3c.unconfigure/trunk/src/z3c/unconfigure/testfixtures/overrides.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: z3c.unconfigure/trunk/src/z3c/unconfigure/testing.py
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/testing.py	2008-08-06 09:11:15 UTC (rev 89429)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/testing.py	2008-08-06 09:17:57 UTC (rev 89430)
@@ -14,7 +14,7 @@
 """Test fixtures
 """
 from zope.interface import Interface
-from zope.schema import Text
+from zope.schema import Text, TextLine
 
 class IPrint(Interface):
     msg = Text(title=u'Message')
@@ -28,3 +28,15 @@
 
 def do_print(msg):
     print msg
+
+
+class ILolCat(Interface):
+    who = TextLine(title=u'Who')
+    canhas = TextLine(title=u'Can has?')
+
+def lolcat(_context, who, canhas):
+    _context.action(
+        discriminator=('lolcat', who,),
+        callable=do_print,
+        args=(who + ' can has ' + canhas + '?',),
+        )

Modified: z3c.unconfigure/trunk/src/z3c/unconfigure/tests.py
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/tests.py	2008-08-06 09:11:15 UTC (rev 89429)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/tests.py	2008-08-06 09:17:57 UTC (rev 89430)
@@ -13,6 +13,7 @@
 ##############################################################################
 """Tests
 """
+import os
 import zope.testing.cleanup
 from zope.testing import doctest
 from zope.configuration import config
@@ -32,14 +33,30 @@
                                    namespace="*",
                                    schema=zopeconfigure.IZopeConfigure,
                                    handler=Unconfigure)
+
+    # Test directives
     config.defineSimpleDirective(
         context, "print", testing.IPrint, testing.print_, namespace="*")
+    config.defineSimpleDirective(
+        context, "lolcat", testing.ILolCat, testing.lolcat, namespace="*")
 
+    source = '''\
+<configure package="z3c.unconfigure.testfixtures">
+%s
+</configure>''' % source
+
     xmlconfig.string(source, context)
 
+def cat(filename):
+    here = os.path.dirname(__file__)
+    filename = os.path.join(here, 'testfixtures', filename)
+    print open(filename).read()
 
 def test_suite():
     return doctest.DocFileSuite('README.txt',
                                 package='z3c.unconfigure',
-                                globs={'zcml': zcml},
-                                tearDown=tearDown)
+                                globs={'zcml': zcml,
+                                       'cat': cat},
+                                tearDown=tearDown,
+                                optionflags=doctest.NORMALIZE_WHITESPACE,
+                                )



More information about the Checkins mailing list