Skip to content

Commit

Permalink
use ValueError instead of AttributeError for incorrect args
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalbert committed May 10, 2024
1 parent 99f8972 commit 917edc8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions adafruit_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def wrap_socket( # pylint: disable=unused-argument
if hasattr(self._iface, "TLS_MODE"):
return _FakeSSLSocket(socket, self._iface.TLS_MODE)

raise AttributeError("This radio does not support TLS/HTTPS")
raise ValueError("This radio does not support TLS/HTTPS")


def create_fake_ssl_context(
Expand Down Expand Up @@ -159,7 +159,7 @@ def get_radio_socketpool(radio):
ssl_context = create_fake_ssl_context(pool, radio)

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

_global_key_by_socketpool[pool] = key
_global_socketpools[key] = pool
Expand Down
4 changes: 2 additions & 2 deletions tests/get_radio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_get_radio_socketpool_wiznet5k( # pylint: disable=unused-argument

def test_get_radio_socketpool_unsupported():
radio = mocket.MockRadio.Unsupported()
with pytest.raises(AttributeError) as context:
with pytest.raises(ValueError) as context:
adafruit_connection_manager.get_radio_socketpool(radio)
assert "Unsupported radio class" in str(context)

Expand Down Expand Up @@ -100,7 +100,7 @@ def test_get_radio_ssl_context_wiznet5k( # pylint: disable=unused-argument

def test_get_radio_ssl_context_unsupported():
radio = mocket.MockRadio.Unsupported()
with pytest.raises(AttributeError) as context:
with pytest.raises(ValueError) as context:
adafruit_connection_manager.get_radio_ssl_context(radio)
assert "Unsupported radio class" in str(context)

Expand Down
4 changes: 2 additions & 2 deletions tests/protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_get_https_no_ssl():
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)

# verify not sending in a SSL context for a HTTPS call errors
with pytest.raises(AttributeError) as context:
with pytest.raises(ValueError) as context:
connection_manager.get_socket(mocket.MOCK_HOST_1, 443, "https:")
assert "ssl_context must be set" in str(context)
assert "ssl_context must be provided if using ssl" in str(context)


def test_connect_https():
Expand Down
2 changes: 1 addition & 1 deletion tests/ssl_context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_connect_wiznet5k_https_not_supported( # pylint: disable=unused-argumen
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)

# verify a HTTPS call for a board without built in WiFi and SSL support errors
with pytest.raises(AttributeError) as context:
with pytest.raises(ValueError) as context:
connection_manager.get_socket(
mocket.MOCK_HOST_1, 443, "https:", ssl_context=ssl_context
)
Expand Down

0 comments on commit 917edc8

Please sign in to comment.