Files
phpy/tests/test_stream.py
2023-12-25 15:31:25 +08:00

29 lines
812 B
Python

import pytest
import phpy
def test_stream_client():
errno = phpy.Reference()
errstr = phpy.Reference()
rs = phpy.call("stream_socket_client", 'tcp://127.0.0.1:9999', errno, errstr, 30)
assert rs is False
assert errno.get() == 111
assert errstr.get() == 'Connection refused'
def test_stream_client_baidu():
errno = phpy.Reference()
errstr = phpy.Reference()
rs = phpy.call("stream_socket_client", 'tcp://www.baidu.com:80', errno, errstr, 30)
assert rs
assert errno.get() == 0
assert errstr.get() == ''
phpy.call('fwrite', rs, "GET / HTTP/1.0\r\nHost: www.baidu.com\r\nAccept: */*\r\n\r\n")
content = phpy.String()
while not phpy.call('feof', rs):
content += phpy.call('fread', rs, 8192)
assert str(content).find('百度搜索') != -1