Skip to content

Commit 49bc2ec

Browse files
committed
redo test outputs
1 parent 917edc8 commit 49bc2ec

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

adafruit_connection_manager.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ def _free_sockets(self, force: bool = False) -> None:
204204
for socket in open_sockets:
205205
self.close_socket(socket)
206206

207+
def _register_connected_socket(self, key, socket):
208+
"""Register a socket as managed."""
209+
self._key_by_managed_socket[socket] = key
210+
self._managed_socket_by_key[key] = socket
211+
207212
def _get_connected_socket( # pylint: disable=too-many-arguments
208213
self,
209214
addr_info: List[Tuple[int, int, int, str, Tuple[str, int]]],
@@ -264,10 +269,6 @@ def free_socket(self, socket: SocketType) -> None:
264269
raise RuntimeError("Socket not managed")
265270
self._available_sockets.add(socket)
266271

267-
def _register_connected_socket(self, key, socket):
268-
self._key_by_managed_socket[socket] = key
269-
self._managed_socket_by_key[key] = socket
270-
271272
# pylint: disable=too-many-arguments
272273
def get_socket(
273274
self,
@@ -290,7 +291,7 @@ def get_socket(
290291
used for multiple simultaneous connections to the same host
291292
:param float timeout: how long to wait to connect
292293
:param bool is_ssl: ``True`` If the connection is to be over SSL;
293-
automatically set when ``proto`` is ``"https:"`
294+
automatically set when ``proto`` is ``"https:"``
294295
:param Optional[SSLContextType]: SSL context to use when making SSL requests
295296
"""
296297
if session_id:

tests/get_socket_test.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_get_socket_not_flagged_free():
9191
# get a socket for the same host, should be a different one
9292
with pytest.raises(RuntimeError) as context:
9393
socket = connection_manager.get_socket(mocket.MOCK_HOST_1, 80, "http:")
94-
assert "Socket already connected" in str(context)
94+
assert "An existing socket is already connected" in str(context)
9595

9696

9797
def test_get_socket_os_error():
@@ -105,9 +105,8 @@ def test_get_socket_os_error():
105105
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
106106

107107
# try to get a socket that returns a OSError
108-
with pytest.raises(RuntimeError) as context:
108+
with pytest.raises(OSError):
109109
connection_manager.get_socket(mocket.MOCK_HOST_1, 80, "http:")
110-
assert "Error connecting socket: OSError" in str(context)
111110

112111

113112
def test_get_socket_runtime_error():
@@ -121,9 +120,8 @@ def test_get_socket_runtime_error():
121120
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
122121

123122
# try to get a socket that returns a RuntimeError
124-
with pytest.raises(RuntimeError) as context:
123+
with pytest.raises(RuntimeError):
125124
connection_manager.get_socket(mocket.MOCK_HOST_1, 80, "http:")
126-
assert "Error connecting socket: RuntimeError" in str(context)
127125

128126

129127
def test_get_socket_connect_memory_error():
@@ -139,9 +137,8 @@ def test_get_socket_connect_memory_error():
139137
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
140138

141139
# try to connect a socket that returns a MemoryError
142-
with pytest.raises(RuntimeError) as context:
140+
with pytest.raises(MemoryError):
143141
connection_manager.get_socket(mocket.MOCK_HOST_1, 80, "http:")
144-
assert "Error connecting socket: MemoryError" in str(context)
145142

146143

147144
def test_get_socket_connect_os_error():
@@ -157,9 +154,8 @@ def test_get_socket_connect_os_error():
157154
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
158155

159156
# try to connect a socket that returns a OSError
160-
with pytest.raises(RuntimeError) as context:
157+
with pytest.raises(OSError):
161158
connection_manager.get_socket(mocket.MOCK_HOST_1, 80, "http:")
162-
assert "Error connecting socket: OSError" in str(context)
163159

164160

165161
def test_get_socket_runtime_error_ties_again_at_least_one_free():
@@ -211,9 +207,8 @@ def test_get_socket_runtime_error_ties_again_only_once():
211207
free_sockets_mock.assert_not_called()
212208

213209
# try to get a socket that returns a RuntimeError twice
214-
with pytest.raises(RuntimeError) as context:
210+
with pytest.raises(RuntimeError):
215211
connection_manager.get_socket(mocket.MOCK_HOST_2, 80, "http:")
216-
assert "Error connecting socket: error 2, first error: error 1" in str(context)
217212
free_sockets_mock.assert_called_once()
218213

219214

@@ -248,8 +243,7 @@ def test_fake_ssl_context_connect_error( # pylint: disable=unused-argument
248243
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
249244
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
250245

251-
with pytest.raises(RuntimeError) as context:
246+
with pytest.raises(OSError):
252247
connection_manager.get_socket(
253248
mocket.MOCK_HOST_1, 443, "https:", ssl_context=ssl_context
254249
)
255-
assert "Error connecting socket: [Errno 12] RuntimeError" in str(context)

0 commit comments

Comments
 (0)