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


Python case.TestCase方法代碼示例

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


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

示例1: addSuccess

# 需要導入模塊: from unittest import case [as 別名]
# 或者: from unittest.case import TestCase [as 別名]
def addSuccess(self, test: TestCase):
        super().addSuccess(test)
        self.stream.writeln('## Ending Test ##')
        self.passed.append((test, ''))
        logger = getLogger('djongo')
        logger.setLevel(INFO) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,代碼來源:test_runner.py

示例2: test_retry_without_arg

# 需要導入模塊: from unittest import case [as 別名]
# 或者: from unittest.case import TestCase [as 別名]
def test_retry_without_arg(self):
        # Check docstrings of decorated functions.
        def func(*args):
            """func docstring"""
            return 1

        def func_raises(exc=Exception):
            """func_raises docstring"""
            raise exc

        self.assertEqual(retry(func).__doc__, func.__doc__)
        self.assertEqual(retry()(func).__doc__, func.__doc__)
        self.assertEqual(retry(func_raises).__doc__, func_raises.__doc__)
        self.assertEqual(retry()(func_raises).__doc__, func_raises.__doc__)

        # Check func returns correctly after it is decorated.
        self.assertEqual(retry(func)(), 1)
        self.assertEqual(retry()(func)(), 1)

        # Check func raises correctly after it is decorated.
        with self.assertRaises(Exception):
            retry(func_raises, wait=0)()
        with self.assertRaises(Exception):
            retry(wait=0)(func_raises)()

        with self.assertRaises(NotImplementedError):
            retry(func_raises, wait=0)(NotImplementedError)
        with self.assertRaises(NotImplementedError):
            retry(wait=0)(func_raises)(NotImplementedError)

        with self.assertRaises(NotImplementedError):
            retry(func_raises, wait=0, max_attempts=0)(NotImplementedError)
        with self.assertRaises(NotImplementedError):
            retry(wait=0, max_attempts=0)(func_raises)(NotImplementedError)

        # Check TypeError is raised if args have incorrect values.
        with self.assertRaises(TypeError):
            retry(max_attempts="")  # needs to be an int

        with self.assertRaises(TypeError):
            retry(exc=TestCase)  # need to be subclass of Exception (single value)

        with self.assertRaises(TypeError):
            retry(exc=(TestCase,))  # need to be subclass of Exception (tuple)

        with self.assertRaises(TypeError):
            retry(wait="")  # needs to be a float 
開發者ID:johnbywater,項目名稱:eventsourcing,代碼行數:49,代碼來源:test_decorators.py


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