python类TestResult()的实例源码

test_skipping.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_skip_non_unittest_class_new_style(self):
        @unittest.skip("testing")
        class Mixin(object):
            def test_1(self):
                record.append(1)
        class Foo(Mixin, unittest.TestCase):
            pass
        record = []
        result = unittest.TestResult()
        test = Foo("test_1")
        suite = unittest.TestSuite([test])
        suite.run(result)
        self.assertEqual(result.skipped, [(test, "testing")])
        self.assertEqual(record, [])
test_break.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def testWeakReferences(self):
        # Calling registerResult on a result should not keep it alive
        result = unittest2.TestResult()
        unittest2.registerResult(result)

        ref = weakref.ref(result)
        del result

        # For non-reference counting implementations
        gc.collect();gc.collect()
        self.assertIsNone(ref())
test_runner.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_multiple_inheritance(self):
        class AResult(unittest.TestResult):
            def __init__(self, stream, descriptions, verbosity):
                super(AResult, self).__init__(stream, descriptions, verbosity)

        class ATextResult(unittest.TextTestResult, AResult):
            pass

        # This used to raise an exception due to TextTestResult not passing
        # on arguments in its __init__ super call
        ATextResult(None, None, 1)
test_runner.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testBufferAndFailfast(self):
        class Test(unittest2.TestCase):
            def testFoo(self):
                pass
        result = unittest2.TestResult()
        runner = unittest2.TextTestRunner(stream=StringIO(), failfast=True,
                                          buffer=True)
        # Use our result object
        runner._makeResult = lambda: result
        runner.run(Test('testFoo'))

        self.assertTrue(result.failfast)
        self.assertTrue(result.buffer)
test_discovery.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_discover_with_module_that_raises_SkipTest_on_import(self):
        loader = unittest.TestLoader()

        def _get_module_from_name(name):
            raise unittest.SkipTest('skipperoo')
        loader._get_module_from_name = _get_module_from_name

        self.setup_import_issue_tests('test_skip_dummy.py')

        suite = loader.discover('.')
        self.assertEqual(suite.countTestCases(), 1)

        result = unittest.TestResult()
        suite.run(result)
        self.assertEqual(len(result.skipped), 1)
test_case.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_defaultTestResult(self):
        class Foo(unittest2.TestCase):
            def runTest(self):
                pass

        result = Foo().defaultTestResult()
        self.assertEqual(type(result), unittest2.TestResult)

    # "When a setUp() method is defined, the test runner will run that method
    # prior to each test. Likewise, if a tearDown() method is defined, the
    # test runner will invoke that method after each test. In the example,
    # setUp() was used to create a fresh sequence for each test."
    #
    # Make sure the proper call order is maintained, even if setUp() raises
    # an exception.
test_case.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_subtests_failfast(self):
        # Ensure proper test flow with subtests and failfast (issue #22894)
        events = []

        class Foo(unittest.TestCase):
            def test_a(self):
                with self.subTest():
                    events.append('a1')
                events.append('a2')

            def test_b(self):
                with self.subTest():
                    events.append('b1')
                with self.subTest():
                    self.fail('failure')
                events.append('b2')

            def test_c(self):
                events.append('c')

        result = unittest.TestResult()
        result.failfast = True
        suite = unittest.makeSuite(Foo)
        suite.run(result)

        expected = ['a1', 'a2', 'b1']
        self.assertEqual(events, expected)

    # "This class attribute gives the exception raised by the test() method.
    # If a test framework needs to use a specialized exception, possibly to
    # carry additional information, it must subclass this exception in
    # order to ``play fair'' with the framework.  The initial value of this
    # attribute is AssertionError"
test_case.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def testSkippingEverywhere(self):
        def _skip(self=None):
            raise unittest2.SkipTest('some reason')
        def nothing(self):
            pass

        class Test1(unittest2.TestCase):
            test_something = _skip

        class Test2(unittest2.TestCase):
            setUp = _skip
            test_something = nothing

        class Test3(unittest2.TestCase):
            test_something = nothing
            tearDown = _skip

        class Test4(unittest2.TestCase):
            def test_something(self):
                self.addCleanup(_skip)

        for klass in (Test1, Test2, Test3, Test4):
            result = unittest2.TestResult()
            klass('test_something').run(result)
            self.assertEqual(len(result.skipped), 1)
            self.assertEqual(result.testsRun, 1)
test_case.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def testSystemExit(self):
        def _raise(self=None):
            raise SystemExit
        def nothing(self):
            pass

        class Test1(unittest2.TestCase):
            test_something = _raise

        class Test2(unittest2.TestCase):
            setUp = _raise
            test_something = nothing

        class Test3(unittest2.TestCase):
            test_something = nothing
            tearDown = _raise

        class Test4(unittest2.TestCase):
            def test_something(self):
                self.addCleanup(_raise)

        for klass in (Test1, Test2, Test3, Test4):
            result = unittest2.TestResult()
            klass('test_something').run(result)
            self.assertEqual(len(result.errors), 1)
            self.assertEqual(result.testsRun, 1)
test_suite.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_init__empty_tests(self):
        suite = unittest2.TestSuite([])

        self.assertEqual(suite.countTestCases(), 0)
        # countTestCases() still works after tests are run
        suite.run(unittest.TestResult())
        self.assertEqual(suite.countTestCases(), 0)

    # "class TestSuite([tests])"
    # ...
    # "If tests is given, it must be an iterable of individual test cases
    # or other test suites that will be used to build the suite initially"
    #
    # TestSuite should allow any iterable to provide tests
test_suite.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_init__tests_from_any_iterable(self):
        def tests():
            yield unittest2.FunctionTestCase(lambda: None)
            yield unittest2.FunctionTestCase(lambda: None)

        suite_1 = unittest2.TestSuite(tests())
        self.assertEqual(suite_1.countTestCases(), 2)

        suite_2 = unittest2.TestSuite(suite_1)
        self.assertEqual(suite_2.countTestCases(), 2)

        suite_3 = unittest2.TestSuite(set(suite_1))
        self.assertEqual(suite_3.countTestCases(), 2)

        # countTestCases() still works after tests are run
        suite_1.run(unittest.TestResult())
        self.assertEqual(suite_1.countTestCases(), 2)
        suite_2.run(unittest.TestResult())
        self.assertEqual(suite_2.countTestCases(), 2)
        suite_3.run(unittest.TestResult())
        self.assertEqual(suite_3.countTestCases(), 2)

    # "class TestSuite([tests])"
    # ...
    # "If tests is given, it must be an iterable of individual test cases
    # or other test suites that will be used to build the suite initially"
    #
    # Does TestSuite() also allow other TestSuite() instances to be present
    # in the tests iterable?
test_suite.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_countTestCases_simple(self):
        test1 = unittest2.FunctionTestCase(lambda: None)
        test2 = unittest2.FunctionTestCase(lambda: None)
        suite = unittest2.TestSuite((test1, test2))

        self.assertEqual(suite.countTestCases(), 2)
        # countTestCases() still works after tests are run
        suite.run(unittest.TestResult())
        self.assertEqual(suite.countTestCases(), 2)

    # "Return the number of tests represented by the this test object.
    # ...this method is also implemented by the TestSuite class, which can
    # return larger [greater than 1] values"
    #
    # Make sure this holds for nested TestSuite instances, too
test_suite.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_function_in_suite(self):
        def f(_):
            pass
        suite = unittest2.TestSuite()
        suite.addTest(f)

        # when the bug is fixed this line will not crash
        suite.run(unittest2.TestResult())
test_suite.py 文件源码 项目:devsecops-example-helloworld 作者: boozallen 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_overriding_call(self):
        class MySuite(unittest2.TestSuite):
            called = False
            def __call__(self, *args, **kw):
                self.called = True
                unittest2.TestSuite.__call__(self, *args, **kw)

        suite = MySuite()
        wrapper = unittest2.TestSuite()
        wrapper.addTest(suite)
        wrapper(unittest2.TestResult())
        self.assertTrue(suite.called)
support.py 文件源码 项目:hakkuframework 作者: 4shadoww 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def run(self, test):
        result = unittest.TestResult()
        test(result)
        return result
support.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def run(self, test):
        result = unittest.TestResult()
        test(result)
        return result
support.py 文件源码 项目:islam-buddy 作者: hamir 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run(self, test):
        result = unittest.TestResult()
        test(result)
        return result
support.py 文件源码 项目:FightstickDisplay 作者: calexil 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def run(self, test):
        result = unittest.TestResult()
        test(result)
        return result
support.py 文件源码 项目:cryptogram 作者: xinmingzhang 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run(self, test):
        result = unittest.TestResult()
        test(result)
        return result
support.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def run(self, test):
        result = unittest.TestResult()
        test(result)
        return result


问题


面经


文章

微信
公众号

扫码关注公众号