[Zope3-checkins] CVS: Zope3 - ftesting.zcml:1.1 test.py:1.55

Marius Gedminas mgedmin@codeworks.lt
Mon, 14 Apr 2003 08:19:58 -0400


Update of /cvs-repository/Zope3
In directory cvs.zope.org:/tmp/cvs-serv8524

Modified Files:
	test.py 
Added Files:
	ftesting.zcml 
Log Message:
Functional testing framework for Zope 3:
- based on http://dev.zope.org/Zope3/FunctionalTestingFramework
- doc/FTEST.txt contains a short description of the framework
- test.py -f runs functional tests
- ftesting.zcml is the equivalent of site.zcml for functional tests
  (it hardcodes some principals with simple passwords; wouldn't want to do
  that in the real site.zcml)
- src/zope/app/content/ftests/test_file.py is an example functional test



=== Added File Zope3/ftesting.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>

<!-- This file is the equivalent of site.zcml used for functional testing -->

<include package="zope.configuration" file="metameta.zcml" />
<include package="zope.app" />

<role id="Manager" title="Site Manager" />
<role id="Member" title="Site Member" />

<!-- Remove the following directive if you don't want public access -->
<grant permission="zope.View" role="Anonymous" />

<grant permission="zope.View"              role="Manager" />
<grant permission="zope.ManageContent"     role="Manager" />
<grant permission="zope.Security"          role="Manager" />
<grant permission="zope.ManageCode"        role="Manager" />
<grant permission="zope.ManageServices"    role="Manager" />
<grant permission="zope.ManageApplication" role="Manager" />
<grant permission="zope.ManageBindings"    role="Manager" />

<include file="products.zcml" />

<!-- Principals -->

<unauthenticatedPrincipal id="anybody"
                          title="Unauthenticated User" />

<principal id='mgr'
           title="Manager"
           login='mgr'
           password='mgrpw' />

<grant role="Manager" principal="mgr" />

</zopeConfigure>


=== Zope3/test.py 1.54 => 1.55 ===
--- Zope3/test.py:1.54	Fri Apr 11 08:27:09 2003
+++ Zope3/test.py	Mon Apr 14 08:19:27 2003
@@ -13,7 +13,7 @@
 #
 ##############################################################################
 """
-test.py [-aBbcdDgGhLmprtTuv] [modfilter [testfilter]]
+test.py [-aBbcdDfgGhLmprtTuv] [modfilter [testfilter]]
 
 Test harness.
 
@@ -45,6 +45,9 @@
 -D
     Works like -d, except that it loads pdb when an exception occurs.
 
+-f
+    Run functional tests instead of unit tests.
+
 -g threshold
     Set the garbage collector generation0 threshold.  This can be used to
     stress memory and gc correctness.  Some crashes are only reproducible when
@@ -325,13 +328,24 @@
         self.cwd = os.getcwd()
         sys.path.insert(0, os.path.join(self.cwd, self.libdir))
         # Hack again for external products.
+        global functional
+        kind = functional and "functional" or "unit"
         if libdir:
             extra = os.path.join(org_cwd, libdir)
-            print "Running tests from", extra
+            print "Running %s tests from %s" % (kind, extra)
             self.libdir = extra
             sys.path.insert(0, extra)
         else:
-            print "Running tests from", self.cwd
+            print "Running %s tests from %s" % (kind, self.cwd)
+        # Make sure functional tests find ftesting.zcml
+        if functional:
+            config_file = 'ftesting.zcml'
+            if not self.inplace:
+                # We chdired into build, so ftesting.zcml is in the parent directory
+                config_file = os.path.join('..', 'ftesting.zcml')
+            print "Parsing %s" % config_file
+            from zope.testing.functional import FunctionalTestSetup
+            FunctionalTestSetup(config_file)
 
 def match(rx, s):
     if not rx:
@@ -346,9 +360,14 @@
         self.files = []
         # XXX will break if prefix ends with a slash
         self._plen = len(prefix)+1
+        global functional
+        if functional:
+            self.dirname = "ftests"
+        else:
+            self.dirname = "tests"
 
     def visit(self, rx, dir, files):
-        if dir[-5:] != "tests":
+        if os.path.split(dir)[1] != self.dirname:
             return
         # ignore tests that aren't in packages
         if not "__init__.py" in files:
@@ -432,7 +451,7 @@
     if build_inplace:
         utildir = os.path.join(os.getcwd(), "utilities")
     else:
-        utildir = os.path.join(os.getcwd(), "../utilities")
+        utildir = os.path.join(os.getcwd(), "..", "utilities")
     sys.path.append(utildir)
     import unittestgui
     suites = []
@@ -578,6 +597,7 @@
     global timetests
     global progress
     global build_inplace
+    global functional
 
     if argv is None:
         argv = sys.argv
@@ -601,9 +621,10 @@
     progress = False
     timesfn = None
     timetests = 0
+    functional = False
 
     try:
-        opts, args = getopt.getopt(argv[1:], "a:bBcdDg:G:hLmprtTuv",
+        opts, args = getopt.getopt(argv[1:], "a:bBcdDfg:G:hLmprtTuv",
                                    ["all", "help", "libdir=", "times="])
     except getopt.error, msg:
         print msg
@@ -629,6 +650,8 @@
         elif k == "-D":
             debug = True
             debugger = True
+        elif k == "-f":
+            functional = True
         elif k in ("-h", "--help"):
             print __doc__
             sys.exit(0)
@@ -707,10 +730,11 @@
             sys.exit(1)
 
     if VERBOSE:
+        kind = functional and "functional" or "unit"
         if level == 0:
-            print "Running tests at all levels"
+            print "Running %s tests at all levels" % kind
         else:
-            print "Running tests at level", level
+            print "Running %s tests at level %d" % (kind, level)
 
     if args:
         if len(args) > 1: