本文整理汇总了Python中exceptions.Exception方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.Exception方法的具体用法?Python exceptions.Exception怎么用?Python exceptions.Exception使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exceptions
的用法示例。
在下文中一共展示了exceptions.Exception方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_str2
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def test_str2(self):
# verify we can assign to sys.exc_*
sys.exc_traceback = None
sys.exc_value = None
sys.exc_type = None
self.assertEqual(str(Exception()), '')
@skipUnlessIronPython()
def test_array(self):
import System
try:
a = System.Array()
except Exception, e:
self.assertEqual(e.__class__, TypeError)
else:
示例2: test_module_exceptions
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def test_module_exceptions(self):
"""verify exceptions in modules are like user defined exception objects, not built-in types."""
# these modules have normal types...
normal_types = ['sys', 'clr', 'exceptions', '__builtin__', '_winreg', 'mmap', 'nt', 'posix']
builtins = [x for x in sys.builtin_module_names if x not in normal_types ]
for module in builtins:
mod = __import__(module)
for attrName in dir(mod):
val = getattr(mod, attrName)
if isinstance(val, type) and issubclass(val, Exception):
if "BlockingIOError" not in repr(val):
self.assertTrue(repr(val).startswith("<class "))
val.x = 2
self.assertEqual(val.x, 2)
else:
self.assertTrue(repr(val).startswith("<type "))
示例3: determine_jdk_directory
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def determine_jdk_directory(cluster):
"""
Return the directory where the JDK is installed. For example if the JDK is
located in /usr/java/jdk1.8_91, then this method will return the string
'jdk1.8_91'.
This method will throw an Exception if the number of JDKs matching the
/usr/java/jdk* pattern is not equal to 1.
:param cluster: cluster on which to search for the JDK directory
"""
number_of_jdks = cluster.exec_cmd_on_host(cluster.master, 'bash -c "ls -ld /usr/java/j*| wc -l"')
if int(number_of_jdks) != 1:
raise Exception('The number of JDK directories matching /usr/java/jdk* is not 1')
output = cluster.exec_cmd_on_host(cluster.master, 'ls -d /usr/java/j*')
return output.split(os.path.sep)[-1].strip('\n')
示例4: __init__
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def __init__(self, param):
self._source_fn = param.get('source')
self._label_fn = param.get('labels')
# bcf_mode: either FILE or MEM, default=FILE
self._bcf_mode = param.get('bcf_mode', 'FILE')
if not os.path.isfile(self._source_fn) or \
not os.path.isfile(self._label_fn):
raise Exception("Either Source of Label file does not exist")
else:
if self._bcf_mode == 'MEM':
self._bcf = bcf_store_memory(self._source_fn)
elif self._bcf_mode == 'FILE':
self._bcf = bcf_store_file(self._source_fn)
self._data = []
self._labels = []
示例5: load_all
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def load_all(self):
"""The function to load all data and labels
Give:
data: the list of raw data, needs to be decompressed
(e.g., raw JPEG string)
labels: numpy array, with each element is a string
"""
start = time.time()
print("Start Loading Data from BCF {}".format(
'MEMORY' if self._bcf_mode == 'MEM' else 'FILE'))
self._labels = np.loadtxt(self._label_fn).astype(str)
if self._bcf.size() != self._labels.shape[0]:
raise Exception("Number of samples in data"
"and labels are not equal")
else:
for idx in range(self._bcf.size()):
datum_str = self._bcf.get(idx)
self._data.append(datum_str)
end = time.time()
print("Loading {} samples Done: Time cost {} seconds".format(
len(self._data), end - start))
return self._data, self._labels
示例6: test_exception_line_no_with_finally
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def test_exception_line_no_with_finally(self):
def f():
try:
raise Exception() # this line should correspond w/ the number below
finally:
pass
try:
f()
except Exception, e:
tb = sys.exc_info()[2]
expected = [24, 29]
while tb:
self.assertEqual(tb.tb_lineno, expected.pop()) # adding lines will require an update here
tb = tb.tb_next
示例7: test_nested_exceptions
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def test_nested_exceptions(self):
try:
raise Exception()
except Exception, e:
# PushException
try:
raise TypeError
except TypeError, te:
# PushException
ei = sys.exc_info()
# PopException
示例8: test_newstyle_raise
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def test_newstyle_raise(self):
# raise a new style exception via raise type, value that returns an arbitrary object
class MyException(Exception):
def __new__(cls, *args): return 42
try:
raise MyException, 'abc'
self.assertUnreachable()
except Exception, e:
self.assertEqual(e, 42)
示例9: test_exception_doc
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def test_exception_doc(self):
# should be accessible, CPython and IronPython have different strings though.
Exception().__doc__
Exception("abc").__doc__
示例10: test_derived_keyword_args
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def test_derived_keyword_args(self):
class ED(Exception):
def __init__(self, args=''):
pass
self.assertEqual(type(ED(args='')), ED)
示例11: test_issue1164
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def test_issue1164(self):
class error(Exception):
pass
def f():
raise (error,), 0
self.assertRaises(error, f)
示例12: check
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def check(host, port, timeout=5):
info = ''
not_unauth_list = []
weak_auth_list = []
userlist = ['test', 'root', 'www', 'web', 'rsync', 'admin']
if __name__ == '__main__':
passwdlist = ['test', 'neagrle']
else:
passwdlist = PASSWORD_DIC
try:
rwc = RsyncWeakCheck(host,port)
for path_name in rwc.get_all_pathname():
ret = rwc.is_path_not_auth(path_name)
if ret == 0:
not_unauth_list.append(path_name)
elif ret == 1:
for username, passwd in product(userlist, passwdlist):
try:
res = rwc.weak_passwd_check(path_name, username, passwd)
if res:
weak_auth_list.append((path_name, username, passwd))
except VersionNotSuppError as e:
# TODO fengxun error support
pass
except Exception, e:
pass
示例13: testBasicChrome
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def testBasicChrome(self):
builder = trace_data.TraceDataBuilder()
builder.AddTraceFor(trace_data.CHROME_TRACE_PART,
{'traceEvents': [1, 2, 3]})
d = builder.AsData()
self.assertTrue(d.HasTracesFor(trace_data.CHROME_TRACE_PART))
self.assertRaises(Exception, builder.AsData)
示例14: testSetTraceForRaisesAfterAsData
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def testSetTraceForRaisesAfterAsData(self):
builder = trace_data.TraceDataBuilder()
builder.AsData()
self.assertRaises(
exceptions.Exception,
lambda: builder.AddTraceFor(trace_data.TELEMETRY_PART, {}))
示例15: getCallString
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import Exception [as 别名]
def getCallString(level):
#this gets us the frame of the caller and will work
#in python versions 1.5.2 and greater (there are better
#ways starting in 2.1
try:
raise FakeException("this is fake")
except Exception, e:
#get the current execution frame
f = sys.exc_info()[2].tb_frame
#go back as many call-frames as was specified