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


Python testing.assert_raises函数代码示例

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


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


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