当前位置: 首页>>代码示例>>Python>>正文


Python unittest.BaseTestSuite方法代码示例

本文整理汇总了Python中unittest.BaseTestSuite方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.BaseTestSuite方法的具体用法?Python unittest.BaseTestSuite怎么用?Python unittest.BaseTestSuite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest的用法示例。


在下文中一共展示了unittest.BaseTestSuite方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: assert_garbage_collect_test_after_run

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def assert_garbage_collect_test_after_run(self, TestSuiteClass):
        if not unittest.BaseTestSuite._cleanup:
            raise unittest.SkipTest("Suite cleanup is disabled")

        class Foo(unittest.TestCase):
            def test_nothing(self):
                pass

        test = Foo('test_nothing')
        wref = weakref.ref(test)

        suite = TestSuiteClass([wref()])
        suite.run(unittest.TestResult())

        del test

        # for the benefit of non-reference counting implementations
        gc.collect()

        self.assertEqual(suite._tests, [None])
        self.assertIsNone(wref()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_suite.py

示例2: set_timeout

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def set_timeout(testsuite, seconds=None):
    """
    add timout to test case if it didn't have one,
    @param testsuite testsuite form loader()
    @param seconds: timeout seconds
    @return: updated testsuite
    """
    def _testset(testsuite):
        """interate tcs in testsuite"""
        for each in testsuite:
            if not isinstance(each, unittest.BaseTestSuite):
                yield each
            else:
                for each2 in _testset(each):
                    yield  each2

    if seconds:
        for tc in _testset(testsuite):
            assert hasattr(tc, "_testMethodName"), \
                "%s is not an unittest.TestCase object"
            testMethod = getattr(tc, tc._testMethodName)
            test_func = testMethod.im_func
            if not hastimeout(test_func):
                tc.run = timeout(seconds)(tc.run)
    return testsuite 
开发者ID:intel,项目名称:intel-iot-refkit,代码行数:27,代码来源:timeout.py

示例3: test_basetestsuite

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def test_basetestsuite(self):
        class Test(unittest.TestCase):
            wasSetUp = False
            wasTornDown = False
            @classmethod
            def setUpClass(cls):
                cls.wasSetUp = True
            @classmethod
            def tearDownClass(cls):
                cls.wasTornDown = True
            def testPass(self):
                pass
            def testFail(self):
                fail
        class Module(object):
            wasSetUp = False
            wasTornDown = False
            @staticmethod
            def setUpModule():
                Module.wasSetUp = True
            @staticmethod
            def tearDownModule():
                Module.wasTornDown = True

        Test.__module__ = 'Module'
        sys.modules['Module'] = Module
        self.addCleanup(sys.modules.pop, 'Module')

        suite = unittest.BaseTestSuite()
        suite.addTests([Test('testPass'), Test('testFail')])
        self.assertEqual(suite.countTestCases(), 2)

        result = unittest.TestResult()
        suite.run(result)
        self.assertFalse(Module.wasSetUp)
        self.assertFalse(Module.wasTornDown)
        self.assertFalse(Test.wasSetUp)
        self.assertFalse(Test.wasTornDown)
        self.assertEqual(len(result.errors), 1)
        self.assertEqual(len(result.failures), 0)
        self.assertEqual(result.testsRun, 2) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:43,代码来源:test_suite.py

示例4: test_remove_test_at_index

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def test_remove_test_at_index(self):
        if not unittest.BaseTestSuite._cleanup:
            raise unittest.SkipTest("Suite cleanup is disabled")

        suite = unittest.TestSuite()

        suite._tests = [1, 2, 3]
        suite._removeTestAtIndex(1)

        self.assertEqual([1, None, 3], suite._tests) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_suite.py

示例5: test_remove_test_at_index_not_indexable

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def test_remove_test_at_index_not_indexable(self):
        if not unittest.BaseTestSuite._cleanup:
            raise unittest.SkipTest("Suite cleanup is disabled")

        suite = unittest.TestSuite()
        suite._tests = None

        # if _removeAtIndex raises for noniterables this next line will break
        suite._removeTestAtIndex(2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_suite.py

示例6: test_garbage_collect_test_after_run_BaseTestSuite

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def test_garbage_collect_test_after_run_BaseTestSuite(self):
        self.assert_garbage_collect_test_after_run(unittest.BaseTestSuite) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_suite.py

示例7: flattenTestSuite

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def flattenTestSuite(test_suite, module=None):
    # Look for a `doctest_modules` list and attempt to add doctest tests to the
    # suite of tests that we are about to flatten.
    # todo: rename this function to something more appropriate.
    suites = [test_suite]
    doctest_modules = getattr(module, "doctest_modules", ())
    for doctest_module in doctest_modules:
        suite = DocTestSuite(doctest_module)
        suite.injected_module = module.__name__
        suites.append(suite)

    # Now extract all tests from the suite heirarchies and flatten them into a
    # single suite with all tests.
    tests = []
    for suite in suites:
        injected_module = None
        if getattr(suite, "injected_module", None):
            injected_module = suite.injected_module
        for test in suite:
            if injected_module:
                # For doctests, inject the test module name so we can later
                # grab it and use it to group the doctest output along with the
                # test module which specified it should be run.
                test.__module__ = injected_module
            if isinstance(test, unittest.BaseTestSuite):
                tests.extend(flattenTestSuite(test))
            else:
                tests.append(test)
    return GreenTestLoader.suiteClass(tests) 
开发者ID:CleanCut,项目名称:green,代码行数:31,代码来源:loader.py

示例8: filter_tagexp

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def filter_tagexp(testsuite, tagexp):
    """filter according to true or flase of tag expression"""
    if not tagexp:
        return testsuite
    caselist = []
    for each in testsuite:
        if not isinstance(each, unittest.BaseTestSuite):
            if checktags(each, tagexp):
                caselist.append(each)
        else:
            caselist.append(filter_tagexp(each, tagexp))
    return testsuite.__class__(caselist) 
开发者ID:intel,项目名称:intel-iot-refkit,代码行数:14,代码来源:tag.py


注:本文中的unittest.BaseTestSuite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。