本文整理汇总了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
示例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 %}"
)
示例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
示例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')
示例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()
示例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')
示例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
示例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
示例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
示例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
示例11: test_raise_response_works
def test_raise_response_works():
expected = 404
response = assert_raises( Response
, check
, "from aspen import Response; "
"raise Response(404)"
)
示例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
示例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
示例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
示例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