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


Python tests.assert_raises函数代码示例

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


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


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