Changeset 12595 for main


Ignore:
Timestamp:
11 Feb 2015, 15:28:49 (10 years ago)
Author:
uli
Message:

Move test helper.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_async.py

    r12581 r12595  
    33import tempfile
    44import transaction
    5 from contextlib import contextmanager
    65from zc.async.testing import wait_for_result
    76from zope.component import getUtility
     
    1211from waeup.kofa.async import AsyncJob, get_job_id
    1312from waeup.kofa.interfaces import IJobManager, IKofaUtils
    14 from waeup.kofa.testing import FunctionalTestCase, FunctionalLayer
     13from waeup.kofa.testing import (
     14    FunctionalTestCase, FunctionalLayer, expensive_actions,
     15    )
    1516from waeup.kofa.tests.test_async import FunctionalAsyncTestCase
    1617
     
    2223def dummy_func():
    2324    return 42
    24 
    25 
    26 @contextmanager
    27 def expensive_actions():
    28     """A contextmanager to work with a modified `expensive_acrtions_allowed()`
    29 
    30     This method is part of local IKofaUtils.
    31     """
    32     utils = getUtility(IKofaUtils)
    33     old_func = utils.expensive_actions_allowed
    34     try:
    35         yield utils
    36     finally:
    37         # restore function after use
    38         utils.expensive_actions_allowed = old_func
    3925
    4026
  • main/waeup.kofa/trunk/src/waeup/kofa/testing.py

    r12582 r12595  
    2929import zope.component
    3030import waeup.kofa
     31from contextlib import contextmanager
    3132from zc.async.interfaces import COMPLETED
    3233from zope.app.testing.functional import (
    3334    ZCMLLayer, FunctionalTestSetup, getRootFolder, sync, FunctionalTestCase)
    34 from zope.component import getGlobalSiteManager, queryUtility
     35from zope.component import getGlobalSiteManager, queryUtility, getUtility
    3536from zope.security.testing import addCheckerPublic
    3637from zope.testing import renormalizing
    3738from zope.testing.cleanup import cleanUp
     39from waeup.kofa.interfaces import IKofaUtils
    3840
    3941ftesting_zcml = os.path.join(
     
    472474            del self._jobs[job_id]
    473475        return
     476
     477
     478@contextmanager
     479def expensive_actions():
     480    """A contextmanager to work with a modified `expensive_acrtions_allowed()`
     481
     482    This method is part of local IKofaUtils.
     483    """
     484    utils = getUtility(IKofaUtils)
     485    old_func = utils.expensive_actions_allowed
     486    try:
     487        yield utils
     488    finally:
     489        # restore function after use
     490        utils.expensive_actions_allowed = old_func
Note: See TracChangeset for help on using the changeset viewer.