当前位置: 首页>>代码示例>>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;未经允许,请勿转载。