[Zope-CVS] CVS: Products/Zelenium - CHANGES.txt:1.29 README.txt:1.8 zuite.py:1.18

Tres Seaver tseaver at palladion.com
Mon May 9 14:50:59 EDT 2005


Update of /cvs-repository/Products/Zelenium
In directory cvs.zope.org:/tmp/cvs-serv25227

Modified Files:
	CHANGES.txt README.txt zuite.py 
Log Message:
 - Add support for ordering / globbing test cases / subdirs.


=== Products/Zelenium/CHANGES.txt 1.28 => 1.29 ===
--- Products/Zelenium/CHANGES.txt:1.28	Sat May  7 16:33:25 2005
+++ Products/Zelenium/CHANGES.txt	Mon May  9 14:50:28 2005
@@ -6,12 +6,6 @@
       including recursion through subdirectories of that path.  Currently,
       the implementation has the following issues:
 
-      o It doesn't provide control over the order in which test cases or
-        subdirectories are returned.
-
-      o It doesn't allow exclusion / filtering of subdirectories or
-        test cases.
-
       o It only creates OFS.Image.File objects for test cases (no templates,
         scripts, etc.)
 


=== Products/Zelenium/README.txt 1.7 => 1.8 ===
--- Products/Zelenium/README.txt:1.7	Sat May  7 16:38:07 2005
+++ Products/Zelenium/README.txt	Mon May  9 14:50:28 2005
@@ -67,6 +67,24 @@
     suite will recursively load testcases from files in / under the
     directory pointed to by that path.
 
+    The list of files to be included is computed via the following
+    rules:
+
+     - If the directory contains a file, '.objects', it is presumed to
+       contain a list of files to be included, one per line;  only those
+       files / subdirectories (if present) will be included.  In this case,
+       the test cases will be presented in the order indicated in the file,
+       followed by any test cases from subdirectories.
+
+     - Otherwise, if the suite's property, 'filename_glob' is non-empty,
+       it will be expanded (via Python's 'glob.glob') to compute the list
+       of filenames.  The test cases will be presented in alphabetical
+       order, followed by any test cases from subdirectories.
+
+     - Otherwise, any file will be considered a testcase.  The test cases
+       will be presented in alphabetical order, followed by any test cases
+       from subdirectories.
+
   Exporting an Archive
 
     On the "Zip" tab, supply a filename and click the "Download" button.


=== Products/Zelenium/zuite.py 1.17 => 1.18 ===
--- Products/Zelenium/zuite.py:1.17	Sat May  7 16:33:25 2005
+++ Products/Zelenium/zuite.py	Mon May  9 14:50:28 2005
@@ -4,6 +4,7 @@
 
 $Id$
 """
+import glob
 import os
 import re
 from urllib import unquote
@@ -29,7 +30,7 @@
 
 _PINK_BACKGROUND = re.compile('bgcolor="#ffcfcf"')
 
-_EXCLUDE_NAMES = ( 'CVS', '.svn' )
+_EXCLUDE_NAMES = ( 'CVS', '.svn', '.objects' )
 
 def _getNow():
     if _NOW is not None:
@@ -60,11 +61,19 @@
                       , 'selenium-logo.png'
                       ]
 
-def _makeFile(filename):
-    path = os.path.join(_SUPPORT_DIR, filename)
-    return File(id=filename, title='', file=open(path).read())
+def _makeFile(filename, prefix=None, id=None):
 
-_SUPPORT_FILES = dict( [ ( x, _makeFile(x) )
+    if prefix:
+        path = os.path.join( prefix, filename )
+    else:
+        path = filename
+
+    if id is None:
+        id = os.path.split( path )[ 1 ]
+
+    return File( id=id, title='', file=open(path).read() )
+
+_SUPPORT_FILES = dict( [ ( x, _makeFile( x, prefix=_SUPPORT_DIR ) )
                             for x in _SUPPORT_FILE_NAMES ] )
 
 _MARKER = object()
@@ -89,6 +98,7 @@
                           , 'Page Template'
                           )
     filesystem_path = ''
+    filename_glob = ''
     _v_filesystem_objects = None
 
     _properties = ( { 'id' : 'test_case_metatypes'
@@ -99,6 +109,10 @@
                     , 'type' : 'string'
                     , 'mode' : 'w'
                     }
+                  , { 'id' : 'filename_glob'
+                    , 'type' : 'string'
+                    , 'mode' : 'w'
+                    }
                   )
 
     security = ClassSecurityInfo()
@@ -170,20 +184,29 @@
     security.declarePrivate( '_recurseFSTestCases' )
     def _recurseFSTestCases( self, result, prefix, fsobjs ):
 
-        for tcid, test_case in fsobjs.get( 'testcases', {} ).items():
-            path = '/'.join( prefix + ( tcid, ) )
-            result.append( { 'id' : tcid
-                            , 'title' : test_case.title_or_id()
-                            , 'url' : path
-                            , 'path' : path
-                            , 'test_case' : test_case
-                            } )
-
-        for name, info in fsobjs.get( 'subdirs', {} ).items():
-            self._recurseFSTestCases( result
-                                    , prefix + ( name, )
-                                    , info
-                                    )
+        test_cases = dict( [ ( x.getId(), x )
+                                for x in fsobjs.get( 'testcases', () ) ] )
+        subdirs = fsobjs.get( 'subdirs', {} )
+
+        for name in fsobjs.get( 'ordered', [] ):
+
+            if name in test_cases:
+                test_case = test_cases[ name ]
+                name = test_case.getId()
+                path = '/'.join( prefix + ( name, ) )
+                result.append( { 'id' : name
+                               , 'title' : test_case.title_or_id()
+                               , 'url' : path
+                               , 'path' : path
+                               , 'test_case' : test_case
+                               } )
+
+            if name in subdirs:
+                info = subdirs[ name ]
+                self._recurseFSTestCases( result
+                                        , prefix + ( name, )
+                                        , info
+                                        )
 
 
     security.declareProtected(ManageSeleniumTestCases, 'getZipFileName')
@@ -367,18 +390,32 @@
     security.declarePrivate('_grubFilesystem')
     def _grubFilesystem( self, path ):
 
-        info = { 'testcases' : {}, 'subdirs' : {} }
+        info = { 'testcases' : (), 'subdirs' : {} }
+
+        # Look for a '.objects' file with an explicit manifiest
+        manifest = os.path.join( path, '.objects' )
 
-        for name in os.listdir( path ):
+        if os.path.isfile( manifest ):
+            filenames = [ x.strip() for x in open( manifest ).readlines() ]
 
-            if name in _EXCLUDE_NAMES:
-                continue
+        elif self.filename_glob:
+            globbed = glob.glob( os.path.join( path, self.filename_glob ) )
+            filenames = [ os.path.split( x )[ 1 ] for x in globbed ]
+
+        else:   # guess
+            filenames = [ x for x in os.listdir( path )
+                                if x not in _EXCLUDE_NAMES ]
+            filenames.sort()
+
+        info[ 'ordered' ] = filenames
+
+        for name in filenames:
 
             fqfn = os.path.join( path, name )
 
             if os.path.isfile( fqfn ):
                 testcase = _makeFile( fqfn )
-                info[ 'testcases' ][ name ] = testcase.__of__( self )
+                info[ 'testcases' ] += ( testcase, )
 
             elif os.path.isdir( fqfn ):
                 info[ 'subdirs' ][ name ] = self._grubFilesystem( fqfn )
@@ -408,17 +445,45 @@
 
         test_cases = self.listTestCases()
 
-        # ensure suffixes
+        paths = { '' : [] }
+
+        def _ensurePath( prefix, element ):
+            elements = paths.setdefault( prefix, [] )
+            if element not in elements:
+                elements.append( element )
+
         for info in test_cases:
-            info[ 'path' ] = self._getFilename( info[ 'path' ] )
+            # ensure suffixes
+            path = self._getFilename( info[ 'path' ] )
+            info[ 'path' ] = path
             info[ 'url' ] = self._getFilename( info[ 'url' ] )
 
+        for info in test_cases:
+            #parent, filename = os.path.split( info[ 'path' ] )
+            #paths.setdefault( parent, [] ).append( filename )
+            elements = info[ 'path' ].split( os.path.sep )
+            _ensurePath( '', elements[ 0 ] )
+            for i in range( 1, len( elements ) ):
+                prefix = '/'.join( elements[ : i ] )
+                _ensurePath( prefix, elements[ i ] )
+
         archive.writestr( 'testSuite.html'
                         , self.test_suite_html( test_cases=test_cases ) )
 
         for k, v in _SUPPORT_FILES.items():
             archive.writestr( k, v.manage_FTPget() )
 
+        for pathname, filenames in paths.items():
+
+            if pathname == '':
+                filename = '.objects'
+            else:
+                filename = '%s/.objects' % pathname
+
+            archive.writestr( filename
+                            , '\n'.join( filenames )
+                            )
+
         for info in test_cases:
             test_case = info[ 'test_case' ]
 
@@ -558,8 +623,9 @@
     security.declareProtected( View, 'get' )
     def get( self, key, default=_MARKER ):
 
-        if key in self._fsobjs[ 'testcases' ]:
-            return self._fsobjs[ 'testcases' ][ key ].__of__( self )
+        for tc in self._fsobjs[ 'testcases' ]:
+            if tc.getId() == key:
+                return tc.__of__( self )
 
         if key in self._fsobjs[ 'subdirs' ]:
             return self.__class__( self._fsobjs[ 'subdirs' ][ key ]



More information about the Zope-CVS mailing list