當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。