• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python unittest.registerResult函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中unittest.registerResult函数的典型用法代码示例。如果您正苦于以下问题:Python registerResult函数的具体用法?Python registerResult怎么用?Python registerResult使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: testSecondInterrupt

    def testSecondInterrupt(self):
        if due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
            return

        result = unittest.TestResult()
        unittest.installHandler()
        unittest.registerResult(result)

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
            result.breakCaught = True
            if not due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
                self.assertTrue(result.shouldStop)
            os.kill(pid, signal.SIGINT)
            if not due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
                self.fail("Second KeyboardInterrupt not raised")

        try:
            test(result)
        except KeyboardInterrupt:
            pass
        else:
            if not due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
                self.fail("Second KeyboardInterrupt not raised")
        self.assertTrue(result.breakCaught)
开发者ID:jschementi,项目名称:iron,代码行数:26,代码来源:test_break.py


示例2: testTwoResults

    def testTwoResults(self):
        if due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
            return

        unittest.installHandler()

        result = unittest.TestResult()
        unittest.registerResult(result)
        new_handler = signal.getsignal(signal.SIGINT)

        result2 = unittest.TestResult()
        unittest.registerResult(result2)
        self.assertEqual(signal.getsignal(signal.SIGINT), new_handler)

        result3 = unittest.TestResult()

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)

        try:
            test(result)
        except KeyboardInterrupt:
            self.fail("KeyboardInterrupt not handled")

        if not due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
            self.assertTrue(result.shouldStop)
            self.assertTrue(result2.shouldStop)
        self.assertFalse(result3.shouldStop)
开发者ID:jschementi,项目名称:iron,代码行数:29,代码来源:test_break.py


示例3: testTwoResults

    def testTwoResults(self):
        unittest.installHandler()

        result = unittest.TestResult()
        unittest.registerResult(result)
        new_handler = signal.getsignal(signal.SIGINT)

        result2 = unittest.TestResult()
        unittest.registerResult(result2)
        self.assertEqual(signal.getsignal(signal.SIGINT), new_handler)

        result3 = unittest.TestResult()

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)

        try:
            test(result)
        except KeyboardInterrupt:
            self.fail("KeyboardInterrupt not handled")

        self.assertTrue(result.shouldStop)
        self.assertTrue(result2.shouldStop)
        self.assertFalse(result3.shouldStop)
开发者ID:1018365842,项目名称:FreeIMU,代码行数:25,代码来源:test_break.py


示例4: run

    def run(self, test):
        "Run the given test case or test suite."
        result = self._makeResult()
        registerResult(result)
        result.failfast = self.failfast
        result.buffer = self.buffer
        startTime = time.time()
        startTestRun = getattr(result, 'startTestRun', None)
        if startTestRun is not None:
            startTestRun()
        try:
            test(result)
        finally:
            stopTestRun = getattr(result, 'stopTestRun', None)
            if stopTestRun is not None:
                stopTestRun()
        stopTime = time.time()
        timeTaken = stopTime - startTime
        #stopTestRun = getattr(result, 'logRunTime', None)
        #stopTestRun(test, timeTaken)

        result.printErrors()
        if hasattr(result, 'separator2'):
            self.stream.writeln(result.separator2)
        run = result.testsRun
        self.stream.writeln("Ran %d test%s in %.3fs" %
                            (run, run != 1 and "s" or "", timeTaken))
        self.stream.writeln()
        return result
开发者ID:hendrikvgl,项目名称:RoboCup-Spielererkennung,代码行数:29,代码来源:bit_bots_test_runner.py


示例5: testWeakReferences

 def testWeakReferences(self):
     result = unittest.TestResult()
     unittest.registerResult(result)
     ref = weakref.ref(result)
     del result
     gc.collect()
     gc.collect()
     self.assertIsNone(ref())
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:8,代码来源:test_break.py


示例6: run

 def run(self, test):
   result = unittest.TestResult()
   unittest.registerResult(result)
   test(result)
   for kind, errors in [('FAIL', result.failures), ('ERROR', result.errors)]:
     for test, err in errors:
       sys.stderr.write('{} {}\n{}'.format(test, kind, err))
   return result
开发者ID:0xBADCA7,项目名称:grumpy,代码行数:8,代码来源:shard_test.py


示例7: run

    def run(self,
            test_modules=__all__,
            pretend=False,
            logfile='test/test.log',
            loglevel=forcebalance.output.INFO,
            **kwargs):
            
        self.check()

        self.logger.setLevel(loglevel)

        # first install unittest interrupt handler which gracefully finishes current test on Ctrl+C
        unittest.installHandler()

        # create blank test suite and fill it with test suites loaded from each test module
        tests = unittest.TestSuite()
        systemTests = unittest.TestSuite()
        for suite in unittest.defaultTestLoader.discover('test'):
            for module in suite:
                for test in module:
                    modName,caseName,testName = test.id().split('.')
                    if modName in test_modules:
                        if modName=="test_system": systemTests.addTest(test)
                        else: tests.addTest(test)

        tests.addTests(systemTests) # integration tests should be run after other tests

        result = ForceBalanceTestResult()
        
        forcebalance.output.getLogger("forcebalance").addHandler(forcebalance.output.NullHandler())

        ### START TESTING ###
        # run any pretest tasks before first test
        result.startTestRun(tests)

        # if pretend option is enabled, skip all tests instead of running them
        if pretend:
            for test in tests:
                result.addSkip(test)

        # otherwise do a normal test run
        else:
            unittest.registerResult(result)
            try:
                tests.run(result)
            except KeyboardInterrupt:
                # Adding this allows us to determine
                # what is causing tests to hang indefinitely.
                import traceback
                traceback.print_exc()
                self.logger.exception(msg="Test run cancelled by user")
            except:
                self.logger.exception(msg="An unexpected exception occurred while running tests\n")

        result.stopTestRun(tests)
        ### STOP TESTING ###

        return result
开发者ID:leeping,项目名称:forcebalance,代码行数:58,代码来源:__init__.py


示例8: testRegisterResult

    def testRegisterResult(self):
        result = unittest.TestResult()
        self.assertNotIn(result, unittest.signals._results)

        unittest.registerResult(result)
        try:
            self.assertIn(result, unittest.signals._results)
        finally:
            unittest.removeResult(result)
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:9,代码来源:test_break.py


示例9: testRegisterResult

 def testRegisterResult(self):
     result = unittest.TestResult()
     unittest.registerResult(result)
     for ref in unittest.signals._results:
         if ref is result:
             break
         else:
             while ref is not result:
                 self.fail('odd object in result set')
     self.fail('result not found')
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:10,代码来源:test_break.py


示例10: run

    def run(self,
            test_modules=__all__,
            pretend=False,
            logfile='test/test.log',
            loglevel=logging.INFO,
            **kwargs):

        self.logger.setLevel(loglevel)

        # first install unittest interrupt handler which gracefully finishes current test on Ctrl+C
        unittest.installHandler()

        # create blank test suite and fill it with test suites loaded from each test module
        tests = unittest.TestSuite()
        for module in test_modules:
            try:
                m=__import__(module)
                module_tests=unittest.defaultTestLoader.loadTestsFromModule(m)
                tests.addTest(module_tests)
            except ImportError:
                self.logger.error("No such test module: %s\n" % module)
            except:
                self.logger.critical("Error loading '%s'\n" % module)
                print traceback.print_exc()

        result = ForceBalanceTestResult()

        ### START TESTING ###
        # run any pretest tasks before first test
        result.startTestRun(tests)

        # if pretend option is enabled, skip all tests instead of running them
        if pretend:
            for module in tests:
                for test in module:
                    try:
                        result.addSkip(test)
                    # addSkip will fail if run on TestSuite objects
                    except AttributeError: continue

        # otherwise do a normal test run
        else:
            self.console = sys.stdout
            sys.stdout = open(logfile, 'w')

            unittest.registerResult(result)
            tests.run(result)

            sys.stdout.close()
            sys.stdout = self.console

        result.stopTestRun(tests)
        ### STOP TESTING ###

        return result
开发者ID:rmcgibbo,项目名称:forcebalance,代码行数:55,代码来源:__init__.py


示例11: testRegisterResult

    def testRegisterResult(self):
        result = unittest.TestResult()
        unittest.registerResult(result)

        for ref in unittest.signals._results:
            if ref is result:
                break
            elif ref is not result:
                self.fail("odd object in result set")
        else:
            self.fail("result not found")
开发者ID:1018365842,项目名称:FreeIMU,代码行数:11,代码来源:test_break.py


示例12: testWeakReferences

    def testWeakReferences(self):
        # Calling registerResult on a result should not keep it alive
        result = unittest.TestResult()
        unittest.registerResult(result)

        ref = weakref.ref(result)
        del result

        # For non-reference counting implementations
        gc.collect();gc.collect()
        self.assertIsNone(ref())
开发者ID:1018365842,项目名称:FreeIMU,代码行数:11,代码来源:test_break.py


示例13: testRemoveResult

 def testRemoveResult(self):
     result = unittest.TestResult()
     unittest.registerResult(result)
     unittest.installHandler()
     self.assertTrue(unittest.removeResult(result))
     self.assertFalse(unittest.removeResult(unittest.TestResult()))
     try:
         pid = os.getpid()
         os.kill(pid, signal.SIGINT)
     except KeyboardInterrupt:
         pass
     self.assertFalse(result.shouldStop)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:12,代码来源:test_break.py


示例14: run

 def run(self, test):
     result = self._makeResult()
     # diffs between Python 2.6 and Python 2.7
     if hasattr(unittest, 'registerResult'):
         unittest.registerResult(result)
     if hasattr(result, 'failfast'):
         result.failfast = self.failfast
     if hasattr(result, 'buffer'):
         result.buffer = self.buffer
     test(result)
     self.stream.writeln((_testname + ": %d tests, %d failures, %d errors") %
                         (result.testsRun, len(result.failures), len(result.errors)))
     result.printErrors()
     return result
开发者ID:ChrisX34,项目名称:stuff,代码行数:14,代码来源:testBatch.py


示例15: testInterruptCaught

    def testInterruptCaught(self):
        default_handler = signal.getsignal(signal.SIGINT)
        result = unittest.TestResult()
        unittest.installHandler()
        unittest.registerResult(result)
        self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
            result.breakCaught = True
            self.assertTrue(result.shouldStop)

        try:
            test(result)
        except KeyboardInterrupt:
            self.fail('KeyboardInterrupt not handled')
        self.assertTrue(result.breakCaught)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:18,代码来源:test_break.py


示例16: testSecondInterrupt

    def testSecondInterrupt(self):
        result = unittest.TestResult()
        unittest.installHandler()
        unittest.registerResult(result)

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
            result.breakCaught = True
            self.assertTrue(result.shouldStop)
            os.kill(pid, signal.SIGINT)
            self.fail("Second KeyboardInterrupt not raised")

        try:
            test(result)
        except KeyboardInterrupt:
            pass
        else:
            self.fail("Second KeyboardInterrupt not raised")
        self.assertTrue(result.breakCaught)
开发者ID:1018365842,项目名称:FreeIMU,代码行数:20,代码来源:test_break.py


示例17: testRemoveResult

    def testRemoveResult(self):
        if due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
            return

        result = unittest.TestResult()
        unittest.registerResult(result)

        unittest.installHandler()
        self.assertTrue(unittest.removeResult(result))

        # Should this raise an error instead?
        self.assertFalse(unittest.removeResult(unittest.TestResult()))

        try:
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
        except KeyboardInterrupt:
            pass

        self.assertFalse(result.shouldStop)
开发者ID:jschementi,项目名称:iron,代码行数:20,代码来源:test_break.py


示例18: testSecondInterrupt

    def testSecondInterrupt(self):
        if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
            self.skipTest('test requires SIGINT to not be ignored')
        result = unittest.TestResult()
        unittest.installHandler()
        unittest.registerResult(result)

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
            result.breakCaught = True
            self.assertTrue(result.shouldStop)
            os.kill(pid, signal.SIGINT)
            self.fail('Second KeyboardInterrupt not raised')

        try:
            test(result)
        except KeyboardInterrupt:
            pass
        self.fail('Second KeyboardInterrupt not raised')
        self.assertTrue(result.breakCaught)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:21,代码来源:test_break.py


示例19: run

    def run(self, test):
        "Run the given test case or test suite."
        result = self._result
        unittest.registerResult(result)
        result.failfast = self.failfast
        result.buffer = self.buffer
        startTime = time.time()
        startTestRun = getattr(result, 'startTestRun', None)
        if startTestRun is not None:
            startTestRun()
        try:
            test(result)
        finally:
            stopTime = time.time()
            timeTaken = stopTime - startTime
            setTimes = getattr(result, 'setTimes', None)
            if setTimes is not None:
                setTimes(startTime, stopTime, timeTaken)
            stopTestRun = getattr(result, 'stopTestRun', None)
            if stopTestRun is not None:
                stopTestRun()

        return result
开发者ID:caomw,项目名称:grass,代码行数:23,代码来源:runner.py


示例20: testInterruptCaught

    def testInterruptCaught(self):
        if due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
            return

        default_handler = signal.getsignal(signal.SIGINT)

        result = unittest.TestResult()
        unittest.installHandler()
        unittest.registerResult(result)

        self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
            result.breakCaught = True
            if not due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/28171"):
                self.assertTrue(result.shouldStop)

        try:
            test(result)
        except KeyboardInterrupt:
            self.fail("KeyboardInterrupt not handled")
        self.assertTrue(result.breakCaught)
开发者ID:jschementi,项目名称:iron,代码行数:24,代码来源:test_break.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unittest.removeHandler函数代码示例发布时间:2022-05-27
下一篇:
Python unittest.mock函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap