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