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


Python TestCase.failureException方法代碼示例

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


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

示例1: wait_no_exception

# 需要導入模塊: from unittest2 import TestCase [as 別名]
# 或者: from unittest2.TestCase import failureException [as 別名]
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,代碼行數:29,代碼來源:wait.py

示例2: state_wait

# 需要導入模塊: from unittest2 import TestCase [as 別名]
# 或者: from unittest2.TestCase import failureException [as 別名]
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,代碼行數:28,代碼來源:wait.py

示例3: wait_exception

# 需要導入模塊: from unittest2 import TestCase [as 別名]
# 或者: from unittest2.TestCase import failureException [as 別名]
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,代碼行數:17,代碼來源:wait.py

示例4: re_search_wait

# 需要導入模塊: from unittest2 import TestCase [as 別名]
# 或者: from unittest2.TestCase import failureException [as 別名]
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,代碼行數:22,代碼來源:wait.py


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