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


Python TestCase.run方法代码示例

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


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

示例1: test_run

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_run(self):
        events = []
        result = LoggingResult(events)

        class LoggingCase(unittest.TestCase):
            def run(self, result):
                events.append('run %s' % self._testMethodName)

            def test1(self): pass
            def test2(self): pass

        tests = [LoggingCase('test1'), LoggingCase('test2')]

        unittest.TestSuite(tests).run(result)

        self.assertEqual(events, ['run test1', 'run test2'])

    # "Add a TestCase ... to the suite" 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:20,代码来源:test_unittest.py

示例2: test_run_call_order__error_in_setUp

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_run_call_order__error_in_setUp(self):
        events = []
        result = LoggingResult(events)

        def setUp():
            events.append('setUp')
            raise RuntimeError('raised by setUp')

        def test():
            events.append('test')

        def tearDown():
            events.append('tearDown')

        expected = ['startTest', 'setUp', 'addError', 'stopTest']
        unittest.FunctionTestCase(test, setUp, tearDown).run(result)
        self.assertEqual(events, expected)

    # "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 the test raises
    # an error (as opposed to a failure). 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:27,代码来源:test_unittest.py

示例3: test_run_call_order__error_in_tearDown

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_run_call_order__error_in_tearDown(self):
        events = []
        result = LoggingResult(events)

        def setUp():
            events.append('setUp')

        def test():
            events.append('test')

        def tearDown():
            events.append('tearDown')
            raise RuntimeError('raised by tearDown')

        expected = ['startTest', 'setUp', 'test', 'tearDown', 'addError',
                    'stopTest']
        unittest.FunctionTestCase(test, setUp, tearDown).run(result)
        self.assertEqual(events, expected)

    # "Return a string identifying the specific test case."
    #
    # Because of the vague nature of the docs, I'm not going to lock this
    # test down too much. Really all that can be asserted is that the id()
    # will be a string (either 8-byte or unicode -- again, because the docs
    # just say "string") 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:27,代码来源:test_unittest.py

示例4: test_failureException__subclassing__explicit_raise

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_failureException__subclassing__explicit_raise(self):
        events = []
        result = LoggingResult(events)

        class Foo(unittest.TestCase):
            def test(self):
                raise RuntimeError()

            failureException = RuntimeError

        self.failUnless(Foo('test').failureException is RuntimeError)


        Foo('test').run(result)
        expected = ['startTest', 'addFailure', 'stopTest']
        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."
    #
    # Make sure TestCase.run() respects the designated failureException 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:25,代码来源:test_unittest.py

示例5: run

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def run(self, *args, **kwargs):
        if self.switch_expected == 'default':
            self.switch_expected = get_switch_expected(self.fullname)
        return BaseTestCase.run(self, *args, **kwargs) 
开发者ID:34nm,项目名称:gsmtpd,代码行数:6,代码来源:greentest.py

示例6: test_gen_param

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_gen_param(self):
        codelist = QA.QA_fetch_stock_list_adv().code.tolist()
        days = 300
        start = datetime.datetime.now().date() - datetime.timedelta(days)
        end = datetime.datetime.now().date() - datetime.timedelta(10)
        codeListCount = 200
        ips = get_ip_list_by_multi_process_ping(QA.QAUtil.stock_ip_list,
                                                _type='stock')
        param = gen_param(codelist[:codeListCount], start, end,
                          IPList=ips[:cpu_count()])
        a = time.time()
        ps = Parallelism(cpu_count())
        ps.run(QA.QAFetch.QATdx.QA_fetch_get_stock_day, param)
        data = ps.get_results()
        b = time.time()
        t1 = b - a
        data = list(data)
        print('返回数据{}条,用时:{}秒'.format(len(data), t1))
        # print(data)
        # print([x.code.unique() for x in data])
        self.assertTrue(len(data) == codeListCount,
                        '返回结果和输入参数个数不匹配: {} {}'.format(len(data),
                                                       codeListCount))
        i, j = 0, 0
        for x in data:
            try:
                # print(x)
                i += 1
                self.assertTrue((x is None) or (len(x) > 0),
                                '返回数据太少:{}'.format(len(x)))
                if not ((x is None) or (len(x) > 0)):
                    print('data is None')
                if i % 10 == 0:
                    print(x)
            except Exception as e:
                j += 1
        print(i, j) 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:39,代码来源:QATdx_Test_multi_process_map.py

示例7: test_run__empty_suite

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_run__empty_suite(self):
        events = []
        result = LoggingResult(events)

        suite = unittest.TestSuite()

        suite.run(result)

        self.assertEqual(events, [])

    # "Note that unlike TestCase.run(), TestSuite.run() requires the
    # "result object to be passed in." 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:14,代码来源:test_unittest.py

示例8: test_run__requires_result

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_run__requires_result(self):
        suite = unittest.TestSuite()

        try:
            suite.run()
        except TypeError:
            pass
        else:
            self.fail("Failed to raise TypeError")

    # "Run the tests associated with this suite, collecting the result into
    # the test result object passed as result." 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:14,代码来源:test_unittest.py

示例9: test_countTestCases

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_countTestCases(self):
        test = unittest.FunctionTestCase(lambda: None)

        self.assertEqual(test.countTestCases(), 1)

    # "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. 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:14,代码来源:test_unittest.py

示例10: test_run_call_order__failure_in_test

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_run_call_order__failure_in_test(self):
        events = []
        result = LoggingResult(events)

        def setUp():
            events.append('setUp')

        def test():
            events.append('test')
            self.fail('raised by test')

        def tearDown():
            events.append('tearDown')

        expected = ['startTest', 'setUp', 'test', 'addFailure', 'tearDown',
                    'stopTest']
        unittest.FunctionTestCase(test, setUp, tearDown).run(result)
        self.assertEqual(events, expected)

    # "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 tearDown() raises
    # an exception. 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:28,代码来源:test_unittest.py

示例11: test_init

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_init(self):
        result = unittest.TestResult()

        self.failUnless(result.wasSuccessful())
        self.assertEqual(len(result.errors), 0)
        self.assertEqual(len(result.failures), 0)
        self.assertEqual(result.testsRun, 0)
        self.assertEqual(result.shouldStop, False)

    # "This method can be called to signal that the set of tests being
    # run should be aborted by setting the TestResult's shouldStop
    # attribute to True." 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:14,代码来源:test_unittest.py

示例12: test_stop

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_stop(self):
        result = unittest.TestResult()

        result.stop()

        self.assertEqual(result.shouldStop, True)

    # "Called when the test case test is about to be run. The default
    # implementation simply increments the instance's testsRun counter." 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:11,代码来源:test_unittest.py

示例13: test_init__no_test_name

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_init__no_test_name(self):
        class Test(unittest.TestCase):
            def runTest(self): raise MyException()
            def test(self): pass

        self.assertEqual(Test().id()[-13:], '.Test.runTest')

    # "class TestCase([methodName])"
    # ...
    # "Each instance of TestCase will run a single test method: the
    # method named methodName." 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:13,代码来源:test_unittest.py

示例14: test_init__test_name__valid

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_init__test_name__valid(self):
        class Test(unittest.TestCase):
            def runTest(self): raise MyException()
            def test(self): pass

        self.assertEqual(Test('test').id()[-10:], '.Test.test')

    # "class TestCase([methodName])"
    # ...
    # "Each instance of TestCase will run a single test method: the
    # method named methodName." 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:13,代码来源:test_unittest.py

示例15: test_defaultTestResult

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import run [as 别名]
def test_defaultTestResult(self):
        class Foo(unittest.TestCase):
            def runTest(self):
                pass

        result = Foo().defaultTestResult()
        self.assertEqual(type(result), unittest.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. 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:17,代码来源:test_unittest.py


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