test_socket.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:trio 作者: python-trio 项目源码 文件源码
def test_from_stdlib_socket():
    sa, sb = stdlib_socket.socketpair()
    assert not isinstance(sa, tsocket.SocketType)
    with sa, sb:
        ta = tsocket.from_stdlib_socket(sa)
        assert isinstance(ta, tsocket.SocketType)
        assert sa.fileno() == ta.fileno()
        await ta.send(b"x")
        assert sb.recv(1) == b"x"

    # rejects other types
    with pytest.raises(TypeError):
        tsocket.from_stdlib_socket(1)

    class MySocket(stdlib_socket.socket):
        pass

    mysock = MySocket()
    with pytest.raises(TypeError):
        tsocket.from_stdlib_socket(mysock)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号