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


Python unittest2.installHandler函数代码示例

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


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

示例1: testTwoResults

    def testTwoResults(self):
        unittest2.installHandler()

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

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

        result3 = unittest2.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:anupkrish24,项目名称:kaLLogs,代码行数:25,代码来源:test_break.py

示例2: runTests

 def runTests(self):
     if (self.catchbreak
         and getattr(unittest, 'installHandler', None) is not None):
         unittest.installHandler()
     testRunner = self._get_runner()
     self.result = testRunner.run(self.test)
     if self.exit:
         sys.exit(not self.result.wasSuccessful())
开发者ID:jelmer,项目名称:testtools,代码行数:8,代码来源:run.py

示例3: testRemoveHandler

    def testRemoveHandler(self):
        default_handler = signal.getsignal(signal.SIGINT)
        unittest2.installHandler()
        unittest2.removeHandler()
        self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)

        # check that calling removeHandler multiple times has no ill-effect
        unittest2.removeHandler()
        self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
开发者ID:anupkrish24,项目名称:kaLLogs,代码行数:9,代码来源:test_break.py

示例4: testRemoveHandlerAsDecorator

    def testRemoveHandlerAsDecorator(self):
        default_handler = signal.getsignal(signal.SIGINT)
        unittest2.installHandler()

        @unittest2.removeHandler
        def test():
            self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)

        test()
        self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)
开发者ID:anupkrish24,项目名称:kaLLogs,代码行数:10,代码来源:test_break.py

示例5: testInstallHandler

    def testInstallHandler(self):
        default_handler = signal.getsignal(signal.SIGINT)
        unittest2.installHandler()
        self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)

        try:
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
        except KeyboardInterrupt:
            self.fail("KeyboardInterrupt not handled")

        self.assertTrue(unittest2.signals._interrupt_handler.called)
开发者ID:anupkrish24,项目名称:kaLLogs,代码行数:12,代码来源:test_break.py

示例6: testRemoveResult

    def testRemoveResult(self):
        result = unittest2.TestResult()
        unittest2.registerResult(result)

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

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

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

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

示例7: testHandlerReplacedButCalled

 def testHandlerReplacedButCalled(self):
     # If our handler has been replaced (is no longer installed) but is
     # called by the *new* handler, then it isn't safe to delay the
     # SIGINT and we should immediately delegate to the default handler
     unittest2.installHandler()
     
     handler = signal.getsignal(signal.SIGINT)
     def new_handler(frame, signum):
         handler(frame, signum)
     signal.signal(signal.SIGINT, new_handler)
     
     try:
         pid = os.getpid()
         os.kill(pid, signal.SIGINT)
     except KeyboardInterrupt:
         pass
     else:
         self.fail("replaced but delegated handler doesn't raise interrupt")
开发者ID:iadrich,项目名称:jaydebeapi,代码行数:18,代码来源:test_break.py

示例8: run_parallel

    def run_parallel(self, test_suites, test_runner, json_result=False):
        exit_code = 0
        proc = None
        unittest.installHandler()
        processes = []
        manager = Manager()
        results = manager.list()
        start = time.time()

        for test_suite in test_suites:
            proc = Process(target=execute_test, args=(
                test_runner,
                test_suite,
                results))
            processes.append(proc)
            proc.start()

        for proc in processes:
            proc.join()

        finish = time.time()

        errors, failures, _ = dump_results(start, finish, results)

        if json_result:
            all_results = []
            for tests, result in zip(test_suites, results):
                result_parser = SummarizeResults(
                    vars(result),
                    tests,
                    (finish - start))
                all_results += result_parser.gather_results()

            # Convert Result objects to dicts for serialization
            json_results = []
            for r in all_results:
                json_results.append(r.__dict__)
            with open(os.getcwd() + "/results.json", 'wb') as result_file:
                json.dump(json_results, result_file)

        if failures or errors:
            exit_code = 1

        return exit_code
开发者ID:ProjectMeniscus,项目名称:opencafe,代码行数:44,代码来源:runner.py

示例9: run_parallel

    def run_parallel(self, test_suites, test_runner, result_type=None,
                     results_path=None):
        exit_code = 0
        proc = None
        unittest.installHandler()
        processes = []
        manager = Manager()
        results = manager.list()
        start = time.time()

        for test_suite in test_suites:
            proc = Process(target=execute_test, args=(
                test_runner,
                test_suite,
                results))
            processes.append(proc)
            proc.start()

        for proc in processes:
            proc.join()

        finish = time.time()

        errors, failures, _ = dump_results(start, finish, results)

        if result_type is not None:
            all_results = []
            for tests, result in zip(test_suites, results):
                result_parser = SummarizeResults(
                    vars(result),
                    tests,
                    (finish - start))
                all_results += result_parser.gather_results()

            reporter = Reporter(result_parser=result_parser,
                                all_results=all_results)
            reporter.generate_report(result_type=result_type,
                                     path=results_path)

        if failures or errors:
            exit_code = 1

        return exit_code
开发者ID:peterhowells,项目名称:opencafe,代码行数:43,代码来源:runner.py

示例10: testSecondInterrupt

 def testSecondInterrupt(self):
     result = unittest2.TestResult()
     unittest2.installHandler()
     unittest2.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:iadrich,项目名称:jaydebeapi,代码行数:20,代码来源:test_break.py

示例11: testInterruptCaught

    def testInterruptCaught(self):
        default_handler = signal.getsignal(signal.SIGINT)

        result = unittest2.TestResult()
        unittest2.installHandler()
        unittest2.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:anupkrish24,项目名称:kaLLogs,代码行数:20,代码来源:test_break.py

示例12: testHandlerReplacedButCalled

    def testHandlerReplacedButCalled(self):
        # Can't use skipIf decorator because the signal handler may have
        # been changed after defining this method.
        if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
            self.skipTest("test requires SIGINT to not be ignored")
        # If our handler has been replaced (is no longer installed) but is
        # called by the *new* handler, then it isn't safe to delay the
        # SIGINT and we should immediately delegate to the default handler
        unittest2.installHandler()

        handler = signal.getsignal(signal.SIGINT)
        def new_handler(frame, signum):
            handler(frame, signum)
        signal.signal(signal.SIGINT, new_handler)

        try:
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
        except KeyboardInterrupt:
            pass
        else:
            self.fail("replaced but delegated handler doesn't raise interrupt")
开发者ID:anupkrish24,项目名称:kaLLogs,代码行数:22,代码来源:test_break.py

示例13: run_serialized

    def run_serialized(self, master_suite, test_runner, result_type=None,
                       results_path=None):
        exit_code = 0
        unittest.installHandler()
        start_time = time.time()
        result = test_runner.run(master_suite)
        total_execution_time = time.time() - start_time

        if result_type is not None:
            result_parser = SummarizeResults(vars(result), master_suite,
                                             total_execution_time)
            all_results = result_parser.gather_results()
            reporter = Reporter(result_parser=result_parser,
                                all_results=all_results)
            reporter.generate_report(result_type=result_type,
                                     path=results_path)

        log_results(result)
        if not result.wasSuccessful():
            exit_code = 1

        return exit_code
开发者ID:peterhowells,项目名称:opencafe,代码行数:22,代码来源:runner.py

示例14: testSecondInterrupt

    def testSecondInterrupt(self):
        # Can't use skipIf decorator because the signal handler may have
        # been changed after defining this method.
        if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
            self.skipTest("test requires SIGINT to not be ignored")
        result = unittest2.TestResult()
        unittest2.installHandler()
        unittest2.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:anupkrish24,项目名称:kaLLogs,代码行数:24,代码来源:test_break.py

示例15: run_serialized

    def run_serialized(self, master_suite, test_runner, json_result=False):
        exit_code = 0
        unittest.installHandler()
        start_time = time.time()
        result = test_runner.run(master_suite)
        total_execution_time = time.time() - start_time

        if json_result:
            result_parser = SummarizeResults(vars(result), master_suite,
                                             total_execution_time)
            all_results = result_parser.gather_results()

            # Convert Result objects to dicts for serialization
            json_results = []
            for r in all_results:
                json_results.append(r.__dict__)
            with open(os.getcwd() + "/results.json", 'wb') as result_file:
                json.dump(json_results, result_file)

        log_results(result)
        if not result.wasSuccessful():
            exit_code = 1

        return exit_code
开发者ID:ProjectMeniscus,项目名称:opencafe,代码行数:24,代码来源:runner.py


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