[Checkins] SVN: grok/branches/philikon-grokking-tests/src/grok/ Use the test grokking functionality for functional tests as well:

Philipp von Weitershausen philikon at philikon.de
Wed Mar 28 04:22:48 EDT 2007


Log message for revision 73822:
  Use the test grokking functionality for functional tests as well:
  
  * Lots of test-searching code gets removed, woohoo!
  
  * A big copy-n-paste for FunctionalDocTestSuite gets removed, woohoo! (The same thing
    can be accomplished using a standard DocTestSuite with some extraglobs and the right
    setUp, tearDown pair).
  
  * Give grok its own ftesting.zcml that's taylored to its ftest needs and independent
    of what a particular instance might have in etc/ftesting.zcml.  Also, since it loads
    less than Zope 3's standard ftesting.zcml, it's about 0.3 secs faster on my machine ;).
  
  * grok.testing.GrokFunctionalLayer is an ftest layer that grok-based projects can use
    for ftests
  

Changed:
  A   grok/branches/philikon-grokking-tests/src/grok/ftesting.zcml
  U   grok/branches/philikon-grokking-tests/src/grok/ftests/test_grok_functional.py
  U   grok/branches/philikon-grokking-tests/src/grok/testing.py

-=-
Added: grok/branches/philikon-grokking-tests/src/grok/ftesting.zcml
===================================================================
--- grok/branches/philikon-grokking-tests/src/grok/ftesting.zcml	2007-03-28 08:17:53 UTC (rev 73821)
+++ grok/branches/philikon-grokking-tests/src/grok/ftesting.zcml	2007-03-28 08:22:48 UTC (rev 73822)
@@ -0,0 +1,52 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   i18n_domain="grok"
+   package="grok"
+   >
+
+  <include package="zope.i18n" file="meta.zcml" />
+  <include package="zope.security" file="meta.zcml" />
+  <include package="zope.app" file="meta.zcml" />
+  <include package="zope.app.securitypolicy" file="meta.zcml" />
+  <include package="grok" file="meta.zcml" />
+
+  <include package="zope.annotation" />
+  <include package="zope.copypastemove" />
+  <include package="zope.formlib" />
+  <include package="zope.i18n.locales" />
+  <include package="zope.publisher" />
+  <include package="zope.traversing" />
+  <include package="zope.traversing.browser" />
+  <include package="zope.app" />
+  <include package="zope.app.authentication" />
+  <include package="zope.app.catalog" />
+  <include package="zope.app.intid" />
+  <include package="zope.app.keyreference" />
+  <include package="grok" />
+
+  <include package="zope.app.securitypolicy" />
+  <securityPolicy
+      component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy"
+      />
+
+  <unauthenticatedPrincipal
+      id="zope.anybody"
+      title="Unauthenticated User"
+      />
+  <grant
+      permission="zope.View"
+      principal="zope.anybody"
+      />
+
+  <principal
+      id="zope.mgr"
+      title="Manager"
+      login="mgr"
+      password="mgrpw"
+      />
+
+  <role id="zope.Manager" title="Site Manager" />
+  <grantAll role="zope.Manager" />
+  <grant role="zope.Manager" principal="zope.mgr" />
+
+</configure>


Property changes on: grok/branches/philikon-grokking-tests/src/grok/ftesting.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: grok/branches/philikon-grokking-tests/src/grok/ftests/test_grok_functional.py
===================================================================
--- grok/branches/philikon-grokking-tests/src/grok/ftests/test_grok_functional.py	2007-03-28 08:17:53 UTC (rev 73821)
+++ grok/branches/philikon-grokking-tests/src/grok/ftests/test_grok_functional.py	2007-03-28 08:22:48 UTC (rev 73822)
@@ -1,66 +1,29 @@
+import os
 import unittest
-from pkg_resources import resource_listdir
 from zope.testing import doctest
 from zope.app.testing.functional import (HTTPCaller, getRootFolder,
-                                         FunctionalTestSetup, sync, Functional)
+                                         FunctionalTestSetup, sync)
+from grok.testing import grok_tests, GrokFunctionalLayer
 
-# XXX bastardized from zope.app.testing.functional.FunctionalDocFileSuite :-(
-def FunctionalDocTestSuite(*paths, **kw):
-    globs = kw.setdefault('globs', {})
-    globs['http'] = HTTPCaller()
-    globs['getRootFolder'] = getRootFolder
-    globs['sync'] = sync
+def setUp(test):
+    FunctionalTestSetup().setUp()
 
-    #kw['package'] = doctest._normalize_module(kw.get('package'))
+def tearDown(test):
+    FunctionalTestSetup().tearDown()
 
-    kwsetUp = kw.get('setUp')
-    def setUp(test):
-        FunctionalTestSetup().setUp()
-
-        if kwsetUp is not None:
-            kwsetUp(test)
-    kw['setUp'] = setUp
-
-    kwtearDown = kw.get('tearDown')
-    def tearDown(test):
-        if kwtearDown is not None:
-            kwtearDown(test)
-        FunctionalTestSetup().tearDown()
-    kw['tearDown'] = tearDown
-
-    if 'optionflags' not in kw:
-        old = doctest.set_unittest_reportflags(0)
-        doctest.set_unittest_reportflags(old)
-        kw['optionflags'] = (old
-                             | doctest.ELLIPSIS
-                             | doctest.REPORT_NDIFF
-                             | doctest.NORMALIZE_WHITESPACE)
-
-    suite = doctest.DocTestSuite(*paths, **kw)
-    suite.layer = Functional
-    return suite
-
-def suiteFromPackage(name):
-    files = resource_listdir(__name__, name)
-    suite = unittest.TestSuite()
-    for filename in files:
-        if not filename.endswith('.py'):
-            continue
-        if filename == '__init__.py':
-            continue
-
-        dottedname = 'grok.ftests.%s.%s' % (name, filename[:-3])
-        test = FunctionalDocTestSuite(dottedname)
-
-        suite.addTest(test)
-    return suite
-
 def test_suite():
-    suite = unittest.TestSuite()
-    for name in ['view', 'static', 'xmlrpc', 'traversal', 'form', 'url',
-                 'security', 'utility', 'catalog', 'admin']:
-        suite.addTest(suiteFromPackage(name))
-    return suite
+    tests = grok_tests('grok.ftests',
+                       layer=GrokFunctionalLayer,
+                       setUp=setUp,
+                       tearDown=tearDown,
+                       extraglobs=dict(http=HTTPCaller(),
+                                       getRootFolder=getRootFolder,
+                                       sync=sync),
+                       optionflags=(doctest.ELLIPSIS+
+                                    doctest.NORMALIZE_WHITESPACE+
+                                    doctest.REPORT_NDIFF)
+                       )
+    return unittest.TestSuite(tests)
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')

Modified: grok/branches/philikon-grokking-tests/src/grok/testing.py
===================================================================
--- grok/branches/philikon-grokking-tests/src/grok/testing.py	2007-03-28 08:17:53 UTC (rev 73821)
+++ grok/branches/philikon-grokking-tests/src/grok/testing.py	2007-03-28 08:22:48 UTC (rev 73822)
@@ -16,6 +16,7 @@
 """
 import re
 from zope.testing import doctest
+from zope.app.testing.functional import defineLayer
 from grok import util, components, grokker, scan
 
 class DocTestGrokker(components.ModuleGrokker):
@@ -71,3 +72,5 @@
 
     for sub_module_info in module_info.getSubModuleInfos():
         grok_tree(registry, sub_module_info, ignore)
+
+defineLayer('GrokFunctionalLayer', 'ftesting.zcml')



More information about the Checkins mailing list