• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testing.assert_raises函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中aspen.testing.assert_raises函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises函数的具体用法?Python assert_raises怎么用?Python assert_raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_raises函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_parse_network_address_unix_socket_fails_on_windows

def test_parse_network_address_unix_socket_fails_on_windows():
    oldval = aspen.WINDOWS
    try:
        aspen.WINDOWS = True
        assert_raises(ValueError, parse.network_address, u"/foo/bar")
    finally:
        aspen.WINDOWS = oldval
开发者ID:ArmstrongJ,项目名称:aspen-python,代码行数:7,代码来源:test_configuration.py


示例2: test_tornado_base_failure_fails

def test_tornado_base_failure_fails():
    mk(("base.html", "{% block foo %}{% end %} Blam."))
    make_renderer = tornado_factory_factory()
    assert_raises( ParseError
                 , make_renderer
                 , "dummy/filepath.txt"
                 , "{% extends base.html %}"
                   "{% block foo %}Some bytes!{% end %}"
                  )
开发者ID:allisonmobley,项目名称:aspen,代码行数:9,代码来源:test_rendering.py


示例3: test_connecting_unknown_account_fails

def test_connecting_unknown_account_fails():
    tips = [ ('alice', 'bob', 1)
           , ('alice', 'carl', 1)
            ]
    with tip_graph(*tips) as context:
        assert_raises( AssertionError
                     , Participant('bob').take_over
                     , StubAccount('github', 'jim')
                      )
        actual = context.diff()
        assert actual == {}, actual
开发者ID:AbdAllah-Ahmed,项目名称:www.gittip.com,代码行数:11,代码来源:test_participant.py


示例4: test_balanced_bank_account

def test_balanced_bank_account(b_b_account, b_account):
    # b_account = balanced.Account
    # b_b_account = balanced.BankAccount
    # b_b_b_account = billing.BalancedBankAccount
    # got it?
    b_b_b_account = billing.BalancedBankAccount(balanced_account_uri)
    assert b_account.find.called_with(balanced_account_uri)
    assert b_b_account.find.called_with(balanced_bank_account_uri)

    assert b_b_b_account.is_setup
    assert_raises(IndexError, b_b_b_account.__getitem__, 'invalid')
开发者ID:gvenkataraman,项目名称:www.gittip.com,代码行数:11,代码来源:test_billing.py


示例5: test_bad_fails

def test_bad_fails():
    request = StubRequest()
    # once to get a WWW-Authenticate header
    hook = inbound_responder(_auth_func("username", "password"), realm="[email protected]")
    response = assert_raises(Response, hook, request)
    # do something with the header
    auth_headers = _auth_headers(response)
    request.headers['Authorization'] = _digest_auth_for(auth_headers, "username", "badpassword")
    response = assert_raises(Response, hook, request)
    assert response.code == 401, response
    assert not request.auth.authorized()
开发者ID:ArmstrongJ,项目名称:aspen-python,代码行数:11,代码来源:test_httpdigest.py


示例6: test_balanced_bank_account

def test_balanced_bank_account(b_b_account, b_account):
    # b_account = balanced.Account
    # b_b_account = balanced.BankAccount
    # b_b_b_account = billing.BalancedBankAccount
    # got it?
    bank_account = mock.Mock()
    bank_account.is_valid = True
    b_account.find.return_value.bank_accounts.all.return_value = [bank_account]

    b_b_b_account = billing.BalancedBankAccount(balanced_account_uri)
    assert b_account.find.called_with(balanced_account_uri)
    assert b_b_account.find.called_with(balanced_bank_account_uri)

    assert b_b_b_account.is_setup
    assert_raises(IndexError, b_b_b_account.__getitem__, 'invalid')
开发者ID:MikeFair,项目名称:www.gittip.com,代码行数:15,代码来源:test_billing.py


示例7: test_packet_with_odd_frames_tells_you_that

def test_packet_with_odd_frames_tells_you_that():
    Packet_ = lambda s: list(Packet(s)) # assert_raises chokes on generator
    packet = FFFD+'4'+FFFD+'0:::'+FFFD
    exc = assert_raises(SyntaxError, Packet_, packet)
    expected = "There are an odd number of frames in this packet: %s" % packet
    actual = exc.args[0]
    assert actual == expected, actual
开发者ID:buchuki,项目名称:aspen,代码行数:7,代码来源:test_sockets_packet.py


示例8: test_get_response_406_gives_list_of_acceptable_types

def test_get_response_406_gives_list_of_acceptable_types():
    mk(('index', NEGOTIATED_RESOURCE))
    request = StubRequest.from_fs('index')
    request.headers['Accept'] = 'cheese/head'
    actual = assert_raises(Response, get_response, request, Response()).body
    expected ="The following media types are available: text/plain, text/html."
    assert actual == expected, actual
开发者ID:jarpineh,项目名称:aspen,代码行数:7,代码来源:test_negotiated_resource.py


示例9: test_trailing_slash_redirects_trailing_slash

def test_trailing_slash_redirects_trailing_slash():
    mk('foo')
    response = assert_raises(Response, check_trailing_slash, '/foo')

    expected = 301
    actual = response.code
    assert actual == expected, actual
开发者ID:jarpineh,项目名称:aspen,代码行数:7,代码来源:test_gauntlet.py


示例10: test_trailing_slash_redirects_trailing_slash_to_the_right_place

def test_trailing_slash_redirects_trailing_slash_to_the_right_place():
    mk('foo')
    response = assert_raises(Response, check_trailing_slash, '/foo')

    expected = '/foo/'
    actual = response.headers['Location']
    assert actual == expected, actual
开发者ID:jarpineh,项目名称:aspen,代码行数:7,代码来源:test_gauntlet.py


示例11: test_raise_response_works

def test_raise_response_works():
    expected = 404
    response = assert_raises( Response
                            , check
                            , "from aspen import Response; "
                              "raise Response(404)"
                             )
开发者ID:gunshor,项目名称:aspen,代码行数:7,代码来源:test_resources.py


示例12: test_parse_specline_obeys_default_by_media_type_default

def test_parse_specline_obeys_default_by_media_type_default():
    resource = get()
    resource.website.default_renderers_by_media_type.default = 'glubber'
    err = assert_raises(ValueError, resource._parse_specline, 'media/type')
    actual = err.args[0]
    assert actual == ("Unknown renderer for media/type: glubber. "
                      "Possible renderers (starred are missing third-party "
                      "libraries): *pystache, tornado."), actual
开发者ID:jarpineh,项目名称:aspen,代码行数:8,代码来源:test_negotiated_resource.py


示例13: test_event_data_without_args_raises_ValueError

def test_event_data_without_args_raises_ValueError():
    exc = assert_raises( ValueError
                            , Message.from_bytes
                            , '5:::{"name": "bar", "arrrrgs": []}'
                             )
    expected = "An event message must have an 'args' key."
    actual = exc.args[0]
    assert actual == expected, actual
开发者ID:nejstastnejsistene,项目名称:aspen-python,代码行数:8,代码来源:test_sockets_message.py


示例14: test_event_data_with_reserved_name_raises_ValueError

def test_event_data_with_reserved_name_raises_ValueError():
    exc = assert_raises( ValueError
                       , Message.from_bytes
                       , '5:::{"name": "connect", "args": []}'
                        )
    expected = "That event name is reserved: connect."
    actual = exc.args[0]
    assert actual == expected, actual
开发者ID:nejstastnejsistene,项目名称:aspen-python,代码行数:8,代码来源:test_sockets_message.py


示例15: test_raise_response_works

def test_raise_response_works():
    expected = 404
    response = assert_raises( Response
                            , check
                            , "from aspen import Response; raise Response(404)"
                             )
    actual = response.code
    assert actual == expected, actual
开发者ID:alexcouper,项目名称:aspen,代码行数:8,代码来源:test_resources.py


示例16: test_get_renderer_factory_can_raise_syntax_error

def test_get_renderer_factory_can_raise_syntax_error():
    resource = get()
    resource.website.default_renderers_by_media_type['media/type'] = 'glubber'
    err = assert_raises( SyntaxError
                       , resource._get_renderer_factory
                       , 'media/type'
                       , 'oo*gle'
                        )
    msg = err.args[0]
    assert msg.startswith("Malformed renderer oo*gle. It must match"), msg
开发者ID:ArmstrongJ,项目名称:aspen-python,代码行数:10,代码来源:test_negotiated_resource.py


示例17: test_resource_dunder_all_limits_vars

def test_resource_dunder_all_limits_vars():
    actual = assert_raises( KeyError
                            , check
                            , "foo = 'bar'\n"
                              "__all__ = []\n"
                              "[---------]\n"
                              "Greetings, %(foo)s!"
                             )
    # in production, KeyError is turned into a 500 by an outer wrapper
    assert type(actual) == KeyError, actual
开发者ID:nejstastnejsistene,项目名称:aspen-python,代码行数:10,代码来源:test_resources.py


示例18: test_get_renderer_factory_can_raise_syntax_error

def test_get_renderer_factory_can_raise_syntax_error():
    resource = get()
    resource.website.default_renderers_by_media_type['media/type'] = 'glubber'
    err = assert_raises( SyntaxError
                       , resource._get_renderer_factory
                       , 'media/type'
                       , 'oo*gle'
                        )
    actual = err.args[0]
    assert actual == ("Malformed renderer oo*gle. It must match #![a-z0-9.-]+."
                      " Possible renderers (might need third-party libs): "
                      "pystache, tornado."), actual
开发者ID:jarpineh,项目名称:aspen,代码行数:12,代码来源:test_negotiated_resource.py


示例19: test_good_works

def test_good_works():
    request = StubRequest()
    # once to get a WWW-Authenticate header
    hook = inbound_responder(_auth_func("username", "password"), realm="[email protected]")
    response = assert_raises(Response, hook, request)
    # do something with the header
    auth_headers = _auth_headers(response)
    request.headers['Authorization'] = _digest_auth_for(auth_headers, "username", "password")
    #print repr(request.headers['Authorization'])
    response = hook(request)
    success = request.auth.authorized()
    assert success
    assert request.auth.username() == "username", request.auth.username()
开发者ID:ArmstrongJ,项目名称:aspen-python,代码行数:13,代码来源:test_httpdigest.py


示例20: test_intercept_socket_protects_direct_access

def test_intercept_socket_protects_direct_access():
    request = Request(uri="/foo.sock")
    assert_raises(Response, gauntlet.intercept_socket, request)
开发者ID:jarpineh,项目名称:aspen,代码行数:3,代码来源:test_gauntlet.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.check函数代码示例发布时间:2022-05-24
下一篇:
Python message.Message类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap