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

Python tests.assert_raises函数代码示例

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

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



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

示例1: test_semaphore_type_check

def test_semaphore_type_check():
    eventlet.Semaphore(0)
    eventlet.Semaphore(1)
    eventlet.Semaphore(1e2)

    with tests.assert_raises(TypeError):
        eventlet.Semaphore('foo')
    with tests.assert_raises(ValueError):
        eventlet.Semaphore(-1)
开发者ID:cloudera,项目名称:hue,代码行数:9,代码来源:semaphore_test.py


示例2: test_greenpool_type_check

def test_greenpool_type_check():
    eventlet.GreenPool(0)
    eventlet.GreenPool(1)
    eventlet.GreenPool(1e3)

    with tests.assert_raises(TypeError):
        eventlet.GreenPool('foo')
    with tests.assert_raises(ValueError):
        eventlet.GreenPool(-1)
开发者ID:cloudera,项目名称:hue,代码行数:9,代码来源:greenpool_test.py


示例3: test_dont_persist_alias

 def test_dont_persist_alias(self):
     db = sqlsoup.SQLSoup(engine)
     MappedBooks = db.books
     b = db.books._table
     s = select([b.c.published_year, func.count('*').label('n')],
                from_obj=[b], group_by=[b.c.published_year])
     s = s.alias('years_with_count')
     years_with_count = db.map(s, primary_key=[s.c.published_year])
     assert_raises(sqlsoup.SQLSoupError, years_with_count.insert,
                   published_year='2007', n=1)
开发者ID:kenwilcox,项目名称:sqlsoup,代码行数:10,代码来源:test_sqlsoup.py


示例4: test_parse_www_authenticate_malformed

def test_parse_www_authenticate_malformed():
    # TODO: test (and fix) header value 'barbqwnbm-bb...:asd' leads to dead loop
    with tests.assert_raises(httplib2.MalformedHeader):
        httplib2._parse_www_authenticate(
            {
                "www-authenticate": 'OAuth "Facebook Platform" "invalid_token" "Invalid OAuth access token."'
            }
        )
开发者ID:httplib2,项目名称:httplib2,代码行数:8,代码来源:test_auth.py


示例5: test_server_not_found_error_is_raised_for_invalid_hostname

def test_server_not_found_error_is_raised_for_invalid_hostname(mock_socket_connect):
    """Invalidates https://github.com/httplib2/httplib2/pull/100."""
    mock_socket_connect.side_effect = _raise_name_not_known_error
    http = httplib2.Http(
        proxy_info=httplib2.ProxyInfo(
            httplib2.socks.PROXY_TYPE_HTTP, "255.255.255.255", 8001
        )
    )
    with tests.assert_raises(httplib2.ServerNotFoundError):
        http.request("http://invalid.hostname.foo.bar/", "GET")
开发者ID:httplib2,项目名称:httplib2,代码行数:10,代码来源:test_proxy.py


示例6: test_connection_refused

def test_connection_refused():
    http = httplib2.Http()
    http.force_exception_to_status_code = False
    with tests.assert_raises(socket.error):
        http.request(dummy_url)

    # Now test with exceptions turned off
    http.force_exception_to_status_code = True
    response, content = http.request(dummy_url)
    assert response['content-type'] == 'text/plain'
    assert (b"Connection refused" in content or b"actively refused" in content)
    assert response.status == 400
开发者ID:amake,项目名称:httplib2,代码行数:12,代码来源:test_http.py


示例7: test_unknown_server

def test_unknown_server():
    http = httplib2.Http()
    http.force_exception_to_status_code = False
    with tests.assert_raises(httplib2.ServerNotFoundError):
        with mock.patch('socket.socket.connect', side_effect=socket.gaierror):
            http.request("http://no-such-hostname./")

    # Now test with exceptions turned off
    http.force_exception_to_status_code = True
    response, content = http.request("http://no-such-hostname./")
    assert response['content-type'] == 'text/plain'
    assert content.startswith(b"Unable to find")
    assert response.status == 400
开发者ID:amake,项目名称:httplib2,代码行数:13,代码来源:test_http.py


示例8: test_ssl_wrong_ca

def test_ssl_wrong_ca():
    # Test that we get a SSLHandshakeError if we try to access
    # https://www.google.com, using a CA cert file that doesn't contain
    # the CA Google uses (i.e., simulating a cert that's not signed by a
    # trusted CA).
    other_ca_certs = os.path.join(
        os.path.dirname(os.path.abspath(httplib2.__file__)),
        'test', 'other_cacerts.txt')
    assert os.path.exists(other_ca_certs)
    http = httplib2.Http(ca_certs=other_ca_certs)
    http.follow_redirects = False
    with tests.assert_raises(ssl.SSLError):
        http.request('https://www.google.com/', 'GET')
开发者ID:amake,项目名称:httplib2,代码行数:13,代码来源:test_external.py


示例9: test_wait_except

    def test_wait_except(self):
        # https://github.com/eventlet/eventlet/issues/407
        q = eventlet.Queue()

        def get():
            q.get()
            raise KeyboardInterrupt

        eventlet.spawn(get)
        eventlet.sleep()

        with tests.assert_raises(KeyboardInterrupt):
            q.put(None)
            eventlet.sleep()
开发者ID:cloudera,项目名称:hue,代码行数:14,代码来源:queue_test.py


示例10: test_deflate_malformed_response

def test_deflate_malformed_response():
    # Test that we raise a good exception when the deflate fails
    http = httplib2.Http()
    http.force_exception_to_status_code = False
    response = tests.http_response_bytes(
        headers={"content-encoding": "deflate"}, body=b"obviously not compressed"
    )
    with tests.server_const_bytes(response, request_count=2) as uri:
        with tests.assert_raises(httplib2.FailedToDecompressContent):
            http.request(uri, "GET")

        # Re-run the test with out the exceptions
        http.force_exception_to_status_code = True

        response, content = http.request(uri, "GET")
        assert response.status == 500
        assert response.reason.startswith("Content purported")
开发者ID:httplib2,项目名称:httplib2,代码行数:17,代码来源:test_encoding.py


示例11: test_gzip_malformed_response

def test_gzip_malformed_response():
    http = httplib2.Http()
    # Test that we raise a good exception when the gzip fails
    http.force_exception_to_status_code = False
    response = tests.http_response_bytes(
        headers={'content-encoding': 'gzip'},
        body=b'obviously not compressed',
    )
    with tests.server_const_bytes(response, request_count=2) as uri:
        with tests.assert_raises(httplib2.FailedToDecompressContent):
            http.request(uri, 'GET')

        # Re-run the test with out the exceptions
        http.force_exception_to_status_code = True

        response, content = http.request(uri, 'GET')
        assert response.status == 500
        assert response.reason.startswith('Content purported')
开发者ID:amake,项目名称:httplib2,代码行数:18,代码来源:test_encoding.py


示例12: test_select_mark_file_as_reopened

def test_select_mark_file_as_reopened():
    # https://github.com/eventlet/eventlet/pull/294
    # Fix API inconsistency in select and Hub.
    # mark_as_closed takes one argument, but called without arguments.
    # on_error takes file descriptor, but called with an exception object.
    s = original_socket.socket()
    s.setblocking(0)
    s.bind(('127.0.0.1', 0))
    s.listen(5)

    gt = eventlet.spawn(select.select, [s], [s], [s])
    eventlet.sleep(0.01)

    with eventlet.Timeout(0.5) as t:
        with tests.assert_raises(hubs.IOClosed):
            hubs.get_hub().mark_as_reopened(s.fileno())
            gt.wait()
        t.cancel()
开发者ID:cloudera,项目名称:hue,代码行数:18,代码来源:green_select_test.py


示例13: test_no_pk_reflected

 def test_no_pk_reflected(self):
     db = sqlsoup.SQLSoup(engine)
     assert_raises(sqlsoup.SQLSoupError, getattr, db, 'nopk')
开发者ID:kenwilcox,项目名称:sqlsoup,代码行数:3,代码来源:test_sqlsoup.py


示例14: test_udp_ipv6_wrong_addr

 def test_udp_ipv6_wrong_addr(self):
     with tests.mock.patch('eventlet.support.greendns.socket.socket.recvfrom',
                           return_value=(self.query_wire,
                                         ('ffff:0000::1', 53, 0, 0))):
         with tests.assert_raises(dns.query.UnexpectedSource):
             greendns.udp(self.query, '::1')
开发者ID:cloudera,项目名称:hue,代码行数:6,代码来源:greendns_test.py


示例15: test_udp_ipv6_wrong_addr_ignore

 def test_udp_ipv6_wrong_addr_ignore(self):
     with tests.mock.patch('eventlet.support.greendns.socket.socket.recvfrom',
                           side_effect=socket.timeout):
         with tests.assert_raises(dns.exception.Timeout):
             greendns.udp(self.query, '::1', timeout=0.1, ignore_unexpected=True)
开发者ID:cloudera,项目名称:hue,代码行数:5,代码来源:greendns_test.py


示例16: test_udp_ipv6_timeout

 def test_udp_ipv6_timeout(self):
     with tests.mock.patch('eventlet.support.greendns.socket.socket.recvfrom',
                           side_effect=socket.timeout):
         with tests.assert_raises(dns.exception.Timeout):
             greendns.udp(self.query, '::1', timeout=0.1)
开发者ID:cloudera,项目名称:hue,代码行数:5,代码来源:greendns_test.py


示例17: test_query_unknown_raises

 def test_query_unknown_raises(self):
     hr = _make_host_resolver()
     with tests.assert_raises(greendns.dns.resolver.NoAnswer):
         hr.query('example.com')
开发者ID:cloudera,项目名称:hue,代码行数:4,代码来源:greendns_test.py


示例18: test_nosuchtable

 def test_nosuchtable(self):
     db = sqlsoup.SQLSoup(engine)
     assert_raises(exc.NoSuchTableError, getattr, db, 'nosuchtable')
开发者ID:kenwilcox,项目名称:sqlsoup,代码行数:3,代码来源:test_sqlsoup.py


示例19: test_ssl_invalid_ca_certs_path

def test_ssl_invalid_ca_certs_path():
    # Test that we get an ssl.SSLError when specifying a non-existent CA
    # certs file.
    http = httplib2.Http(ca_certs='/nosuchfile')
    with tests.assert_raises(IOError):
        http.request('https://www.google.com/', 'GET')
开发者ID:amake,项目名称:httplib2,代码行数:6,代码来源:test_external.py


示例20: test_connection_refused_raises_exception

def test_connection_refused_raises_exception(mock_socket_connect):
    mock_socket_connect.side_effect = _raise_connection_refused_exception
    http = httplib2.Http()
    http.force_exception_to_status_code = False
    with tests.assert_raises(socket.error):
        http.request(DUMMY_URL)
开发者ID:httplib2,项目名称:httplib2,代码行数:6,代码来源:test_http.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python tests.clicomm函数代码示例发布时间:2022-05-27
下一篇:
Python tests.assert_contains函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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