Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions adafruit_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def create_fake_ssl_context(
return _FakeSSLContext(iface)


class CPythonNetwork: # pylint: disable=too-few-public-methods
"""Radio object to use when using ConnectionManager in CPython."""


_global_connection_managers = {}
_global_key_by_socketpool = {}
_global_socketpools = {}
Expand Down Expand Up @@ -158,6 +162,12 @@ def get_radio_socketpool(radio):
if ssl_context is None:
ssl_context = create_fake_ssl_context(pool, radio)

elif class_name == "CPythonNetwork":
import socket as pool # pylint: disable=import-outside-toplevel
import ssl # pylint: disable=import-outside-toplevel

ssl_context = ssl.create_default_context()

else:
raise ValueError(f"Unsupported radio class: {class_name}")

Expand Down
14 changes: 14 additions & 0 deletions tests/get_radio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def test_get_radio_socketpool_wiznet5k( # pylint: disable=unused-argument
assert socket_pool in adafruit_connection_manager._global_socketpools.values()


def test_get_radio_socketpool_cpython():
radio = adafruit_connection_manager.CPythonNetwork()
socket_pool = adafruit_connection_manager.get_radio_socketpool(radio)
assert socket_pool.__name__ == "socket"
assert socket_pool in adafruit_connection_manager._global_socketpools.values()


def test_get_radio_socketpool_unsupported():
radio = mocket.MockRadio.Unsupported()
with pytest.raises(ValueError) as context:
Expand Down Expand Up @@ -98,6 +105,13 @@ def test_get_radio_ssl_context_wiznet5k( # pylint: disable=unused-argument
assert ssl_context in adafruit_connection_manager._global_ssl_contexts.values()


def test_get_radio_ssl_context_cpython():
radio = adafruit_connection_manager.CPythonNetwork()
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
assert isinstance(ssl_context, ssl.SSLContext)
assert ssl_context in adafruit_connection_manager._global_ssl_contexts.values()


def test_get_radio_ssl_context_unsupported():
radio = mocket.MockRadio.Unsupported()
with pytest.raises(ValueError) as context:
Expand Down