mirror of
https://github.com/php-win-ext/phpy.git
synced 2026-03-24 08:52:08 +01:00
29 lines
812 B
Python
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
|