Changeset 7811 for main/waeup.kofa/trunk/src/waeup/kofa/testing.py
- Timestamp:
- 8 Mar 2012, 19:00:51 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/testing.py
r7581 r7811 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 """Testing support for :mod:`waeup. sirp`.18 """Testing support for :mod:`waeup.kofa`. 19 19 """ 20 20 import grok … … 28 28 import warnings 29 29 import zope.component 30 import waeup. sirp30 import waeup.kofa 31 31 from zope.app.testing.functional import ( 32 32 ZCMLLayer, FunctionalTestSetup, getRootFolder, sync, FunctionalTestCase) … … 37 37 38 38 ftesting_zcml = os.path.join( 39 os.path.dirname(waeup. sirp.__file__), 'ftesting.zcml')39 os.path.dirname(waeup.kofa.__file__), 'ftesting.zcml') 40 40 FunctionalLayer = ZCMLLayer(ftesting_zcml, __name__, 'FunctionalLayer', 41 41 allow_teardown=True) … … 45 45 """ 46 46 result = logging.root.manager.loggerDict.keys() 47 ws_loggers = [x for x in result if 'waeup. sirp' in x]47 ws_loggers = [x for x in result if 'waeup.kofa' in x] 48 48 if ws_loggers: 49 49 # For debugging: show any remaining loggers from w.s. namespace … … 93 93 94 94 def maybe_grok(): 95 """Try to grok the :mod:`waeup. sirp` package.95 """Try to grok the :mod:`waeup.kofa` package. 96 96 97 97 For many tests, even simple ones, we want the components defined 98 somewhere in the :mod:`waeup. sirp` package being registered. While98 somewhere in the :mod:`waeup.kofa` package being registered. While 99 99 grokking the complete package can become expensive when done many 100 100 times, we only want to grok if it did not happen … … 105 105 registered and does nothing in that case. 106 106 107 The grokking of :mod:`waeup. sirp` is done with warnings disabled.107 The grokking of :mod:`waeup.kofa` is done with warnings disabled. 108 108 109 109 Returns ``True`` if grokking was done, ``False`` else. … … 122 122 123 123 import unittest2 as unittest # Want Python 2.7 features 124 from waeup. sirp.testing import (124 from waeup.kofa.testing import ( 125 125 maybe_grok, setUpZope, cleanUpZope, 126 126 ) 127 from waeup. sirp.app import University127 from waeup.kofa.app import University 128 128 129 129 class MyTestCase(unittest.TestCase): … … 153 153 Here the component registration is done only once for the whole 154 154 :class:`unittest.TestCase` and no ZODB is needed. That means 155 inside the tests you can expect to have all :mod:`waeup. sirp`155 inside the tests you can expect to have all :mod:`waeup.kofa` 156 156 components (utilities, adapter, events) registered but as objects 157 157 have here still have no place inside a ZODB things like 'browsing' … … 163 163 If you use the Zope testrunner (from :mod:`zope.testing`) 164 164 then you have to use appropriate layers like the 165 :class:`waeup. sirp.testing.SIRPUnitTestLayer`.165 :class:`waeup.kofa.testing.KOFAUnitTestLayer`. 166 166 167 167 Usage with :mod:`zope.testing` testrunners … … 172 172 like the one defined in this module. 173 173 174 .. seealso:: :class:`waeup. sirp.testing.SIRPUnitTestLayer`174 .. seealso:: :class:`waeup.kofa.testing.KOFAUnitTestLayer` 175 175 176 176 """ 177 177 gsm = getGlobalSiteManager() 178 178 # If there are any event handlers registered already, we assume 179 # that waeup. sirpwas grokked already. There might be a batter179 # that waeup.kofa was grokked already. There might be a batter 180 180 # check, though. 181 181 if len(list(gsm.registeredHandlers())) > 0: … … 184 184 addCheckerPublic() 185 185 warnings.simplefilter('ignore') # disable (erraneous) warnings 186 grok.testing.grok('waeup. sirp')186 grok.testing.grok('waeup.kofa') 187 187 warnings.simplefilter('default') # reenable warnings 188 188 return True … … 191 191 """Register a datacenter config utility for non-functional tests. 192 192 """ 193 from waeup. sirp.interfaces import IDataCenterConfig193 from waeup.kofa.interfaces import IDataCenterConfig 194 194 conf = queryUtility(IDataCenterConfig) 195 195 if conf is not None: … … 204 204 """Unregister a datacenter config utility for non-functional tests. 205 205 """ 206 from waeup. sirp.interfaces import IDataCenterConfig206 from waeup.kofa.interfaces import IDataCenterConfig 207 207 conf = queryUtility(IDataCenterConfig) 208 208 if conf is None: … … 214 214 return 215 215 216 class SIRPUnitTestLayer(object):217 """A layer for tests that groks `waeup. sirp`.218 219 A Zope test layer that registers all :mod:`waeup. sirp` components216 class KOFAUnitTestLayer(object): 217 """A layer for tests that groks `waeup.kofa`. 218 219 A Zope test layer that registers all :mod:`waeup.kofa` components 220 220 before attached tests are run and cleans this registrations up 221 afterwards. Also basic (non-waeup. sirp) components like the event221 afterwards. Also basic (non-waeup.kofa) components like the event 222 222 dispatcher machinery are registered, set up and cleaned up. 223 223 … … 237 237 238 238 import unittest 239 from waeup. sirp.testing import SIRPUnitTestLayer239 from waeup.kofa.testing import KOFAUnitTestLayer 240 240 241 241 class MyTestCase(unittest.TestCase): 242 242 243 layer = SIRPUnitTestLayer243 layer = KOFAUnitTestLayer 244 244 245 245 # per-test setups and real tests go here... … … 331 331 def clear_logger_collector(): 332 332 from zope.component import queryUtility, getGlobalSiteManager 333 from waeup. sirp.interfaces import ILoggerCollector333 from waeup.kofa.interfaces import ILoggerCollector 334 334 collector = queryUtility(ILoggerCollector) 335 335 if collector is None: … … 363 363 If no special `checker` is passed, we use an extended 364 364 :class:`doctest.OutputChecker` as defined in 365 :mod:`waeup. sirp.testing`.365 :mod:`waeup.kofa.testing`. 366 366 367 367 If optional `optionflags` are not given, use ``REPORT_NDIFF``, 368 368 ``ELLIPSIS``, and ``NORMALIZE_WHITESPACE``. 369 369 370 .. seealso:: :data:`waeup. sirp.testing.optionflags`371 372 .. seealso:: :data:`waeup. sirp.testing.checker`370 .. seealso:: :data:`waeup.kofa.testing.optionflags` 371 372 .. seealso:: :data:`waeup.kofa.testing.checker` 373 373 """ 374 374 if checker.check_output(want, got, optionflags): … … 406 406 instance by something like: 407 407 408 from waeup. sirp.testing import get_doctest_suite408 from waeup.kofa.testing import get_doctest_suite 409 409 def test_suite(): 410 410 suite = get_doctest_suite(['mypkg/foo.txt', 'mypkg/bar.txt'])
Note: See TracChangeset for help on using the changeset viewer.