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)
评论列表
文章目录