本文整理汇总了Python中t.raises函数的典型用法代码示例。如果您正苦于以下问题:Python raises函数的具体用法?Python raises怎么用?Python raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raises函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_counter_eq_derive
def test_counter_eq_derive():
"""Test parsing of counters when expecting derives and vice versa"""
def run_parse(parse_func):
def wrapped(data):
return list(parse_func(data))
return wrapped
types = "false_counter value:COUNTER:U:U\nfalse_derive value:DERIVE:U:U\n"
with t.unlinking(t.temp_file(TYPESDB + types)) as path:
parser = bucky.collectd.CollectDParser(types_dbs=[path])
for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts'):
for data in pkts(pkts_file):
t.not_raises(ProtocolError, run_parse(parser.parse), data)
for pkts_file in ('collectd-false-counter.pkts',
'collectd-false-derive.pkts'):
for data in pkts(pkts_file):
t.raises(ProtocolError, run_parse(parser.parse), data)
parser = bucky.collectd.CollectDParser(types_dbs=[path],
counter_eq_derive=True)
for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts',
'collectd-false-counter.pkts',
'collectd-false-derive.pkts'):
for data in pkts(pkts_file):
t.not_raises(ProtocolError, run_parse(parser.parse), data)
示例2: test_set_item
def test_set_item():
fl = t.FileList("a.c", "b.c")
fl[0] = "foo.py"
t.eq(fl, ["foo.py", "b.c"])
def assign():
fl[1] = 2
t.raises(TypeError, assign)
示例3: test_exp_02
def test_exp_02():
with mock.patch.object(SyncthingClient, 'request') as mock_response:
code = 500
msg = 'Error occured'
mock_response.side_effect = PySyncthingError(code=code, message=msg)
api = SyncthingClient(TOKEN, BASE_URL)
t.raises(PySyncthingError, api.get_version)
示例4: test_not_synthed
def test_not_synthed():
@t.synth()
def synth(task):
task.synth(t.tmpfname())
t.raises(t.FileSynthError, t.app.run, None, ["synth"])
示例5: test_del_item
def test_del_item():
fl = t.FileList("a.c", "b.c")
del fl[0]
t.eq(fl[0], "b.c")
def rem():
del fl[2]
t.raises(IndexError, rem)
示例6: test_two_task_cycle
def test_two_task_cycle():
t.task("foo", ["bar"])(lambda: 2)
t.task("bar", ["foo"])(lambda: "hi")
for task in ["foo", "bar"]:
t.app.clear()
t.raises(t.DependencyCycleError, t.app.run, None, [task])
t.eq(t.app._dbg, [])
示例7: test_simple_ns
def test_simple_ns():
with t.ns("rho"):
@t.task
def foo():
return 2
t.raises(t.TaskNotFoundError, t.app.run, None, ["foo"])
t.app.run(None, ["rho:foo"])
t.eq(t.app._dbg, [("rho:foo", 2)])
示例8: test_date_errors
def test_date_errors():
# Disallowed by iso8601 to avoid confusion with YYMMDD
t.raises(FMT_ERROR, pdate, "195406")
t.raises(FMT_ERROR, pdate, "foo")
t.raises(FMT_ERROR, pdate, "1954-0607")
t.raises(FMT_ERROR, pdate, "195406-07")
t.raises(FMT_ERROR, pdate, "1954")
示例9: test_exp_01
def test_exp_01():
with mock.patch.object(SyncthingClient, 'request') as mock_response:
code = 500
msg = 'Error occured'
mock_response.status_int = code
mock_response.body_string.return_value = msg
api = SyncthingClient(TOKEN, BASE_URL)
t.raises(PySyncthingError, api.get_version)
示例10: test_callable_validation
def test_callable_validation():
c = config.Config()
def func(a, b):
pass
c.set("pre_fork", func)
t.eq(c.pre_fork, func)
t.raises(TypeError, c.set, "pre_fork", 1)
t.raises(TypeError, c.set, "pre_fork", lambda x: True)
示例11: test_020
def test_020():
u = "http://test:[email protected]%s:%s/auth" % (HOST, PORT)
res = Resource(u)
r = res.get()
t.eq(r.status_int, 200)
u = "http://test:[email protected]%s:%s/auth" % (HOST, PORT)
res = Resource(u)
t.raises(Unauthorized, res.get)
示例12: test_ident_unknown
def test_ident_unknown(conn, cursor):
obj = {"name": "test", "sql": "select 1 as ${'zing' | ident}"}
s = t.Statement(obj)
t.raises(t.RenderError, s.dbs[None].prepare, conn, {})
try:
s.dbs[None].prepare(conn, {})
except t.RenderError, e:
str(e) # Doesn't raise
示例13: test_iter
def test_iter():
fl = t.FileList("a.c", "b.c", "exist*")
i = iter(fl)
t.eq(isinstance(i, t.FileListIter), True)
t.eq(i.next(), "a.c")
t.eq(isinstance(i.next(), t.path), True)
t.eq(i.next(), "existing")
t.raises(StopIteration, i.next)
示例14: test_exceed_time
def test_exceed_time(cx):
script = """
var time = function() {return (new Date()).getTime();};
var start = time();
while((time() - start) < 100000) {}
"""
cx.max_time(1)
t.raises(SystemError, cx.execute, script)
示例15: test_ident_no_dbinfo
def test_ident_no_dbinfo(conn, cursor):
info = t.dbwrapper.DB_INFO["sqlite"]
try:
t.dbwrapper.DB_INFO.pop("sqlite")
obj = {"name": "test", "sql": "select 1 as ${foo | ident}"}
s = t.Statement(obj)
t.raises(KeyError, s.dbs[None].prepare, conn, {"foo": "zip"})
finally:
t.dbwrapper.DB_INFO["sqlite"] = info