本文整理汇总了Python中unittest2.installHandler函数的典型用法代码示例。如果您正苦于以下问题:Python installHandler函数的具体用法?Python installHandler怎么用?Python installHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了installHandler函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: run
#.........这里部分代码省略.........
if cl_args.packages is None:
for module in self.get_modules(repo_path, module_regex):
try:
loaded_module = self.load_module(module)
except ImportError:
self.print_traceback()
continue
try:
suite = self.build_suite(loaded_module, method_regex, cl_args.tags, cl_args.supress_flag)
master_suite.addTests(suite)
test_classes.append(suite)
except ImportError:
self.print_traceback()
continue
except AttributeError:
self.print_traceback()
continue
except Exception:
self.print_traceback()
continue
else:
for package_name in cl_args.packages:
test_path = self.find_subdir(repo_path, package_name)
if test_path is None:
err_msg = self.error_msg("Package", package_name)
print self.colorize(err_msg, HIGHLIGHTED_RED)
continue
for module_path in self.get_modules(test_path, module_regex):
try:
loaded_module = self.load_module(module_path)
except ImportError:
self.print_traceback()
continue
try:
suite = self.build_suite(loaded_module, method_regex, cl_args.tags, cl_args.supress_flag)
master_suite.addTests(suite)
test_classes.append(suite)
except ImportError:
self.print_traceback()
continue
except AttributeError:
self.print_traceback()
continue
except Exception:
self.print_traceback()
continue
if cl_args.parallel:
unittest.installHandler()
processes = []
manager = Manager()
results = manager.list()
start = time.time()
for test in test_classes:
p = Process(target=execute_test, args=(test_runner, test, results))
processes.append(p)
p.start()
for p in processes:
p.join()
finish = time.time()
print "=" * 71
print "Tests Complete."
print "=" * 71
run = 0
errors = 0
failures = 0
for result in results:
run += result.testsRun
errors += len(result.errors)
failures += len(result.failures)
print ("Ran %d test%s in %.3fs" % (run, run != 1 and "s" or "", finish - start))
if failures:
print ("Failures=%d" % failures)
if errors:
print ("Errors=%d" % errors)
if failures or errors:
exit(1)
else:
unittest.installHandler()
start_time = time.time()
result = test_runner.run(master_suite)
total_execution_time = time.time() - start_time
if cl_args.generateXML is not None:
xml_path = "".join([parent_path, cl_args.generateXML])
parse_res = ParseResult(vars(result), master_suite, xml_path, total_execution_time)
parse_res.generate_xml_report()
self.log_results(result)
if not result.wasSuccessful():
exit(1)
开发者ID:Alger,项目名称:opencafe,代码行数:101,代码来源:runner.py
示例17: run
#.........这里部分代码省略.........
continue
except Exception:
self.print_traceback()
continue
else:
for package_name in cl_args.packages:
test_path = self.find_subdir(repo_path, package_name)
if test_path is None:
err_msg = self.error_msg('Package', package_name)
print err_msg
continue
for module_path in self.get_modules(test_path,
module_regex):
try:
loaded_module = self.load_module(module_path)
except ImportError:
self.print_traceback()
continue
try:
suite = self.build_suite(loaded_module,
method_regex,
cl_args.tags,
cl_args.supress_flag)
master_suite.addTests(suite)
test_classes.append(suite)
except ImportError:
self.print_traceback()
continue
except AttributeError:
self.print_traceback()
continue
except Exception:
self.print_traceback()
continue
if cl_args.parallel:
unittest.installHandler()
processes = []
manager = Manager()
results = manager.list()
start = time.time()
for test in test_classes:
proc = Process(target=execute_test, args=(test_runner,
test, results))
processes.append(proc)
proc.start()
for proc in processes:
proc.join()
finish = time.time()
print '-' * 71
run = 0
errors = 0
failures = 0
for result in results:
run += result.testsRun
errors += len(result.errors)
failures += len(result.failures)
print ("Ran %d test%s in %.3fs" % (run,
run != 1 and "s" or "",
finish - start))
fail = ''
error = ''
space = ''
if failures:
fail = "Failures=%d" % failures
if errors:
error = "Errors=%d" % errors
if failures or errors:
if failures and errors:
space = ' '
print
print 'FAILED ({}{}{})'.format(fail, space, error)
exit(1)
else:
unittest.installHandler()
start_time = time.time()
result = test_runner.run(master_suite)
total_execution_time = time.time() - start_time
if cl_args.generateXML is not None:
xml_path = ''.join([parent_path, cl_args.generateXML])
parse_res = ParseResult(vars(result), master_suite,
xml_path, total_execution_time)
parse_res.generate_xml_report()
log_results(result)
if not result.wasSuccessful():
exit(1)
开发者ID:jmvrbanac,项目名称:opencafe,代码行数:101,代码来源:runner.py
示例18: optparse_callback_catch_keyboard_interrupt
def optparse_callback_catch_keyboard_interrupt(*args, **kwargs):
unittest.installHandler()
开发者ID:nesi,项目名称:irods,代码行数:2,代码来源:run_tests.py
注:本文中的unittest2.installHandler函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论