当前位置: 首页>>代码示例>>Python>>正文


Python t.raises函数代码示例

本文整理汇总了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)
开发者ID:dimrozakis,项目名称:bucky,代码行数:27,代码来源:test_002_collectd.py

示例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)
开发者ID:GaelVaroquaux,项目名称:smithy,代码行数:7,代码来源:100-file-list-tests.py

示例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)
开发者ID:arnaudmorin,项目名称:pysyncthing,代码行数:7,代码来源:001-test-pysyncthing.py

示例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"])
    
开发者ID:GaelVaroquaux,项目名称:smithy,代码行数:6,代码来源:008-synth-task-tests.py

示例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)
开发者ID:GaelVaroquaux,项目名称:smithy,代码行数:7,代码来源:100-file-list-tests.py

示例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, [])
开发者ID:GaelVaroquaux,项目名称:smithy,代码行数:8,代码来源:003-dep-cycle-tests.py

示例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)])
开发者ID:GaelVaroquaux,项目名称:smithy,代码行数:8,代码来源:005-namespace-tests.py

示例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")
开发者ID:pombredanne,项目名称:sheba,代码行数:8,代码来源:005-util-test.py

示例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)
开发者ID:arnaudmorin,项目名称:pysyncthing,代码行数:8,代码来源:001-test-pysyncthing.py

示例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)
开发者ID:bbroad,项目名称:gunicorn,代码行数:8,代码来源:003-test-config.py

示例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)
开发者ID:czue,项目名称:restkit,代码行数:8,代码来源:005-test-resource.py

示例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
开发者ID:pombredanne,项目名称:sheba,代码行数:8,代码来源:002-statement-test.py

示例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)
开发者ID:GaelVaroquaux,项目名称:smithy,代码行数:8,代码来源:100-file-list-tests.py

示例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)
开发者ID:FromPointer,项目名称:python-spidermonkey,代码行数:8,代码来源:test-context.py

示例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
开发者ID:pombredanne,项目名称:sheba,代码行数:9,代码来源:002-statement-test.py


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