本文整理匯總了Python中exceptions.SystemExit方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.SystemExit方法的具體用法?Python exceptions.SystemExit怎麽用?Python exceptions.SystemExit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類exceptions
的用法示例。
在下文中一共展示了exceptions.SystemExit方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_with_processors
# 需要導入模塊: import exceptions [as 別名]
# 或者: from exceptions import SystemExit [as 別名]
def handle_with_processors(self):
def process(processors):
try:
if processors:
p, processors = processors[0], processors[1:]
return p(lambda: process(processors))
else:
return self.handle()
except web.HTTPError:
raise
except (KeyboardInterrupt, SystemExit):
raise
except:
print >> web.debug, traceback.format_exc()
raise self.internalerror()
# processors must be applied in the resvere order. (??)
return process(self.processors)
示例2: get_argparse_error
# 需要導入模塊: import exceptions [as 別名]
# 或者: from exceptions import SystemExit [as 別名]
def get_argparse_error(args):
"""When argparse raises an error it writes to stderr and does a sys.exit"""
with mock.patch('sys.stderr', io.StringIO()) as output:
try:
result = main([sys.argv[0], ] + args)
raise Exception("Expected a fail")
except exc.SystemExit:
pass
return output.getvalue()
示例3: run_test_pkg
# 需要導入模塊: import exceptions [as 別名]
# 或者: from exceptions import SystemExit [as 別名]
def run_test_pkg(pkg_name, do_not_run=[]):
log_info("--%s package----------------------------------------" % pkg_name)
#Determine where the test package is and ensure it exists
log_debug("The current working directory is " + __CWD)
pkg_dir_name = os.path.join(__CWD, pkg_name.replace(".", os.sep))
log_debug("The test package location is " + pkg_dir_name)
if not file_exists(os.path.join(pkg_dir_name, "__init__.py")):
err_msg = "No such test package: %s" % pkg_dir_name
log_error(err_msg)
raise Exception(err_msg)
#Build up a list of all subpackages/modules contained in test package
subpkg_list = [x for x in os.listdir(pkg_dir_name) if not x.endswith(".py") and file_exists(os.path.join(pkg_dir_name, x, "__init__.py"))]
log_debug("Subpackages found: %s" % (str(subpkg_list)))
module_list = [x for x in os.listdir(pkg_dir_name) if x.endswith(".py") and x!="__init__.py"]
log_debug("Modules found: %s" % (str(module_list)))
if len(module_list)==0:
log_warn("No test modules found in the %s test package!" % pkg_name)
print ""
if options.GEN_TEST_PLAN:
l.info("Generating test documentation for '%s' package..." % pkg_name)
pydoc.writedoc(pkg_name)
#Import all tests
for test_module in module_list:
test_module = pkg_name + "." + test_module.split(".py", 1)[0]
if options.RUN_TESTS:
if test_module in do_not_run:
log_info("--Testing of %s has been disabled!" % test_module)
continue
log_info("--Testing %s..." % test_module)
try:
__import__(test_module)
except SystemExit, e:
if e.code!=0:
raise Exception("Importing '%s' caused an unexpected exit code: %s" % (test_module, str(e.code)))
print ""
if options.GEN_TEST_PLAN:
l.info("Generating test documentation for '%s' module..." % test_module)
pydoc.writedoc(test_module)
#Recursively import subpackages
示例4: run_test_pkg
# 需要導入模塊: import exceptions [as 別名]
# 或者: from exceptions import SystemExit [as 別名]
def run_test_pkg(pkg_name, do_not_run=[]):
log_info("--%s package----------------------------------------" % pkg_name)
#Determine where the test package is and ensure it exists
log_debug("The current working directory is " + __CWD)
pkg_dir_name = os.path.join(__CWD, pkg_name.replace(".", os.sep))
log_debug("The test package location is " + pkg_dir_name)
if not file_exists(os.path.join(pkg_dir_name, "__init__.py")):
err_msg = "No such test package: %s" % pkg_dir_name
log_error(err_msg)
raise Exception(err_msg)
#Build up a list of all subpackages/modules contained in test package
subpkg_list = [x for x in os.listdir(pkg_dir_name) if not x.endswith(".py") and file_exists(os.path.join(pkg_dir_name, x, "__init__.py"))]
log_debug("Subpackages found: %s" % (str(subpkg_list)))
module_list = [x for x in os.listdir(pkg_dir_name) if x.endswith(".py") and x!="__init__.py"]
log_debug("Modules found: %s" % (str(module_list)))
if len(module_list)==0:
log_warn("No test modules found in the %s test package!" % pkg_name)
print("")
if options.GEN_TEST_PLAN:
l.info("Generating test documentation for '%s' package..." % pkg_name)
pydoc.writedoc(pkg_name)
#Import all tests
for test_module in module_list:
test_module = pkg_name + "." + test_module.split(".py", 1)[0]
if options.RUN_TESTS:
if test_module in do_not_run:
log_info("--Testing of %s has been disabled!" % test_module)
continue
log_info("--Testing %s..." % test_module)
try:
__import__(test_module)
except SystemExit as e:
if e.code!=0:
raise Exception("Importing '%s' caused an unexpected exit code: %s" % (test_module, str(e.code)))
print("")
if options.GEN_TEST_PLAN:
l.info("Generating test documentation for '%s' module..." % test_module)
pydoc.writedoc(test_module)
#Recursively import subpackages
for subpkg in subpkg_list:
run_test_pkg(pkg_name + "." + subpkg)