Back to index

plone3  3.1.7
Classes | Functions | Variables
PluginRegistry.utils Namespace Reference

Classes

class  TestFileFinder

Functions

def directlyProvides
def remove_stale_bytecode
def find_unit_test_files
def module_name_from_path
def get_suite
def allTests

Variables

tuple product_dir = package_home( globals() )
tuple product_prefix = os.path.join( os.path.split(product_dir)[:-1] )
tuple _wwwdir = os.path.join( product_dir, 'www' )

Function Documentation

def PluginRegistry.utils.allTests (   from_dir = product_dir,
  test_prefix = 'test' 
)
    Walk the product and build a unittest.TestSuite aggregating tests.

Definition at line 124 of file utils.py.

00124 
00125 def allTests( from_dir=product_dir, test_prefix='test' ):
00126     """
00127         Walk the product and build a unittest.TestSuite aggregating tests.
00128     """
00129     os.path.walk( from_dir, remove_stale_bytecode, None )
00130     test_files = find_unit_test_files( from_dir, test_prefix )
00131     test_files.sort()
00132 
00133     suite = unittest.TestSuite()
00134 
00135     for test_file in test_files:
00136 
00137         s = get_suite( test_file )
00138         if s is not None:
00139             suite.addTest( s )
00140 
00141     return suite

Here is the call graph for this function:

def PluginRegistry.utils.directlyProvides (   obj,
  interfaces 
)

Definition at line 23 of file utils.py.

00023 
00024     def directlyProvides(obj, *interfaces):
00025         obj.__implements__ = ( getattr( obj.__class__, '__implements__', () ) +
00026                                tuple( interfaces )
00027                              )

def PluginRegistry.utils.find_unit_test_files (   from_dir = product_dir,
  test_prefix = 'test' 
)
    Walk the product, return a list of all unittest files.

Definition at line 86 of file utils.py.

00086 
00087 def find_unit_test_files( from_dir=product_dir, test_prefix='test' ):
00088     """
00089         Walk the product, return a list of all unittest files.
00090     """
00091     finder = TestFileFinder()
00092     os.path.walk( from_dir, finder.visit, test_prefix )
00093     return finder.files

Here is the caller graph for this function:

    Retrieve a TestSuite from 'file'.

Definition at line 107 of file utils.py.

00107 
00108 def get_suite( file ):
00109     """
00110         Retrieve a TestSuite from 'file'.
00111     """
00112     module_name = module_name_from_path( file )
00113     loader = unittest.defaultTestLoader
00114     try:
00115         suite = loader.loadTestsFromName( '%s.test_suite' % module_name )
00116     except AttributeError:
00117 
00118         try:
00119             suite = loader.loadTestsFromName(  module_name )
00120         except ImportError, err:
00121             print "Error importing %s\n%s" % (module_name, err)
00122             raise
00123     return suite

Here is the call graph for this function:

Here is the caller graph for this function:

    Return the dotted module name matching the filesystem path.

Definition at line 94 of file utils.py.

00094 
00095 def module_name_from_path( path ):
00096     """
00097         Return the dotted module name matching the filesystem path.
00098     """
00099     assert path.endswith( '.py' )
00100     path = path[:-3]
00101     path = path[ len(product_prefix) + 1: ] # strip extraneous crap
00102     dirs = []
00103     while path:
00104         path, end = os.path.split( path )
00105         dirs.insert( 0, end )
00106     return ".".join( dirs )

Here is the caller graph for this function:

def PluginRegistry.utils.remove_stale_bytecode (   arg,
  dirname,
  names 
)
    Troll product, removing compiled turds whose source is now gone.

Definition at line 36 of file utils.py.

00036 
00037 def remove_stale_bytecode( arg, dirname, names ):
00038     """
00039         Troll product, removing compiled turds whose source is now gone.
00040     """
00041     names = map( os.path.normcase, names )
00042 
00043     for name in names:
00044 
00045         if name.endswith( ".pyc" ) or name.endswith( ".pyo" ):
00046 
00047             srcname = name[:-1]
00048 
00049             if srcname not in names:
00050 
00051                 fullname = os.path.join( dirname, name )
00052 
00053                 if __debug__:
00054                     print "Removing stale bytecode file", fullname
00055 
00056                 os.unlink( fullname )


Variable Documentation

tuple PluginRegistry.utils._wwwdir = os.path.join( product_dir, 'www' )

Definition at line 31 of file utils.py.

tuple PluginRegistry.utils.product_dir = package_home( globals() )

Definition at line 28 of file utils.py.

tuple PluginRegistry.utils.product_prefix = os.path.join( os.path.split(product_dir)[:-1] )

Definition at line 29 of file utils.py.