Files
micropython/tests/extmod/socket_badconstructor.py
T
Damien George 72222a63ca tests/extmod: Don't require constructor to raise for bad socket type.
Some socket implementations (eg `extmod/modsocket.c`) don't (and can't
easily) raise an exception for an invalid socket type.  So just test that
passing such a value doesn't crash the device.

Signed-off-by: Damien George <damien@micropython.org>
2026-05-08 02:08:00 +10:00

30 lines
596 B
Python

# Test passing in bad values to socket.socket constructor.
try:
import socket
except:
print("SKIP")
raise SystemExit
try:
s = socket.socket(None)
except TypeError:
print("TypeError")
try:
s = socket.socket(socket.AF_INET, None)
except TypeError:
print("TypeError")
# This may or may not raise an exception, depending on the socket implementation.
# The test is here for coverage.
try:
s = socket.socket(socket.AF_INET, 123456)
except OSError:
pass
try:
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, None)
except TypeError:
print("TypeError")