tests: Make socket tests compatible with CPython on windows.

Note these are mostly the 'bare' socket tests, not the ssl/tls ones
for instance: most of these don't run on CPython because of
incompatible wrap_socket() arguments.
The change mostly consists of checking the WSA error codes next to
the errno ones and these are written as numeric values because the
names (like WSAEAGAIN) are only available in CPython and not in
micropython.

Signed-off-by: stijn <stijn@ignitron.net>
pull/12810/head
stijn 2023-10-24 17:08:43 +02:00
rodzic 51d05c442a
commit a0127919bc
9 zmienionych plików z 11 dodań i 9 usunięć

Wyświetl plik

@ -11,4 +11,4 @@ s = socket.socket()
try: try:
s.recv(1) s.recv(1)
except OSError as er: except OSError as er:
print("ENOTCONN:", er.errno == errno.ENOTCONN) print("ENOTCONN:", er.errno in (errno.ENOTCONN, 10057))

Wyświetl plik

@ -18,4 +18,4 @@ s.settimeout(0)
try: try:
s.recv(1) s.recv(1)
except OSError as er: except OSError as er:
print("EAGAIN:", er.errno == errno.EAGAIN) print("EAGAIN:", er.errno in (errno.EAGAIN, 10035))

Wyświetl plik

@ -21,7 +21,7 @@ async def handle_connection(reader, writer):
writer.close() writer.close()
await writer.wait_closed() await writer.wait_closed()
except OSError as er: except OSError as er:
print("OSError", er.errno) print("OSError", er.errno in (22, 104))
ev.set() ev.set()

Wyświetl plik

@ -1,5 +1,5 @@
--- instance0 --- --- instance0 ---
b'GET / HTTP' b'GET / HTTP'
OSError 104 OSError True
--- instance1 --- --- instance1 ---

Wyświetl plik

@ -17,7 +17,7 @@ def instance0():
try: try:
print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN
except OSError as er: except OSError as er:
print(er.errno in (107, 128)) print(er.errno in (107, 128, 10057))
s.close() s.close()

Wyświetl plik

@ -9,5 +9,5 @@ s.listen(1)
try: try:
s.accept() s.accept()
except OSError as er: except OSError as er:
print(er.errno == 11) # 11 is EAGAIN print(er.errno in (11, 10035)) # 11 is EAGAIN
s.close() s.close()

Wyświetl plik

@ -15,5 +15,7 @@ s.listen(1)
try: try:
s.accept() s.accept()
except OSError as er: except OSError as er:
print(er.errno in (errno.ETIMEDOUT, "timed out")) # CPython uses a string instead of errno print(
er.errno == errno.ETIMEDOUT or str(er) == "timed out"
) # CPython uses a string instead of errno
s.close() s.close()

Wyświetl plik

@ -9,7 +9,7 @@ def test(peer_addr):
try: try:
s.connect(peer_addr) s.connect(peer_addr)
except OSError as er: except OSError as er:
print(er.errno == errno.EINPROGRESS) print(er.errno in (errno.EINPROGRESS, 10035))
s.close() s.close()

Wyświetl plik

@ -12,7 +12,7 @@ def test(addr, hostname, block=True):
s.connect(addr) s.connect(addr)
print("connected") print("connected")
except OSError as e: except OSError as e:
if e.errno != errno.EINPROGRESS: if e.errno not in (errno.EINPROGRESS, 10035):
raise raise
print("EINPROGRESS") print("EINPROGRESS")