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

Python unittest.installHandler函数代码示例

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

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



在下文中一共展示了installHandler函数的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: __init__

    def __init__(self, tests=[], from_gui=False, categories=['system', 'unit', 'gui', 'verification'], timing=False):
        """Store the list of tests to preform.

        The test list should be something like ['N_state_model.test_stereochem_analysis'].  The first part is the imported test case class, the second is the specific test.


        @keyword tests:         The list of tests to preform.  If left at [], then all tests will be run.
        @type tests:            list of str
        @keyword from_gui:      A flag which indicates if the tests are being run from the GUI or not.
        @type from_gui:         bool
        @keyword categories:    The list of test categories to run, for example ['system', 'unit', 'gui', 'verification'] for all tests.
        @type categories:       list of str
        @keyword timing:        A flag which if True will enable timing of individual tests.
        @type timing:           bool
        """

        # Store the args.
        self.tests = tests
        self.from_gui = from_gui
        self.categories = categories

        # Set up the test runner.
        if from_gui:
            self.runner = GuiTestRunner(stream=sys.stdout, timing=timing)
        else:
            self.runner = RelaxTestRunner(stream=sys.stdout, timing=timing)

        # Let the tests handle the keyboard interrupt (for Python 2.7 and higher).
        if hasattr(unittest, 'installHandler'):
            unittest.installHandler()
开发者ID:pombredanne,项目名称:relax,代码行数:30,代码来源:test_suite_runner.py


示例4: 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


示例5: testRemoveHandler

 def testRemoveHandler(self):
     default_handler = signal.getsignal(signal.SIGINT)
     unittest.installHandler()
     unittest.removeHandler()
     self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
     unittest.removeHandler()
     self.assertEqual(signal.getsignal(signal.SIGINT), default_handler)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:7,代码来源:test_break.py


示例6: run

 def run(self):    
   build = self.get_finalized_command("build")
   build.run()
   
   if self.catch:
     unittest.installHandler()
   
   sys.path.insert(0, str(Path(build.build_lib).resolve()))
   
   test_loader = unittest.defaultTestLoader
   
   if self.test_name:
     tests = test_loader.loadTestsFromName(self.test_name, None)
   else:
     tests = test_loader.discover(self.start_dir, self.pattern)
   
   test_runner = unittest.TextTestRunner(
     verbosity = self.verbose,
     failfast = self.failfast,
     buffer = self.buffer
   )
   
   test_results = test_runner.run(tests)
     
   del sys.path[0]
   
   if self.exit and not test_results.wasSuccessful():
     raise SystemExit()
开发者ID:jashandeep-sohi,项目名称:python-blowfish,代码行数:28,代码来源:dist.py


示例7: run

    def run(self):
        try:
            import coverage
            use_cov = True
        except:
            use_cov = False
            cov = None

        if use_cov:
            # The latter is required to not give errors on f23, probably
            # a temporary bug.
            omit = ["/usr/*", "/*/tests/*", "/builddir/*"]
            cov = coverage.coverage(omit=omit)
            cov.erase()
            cov.start()

        import tests as testsmodule
        testsmodule.cov = cov
        testsmodule.utils.REGENERATE_OUTPUT = bool(self.regenerate_output)

        if hasattr(unittest, "installHandler"):
            try:
                unittest.installHandler()
            except:
                print "installHandler hack failed"

        tests = unittest.TestLoader().loadTestsFromNames(self._testfiles)
        if self.only:
            newtests = []
            for suite1 in tests:
                for suite2 in suite1:
                    for testcase in suite2:
                        if self.only in str(testcase):
                            newtests.append(testcase)

            if not newtests:
                print "--only didn't find any tests"
                sys.exit(1)
            tests = unittest.TestSuite(newtests)
            print "Running only:"
            for test in newtests:
                print "%s" % test
            print

        t = unittest.TextTestRunner(verbosity=1)

        try:
            result = t.run(tests)
        except KeyboardInterrupt:
            sys.exit(1)

        if use_cov:
            cov.stop()
            cov.save()

        err = int(bool(len(result.failures) > 0 or
                       len(result.errors) > 0))
        if not err and use_cov and self.coverage:
            cov.report(show_missing=False)
        sys.exit(err)
开发者ID:rowhit,项目名称:virt-manager,代码行数:60,代码来源:setup.py


示例8: run

    def run(self):
        try:
            # Use system 'coverage' if available
            import coverage
            use_coverage = True
        except:
            use_coverage = False

        tests = unittest.TestLoader().loadTestsFromNames(self._testfiles)
        t = unittest.TextTestRunner(verbosity=1)

        if use_coverage:
            coverage.erase()
            coverage.start()

        if hasattr(unittest, "installHandler"):
            try:
                unittest.installHandler()
            except:
                print "installHandler hack failed"

        try:
            result = t.run(tests)
        except KeyboardInterrupt:
            sys.exit(1)

        if use_coverage:
            coverage.stop()

        sys.exit(int(bool(len(result.failures) > 0 or
                          len(result.errors) > 0)))
开发者ID:aliceinwire,项目名称:virt-manager,代码行数:31,代码来源:setup.py


示例9: runTests

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


示例10: run_tests

def run_tests(file):
    suite = get_tests_suite(file)
    unittest.installHandler()
    logging.disable(logging.INFO)
    results = unittest.TextTestRunner(verbosity=2).run(suite)
    logging.disable(logging.NOTSET)
    unittest.removeHandler()
    return results
开发者ID:jererc,项目名称:tracy-py,代码行数:8,代码来源:test.py


示例11: 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


示例12: run_tests

def run_tests(options, testsuite, runner=None):
    if runner is None:
        runner = unittest.TextTestRunner()
        runner.verbosity = options.verbose
        runner.failfast = options.failfast
    if options.catchbreak:
        unittest.installHandler()
    result = runner.run(testsuite)
    return result.wasSuccessful()
开发者ID:benkirk,项目名称:mpi_playground,代码行数:9,代码来源:runtests.py


示例13: main

def main():
    installHandler()
    option_parser = optparse.OptionParser(
        usage="%prog [options] [filenames]",
        description="pyjaco unittests script."
        )
    option_parser.add_option(
        "-a",
        "--run-all",
        action="store_true",
        dest="run_all",
        default=False,
        help="run all tests (including the known-to-fail)"
        )
    option_parser.add_option(
        "-x",
        "--no-error",
        action="store_true",
        dest="no_error",
        default=False,
        help="ignores error (don't display them after tests)"
        )
    option_parser.add_option(
        "-f",
        "--only-failing",
        action="store_true",
        dest="only_failing",
        default=False,
        help="run only failing tests (to check for improvements)"
        )
    options, args = option_parser.parse_args()
    
    with open("py-builtins.js", "w") as f:
        builtins = BuiltinGenerator().generate_builtins()
        f.write(builtins)
    
    runner = testtools.runner.Py2JsTestRunner(verbosity=2)
    results = None
    try:
        if options.run_all:
            results = runner.run(testtools.tests.ALL)
        elif options.only_failing:
            results = runner.run(testtools.tests.KNOWN_TO_FAIL)
        elif args:
            results = runner.run(testtools.tests.get_tests(args))
        else:
            results = runner.run(testtools.tests.NOT_KNOWN_TO_FAIL)
    except KeyboardInterrupt:
        pass
    if not options.no_error and results and results.errors:
        print
        print "errors:"
        print "  (use -x to skip this part)"
        for test, error in results.errors:
            print
            print "*", str(test), "*"
            print error
开发者ID:neoel,项目名称:pyjaco,代码行数:57,代码来源:run_tests.py


示例14: testRemoveHandler

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

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


示例15: testRemoveHandlerAsDecorator

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

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

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


示例16: testInstallHandler

 def testInstallHandler(self):
     default_handler = signal.getsignal(signal.SIGINT)
     unittest.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(unittest.signals._interrupt_handler.called)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:10,代码来源:test_break.py


示例17: do

    def do(self):
        if self.catchbreak and getattr(unittest, 'installHandler', None):
            unittest.installHandler()

        ClusterFixture.env = self.get_environment()

        runner = TestToolsTestRunner(sys.stdout)
        results = runner.run(self.get_tests())

        sys.exit(not results.wasSuccessful())
开发者ID:isotoma,项目名称:sidekick,代码行数:10,代码来源:test.py


示例18: 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


示例19: run_tests

    def run_tests(self, test_suite):
        # Install a signal handler to catch Ctrl-C and display the results
        # (but only if running >2.6).
        if sys.version_info[0] > 2 or sys.version_info[1] > 6:
            unittest.installHandler()

        # Run the tests
        runner = FbJsonTestRunner(verbosity=self.options.verbosity)
        result = runner.run(test_suite)

        return result
开发者ID:disigma,项目名称:buck,代码行数:11,代码来源:__test_main__.py


示例20: 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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python unittest.main函数代码示例发布时间:2022-05-27
下一篇:
Python unittest.getTestCaseNames函数代码示例发布时间: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