當前位置: 首頁>>代碼示例>>Python>>正文


Python unittest2.TestCase類代碼示例

本文整理匯總了Python中unittest2.TestCase的典型用法代碼示例。如果您正苦於以下問題:Python TestCase類的具體用法?Python TestCase怎麽用?Python TestCase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TestCase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

    def __init__(self, fieldnames, data_generators):

        TestCase.__init__(self)

        self._data_generators = list(chain((lambda: self._serial_number, time), data_generators))
        self._fieldnames = list(chain(("_serial", "_time"), fieldnames))
        self._recorder = TestRecorder(self)
        self._serial_number = None
開發者ID:malmoore,項目名稱:splunk-sdk-python,代碼行數:8,代碼來源:test_internals_v2.py

示例2: setUp

    def setUp(self):
        TestCase.setUp(self)

        self.converter = HTML2LatexConverter(
            context=object(),
            request=object(),
            layout=object())

        self.convert = self.converter.convert
開發者ID:4teamwork,項目名稱:ftw.pdfgenerator,代碼行數:9,代碼來源:base.py

示例3: run

 def run(self, result=None):
     # moved bits from original implementation of TestCase.run to
     # keep the way it works
     if result is None:
         result = self.defaultTestResult()
         startTestRun = getattr(result, 'startTestRun', None)
         if startTestRun is not None:
             startTestRun()
     TestCase.run(self, result)
     if not result.wasSuccessful() and failfast:
         result.shouldStop = True
開發者ID:rlgomes,項目名稱:sst,代碼行數:11,代碼來源:runtests.py

示例4: state_wait

def state_wait(lfunction, final_set=set(), valid_set=None):
    #TODO(afazekas): evaluate using ABC here
    if not isinstance(final_set, set):
        final_set = set((final_set,))
    if not isinstance(valid_set, set) and valid_set is not None:
        valid_set = set((valid_set,))
    start_time = time.time()
    old_status = status = lfunction()
    while True:
        if status != old_status:
            LOG.info('State transition "%s" ==> "%s" %d second', old_status,
                     status, time.time() - start_time)
        if status in final_set:
            return status
        if valid_set is not None and status not in valid_set:
            return status
        dtime = time.time() - start_time
        if dtime > default_timeout:
            raise TestCase.failureException("State change timeout exceeded!"
                                            '(%ds) While waiting'
                                            'for %s at "%s"' %
                                            (dtime,
                                            final_set, status))
        time.sleep(default_check_interval)
        old_status = status
        status = lfunction()
開發者ID:eghobo,項目名稱:tempest,代碼行數:26,代碼來源:wait.py

示例5: wait_no_exception

def wait_no_exception(lfunction, exc_class=None, exc_matcher=None):
    """Stops waiting on success"""
    start_time = time.time()
    if exc_matcher is not None:
        exc_class = BotoServerError

    if exc_class is None:
        exc_class = BaseException
    while True:
        result = None
        try:
            result = lfunction()
            LOG.info('No Exception in %d second',
                     time.time() - start_time)
            return result
        except exc_class as exc:
            if exc_matcher is not None:
                res = exc_matcher.match(exc)
                if res is not None:
                    LOG.info(res)
                    raise exc
        # Let the other exceptions propagate
        dtime = time.time() - start_time
        if dtime > default_timeout:
            raise TestCase.failureException("Wait timeout exceeded! (%ds)" %
                                            dtime)
        time.sleep(default_check_interval)
開發者ID:eghobo,項目名稱:tempest,代碼行數:27,代碼來源:wait.py

示例6: assert_

 def assert_(self, *args, **kwargs):
     if sys.version_info >= (2, 7):
         # The unittest2 library uses this deprecated method, we can't raise
         # the exception.
         raise DeprecationWarning(
             'The {0}() function is deprecated. Please start using {1}() '
             'instead.'.format('assert_', 'assertTrue')
         )
     return _TestCase.assert_(self, *args, **kwargs)
開發者ID:cachedout,項目名稱:salt-testing,代碼行數:9,代碼來源:unit.py

示例7: __init__

    def __init__(self, methodName='runTest'):
        TestCase.__init__(self, methodName=methodName)
        self.maxDiff = None
        self.eq = self.assertEqual
        self.neq = self.assertNotEqual

        self.true = self.assertTrue
        self.false = self.assertFalse

        self.isin = self.assertIn
        self.not_in = self.assertNotIn
        self.almost_eq = self.assertAlmostEqual

        self.isinstance = self.assertIsInstance
        self.not_isinstance = self.assertNotIsInstance

        self.raises = self.assertRaises
        self.items_eq = self.assertItemsEqual
開發者ID:kashirov,項目名稱:ztest,代碼行數:18,代碼來源:__init__.py

示例8: test_check_permissions_fails_with_nobody

    def test_check_permissions_fails_with_nobody(self):
        mtool = self.mocker.mock()
        self.expect(mtool.getAuthenticatedMember()).result(
            SpecialUsers.nobody)
        self.mock_tool(mtool, 'portal_membership')

        self.replay()

        view = ResolveOGUIDView(object(), object())

        with TestCase.assertRaises(self, Unauthorized):
            view._check_permissions(object())
開發者ID:hellfish2,項目名稱:opengever.core,代碼行數:12,代碼來源:test_resolve_oguid.py

示例9: test_check_permission_fails_without_view_permission

    def test_check_permission_fails_without_view_permission(self):
        obj = self.mocker.mock()

        mtool = self.mocker.mock()
        self.expect(mtool.getAuthenticatedMember().checkPermission(
                'View', obj)).result(False)
        self.mock_tool(mtool, 'portal_membership')

        self.replay()

        view = ResolveOGUIDView(object(), object())

        with TestCase.assertRaises(self, Unauthorized):
            view._check_permissions(obj)
開發者ID:hellfish2,項目名稱:opengever.core,代碼行數:14,代碼來源:test_resolve_oguid.py

示例10: wait_exception

def wait_exception(lfunction):
    """Returns with the exception or raises one"""
    start_time = time.time()
    while True:
        try:
            lfunction()
        except BaseException as exc:
            LOG.info('Exception in %d second',
                     time.time() - start_time)
            return exc
        dtime = time.time() - start_time
        if dtime > default_timeout:
            raise TestCase.failureException("Wait timeout exceeded! (%ds)" %
                                            dtime)
        time.sleep(default_check_interval)
開發者ID:eghobo,項目名稱:tempest,代碼行數:15,代碼來源:wait.py

示例11: test_validator

    def test_validator(self):
        request = self.mocker.mock()
        self.expect(request.get('PATH_INFO', ANY)).result('somepath/++add++type')

        field = lifecycle.ILifeCycle['custody_period']

        context = None
        view = None
        widget = None

        self.replay()

        validator = getMultiAdapter((context, request, view, field, widget), IValidator)
        validator.validate(20)

        with TestCase.assertRaises(self, ConstraintNotSatisfied):
            validator.validate(15)
開發者ID:hellfish2,項目名稱:opengever.core,代碼行數:17,代碼來源:test_lifecycle.py

示例12: re_search_wait

def re_search_wait(lfunction, regexp):
    """Stops waiting on success"""
    start_time = time.time()
    while True:
        text = lfunction()
        result = re.search(regexp, text)
        if result is not None:
            LOG.info('Pattern "%s" found in %d second in "%s"',
                     regexp,
                     time.time() - start_time,
                     text)
            return result
        dtime = time.time() - start_time
        if dtime > default_timeout:
            raise TestCase.failureException('Pattern find timeout exceeded!'
                                            '(%ds) While waiting for'
                                            '"%s" pattern in "%s"' %
                                            (dtime,
                                            regexp, text))
        time.sleep(default_check_interval)
開發者ID:eghobo,項目名稱:tempest,代碼行數:20,代碼來源:wait.py

示例13: test_validator_in_context

    def test_validator_in_context(self):
        request = self.mocker.mock()
        self.expect(request.get('PATH_INFO', ANY)).result(
            'somepath/++add++type').count(0, None)

        context = self.mocker.mock()
        self.expect(context.REQUEST).result(request).count(0, None)
        self.expect(context.custody_period).result(20).count(0, None)
        self.expect(context.aq_inner).result(context).count(0, None)
        self.expect(context.aq_parent).result(None).count(0, None)

        field = lifecycle.ILifeCycle['custody_period']

        view = None
        widget = None

        self.replay()

        validator = getMultiAdapter((context, request, view, field, widget), IValidator)
        validator.validate(20)
        validator.validate(30)

        with TestCase.assertRaises(self, ConstraintNotSatisfied):
            validator.validate(10)
開發者ID:hellfish2,項目名稱:opengever.core,代碼行數:24,代碼來源:test_lifecycle.py

示例14: setUp

 def setUp(self):
     TestCase.setUp(self)
開發者ID:larrys,項目名稱:splunk-sdk-python,代碼行數:2,代碼來源:test_decorators.py

示例15: __init__

 def __init__(self, method="runTest"):
     """Constructor."""
     TestCase.__init__(self, method)
     self.method = method
     self.pdb_script = None
     self.fnull = None
開發者ID:the9ball,項目名稱:.vim,代碼行數:6,代碼來源:test_support.py


注:本文中的unittest2.TestCase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。