Files
micropython/tests/extmod/socket_badconstructor.py
Jeff Epler e9da4c9c98 unix/modsocket: Use type-checking mp_obj_get_int.
MP_OBJ_SMALL_INT_VALUE would give erroneous results, such as assertion
failures in the coverage build and other oddities like:

    >>> s = socket.socket()
    >>> s.recv(3.14)
    MemoryError: memory allocation failed, allocating 4235896656 bytes

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-09-16 12:04:19 +10:00

23 lines
404 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")
try:
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, None)
except TypeError:
print("TypeError")