Back to index

plone3  3.1.7
layer.py
Go to the documentation of this file.
00001 #
00002 # Layer support
00003 #
00004 
00005 # $Id: layer.py 49924 2007-09-22 21:57:20Z shh42 $
00006 
00007 import five
00008 
00009 _deferred_setup = []
00010 _deferred_cleanup = []
00011 
00012 
00013 class ZCML:
00014 
00015     def setUp(cls):
00016         '''Sets up the CA by loading etc/site.zcml.'''
00017         five.safe_load_site()
00018     setUp = classmethod(setUp)
00019 
00020     def tearDown(cls):
00021         '''Cleans up the CA.'''
00022         five.cleanUp()
00023     tearDown = classmethod(tearDown)
00024 
00025 ZCMLLayer = ZCML
00026 
00027 
00028 class PloneSite(ZCML):
00029 
00030     def setUp(cls):
00031         '''Sets up the Plone site(s).'''
00032         for func, args, kw in _deferred_setup:
00033             func(*args, **kw)
00034     setUp = classmethod(setUp)
00035 
00036     def tearDown(cls):
00037         '''Removes the Plone site(s).'''
00038         for func, args, kw in _deferred_cleanup:
00039             func(*args, **kw)
00040     tearDown = classmethod(tearDown)
00041 
00042 PloneSiteLayer = PloneSite
00043 
00044 
00045 def onsetup(func):
00046     '''Defers a function call to PloneSite layer setup.
00047        Used as a decorator.
00048     '''
00049     def deferred_func(*args, **kw):
00050         _deferred_setup.append((func, args, kw))
00051     return deferred_func
00052 
00053 
00054 def onteardown(func):
00055     '''Defers a function call to PloneSite layer tear down.
00056        Used as a decorator.
00057     '''
00058     def deferred_func(*args, **kw):
00059         _deferred_cleanup.append((func, args, kw))
00060     return deferred_func
00061 
00062 
00063 # Derive from ZopeLite layer if available
00064 try:
00065     from Testing.ZopeTestCase.layer import ZopeLite
00066 except ImportError:
00067     pass
00068 else:
00069     ZCML.__bases__ = (ZopeLite,)
00070