def test_custom_socket_factory():
class CustomSocketFactory:
def socket(self, family, type, proto):
return ("hi", family, type, proto)
csf = CustomSocketFactory()
assert tsocket.set_custom_socket_factory(csf) is None
assert tsocket.socket() == ("hi", tsocket.AF_INET, tsocket.SOCK_STREAM, 0)
assert tsocket.socket(1, 2, 3) == ("hi", 1, 2, 3)
# socket with fileno= doesn't call our custom method
fd = stdlib_socket.socket().detach()
wrapped = tsocket.socket(fileno=fd)
assert hasattr(wrapped, "bind")
wrapped.close()
# Likewise for socketpair
a, b = tsocket.socketpair()
with a, b:
assert hasattr(a, "bind")
assert hasattr(b, "bind")
assert tsocket.set_custom_socket_factory(None) is csf
评论列表
文章目录