Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new SocketPool for ESP32SPI and WIZNET5K #11

Merged
merged 10 commits into from
Apr 30, 2024
9 changes: 4 additions & 5 deletions adafruit_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ def create_fake_ssl_context(


def _get_radio_hash_key(radio):
class_name = radio.__class__.__name__
# trying to use wifi.radio as a key results in:
# TypeError: unsupported type for __hash__: 'Radio'
# So just use the class name in this case
return class_name if class_name == "Radio" else radio
try:
return hash(radio)
except TypeError:
return radio.__class__.__name__
dhalbert marked this conversation as resolved.
Show resolved Hide resolved


def get_radio_socketpool(radio):
Expand Down
12 changes: 12 additions & 0 deletions tests/get_radio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
import adafruit_connection_manager


def test__get_radio_hash_key():
radio = mocket.MockRadio.Radio()
assert adafruit_connection_manager._get_radio_hash_key(radio) == hash(radio)


def test__get_radio_hash_key_not_hashable():
radio = mocket.MockRadio.Radio()

with mock.patch("builtins.hash", side_effect=TypeError()):
assert adafruit_connection_manager._get_radio_hash_key(radio) == "Radio"


def test_get_radio_socketpool_wifi( # pylint: disable=unused-argument
circuitpython_socketpool_module,
):
Expand Down
Loading