Skip to content

Commit 6d469a9

Browse files
authored
Merge pull request #17 from justmobilize/update-tests
Update tests
2 parents 0a4f745 + 0792b27 commit 6d469a9

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

tests/get_socket_test.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,32 @@ def test_get_socket_os_error():
9898
mock_pool = mocket.MocketPool()
9999
mock_socket_1 = mocket.Mocket()
100100
mock_pool.socket.side_effect = [
101-
OSError("OSError"),
101+
OSError("OSError 1"),
102102
mock_socket_1,
103103
]
104104

105105
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
106106

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

111112

112113
def test_get_socket_runtime_error():
113114
mock_pool = mocket.MocketPool()
114115
mock_socket_1 = mocket.Mocket()
115116
mock_pool.socket.side_effect = [
116-
RuntimeError("RuntimeError"),
117+
RuntimeError("RuntimeError 1"),
117118
mock_socket_1,
118119
]
119120

120121
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
121122

122123
# try to get a socket that returns a RuntimeError
123-
with pytest.raises(RuntimeError):
124+
with pytest.raises(RuntimeError) as context:
124125
connection_manager.get_socket(mocket.MOCK_HOST_1, 80, "http:")
126+
assert "RuntimeError 1" in str(context)
125127

126128

127129
def test_get_socket_connect_memory_error():
@@ -132,13 +134,14 @@ def test_get_socket_connect_memory_error():
132134
mock_socket_1,
133135
mock_socket_2,
134136
]
135-
mock_socket_1.connect.side_effect = MemoryError("MemoryError")
137+
mock_socket_1.connect.side_effect = MemoryError("MemoryError 1")
136138

137139
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
138140

139141
# try to connect a socket that returns a MemoryError
140-
with pytest.raises(MemoryError):
142+
with pytest.raises(MemoryError) as context:
141143
connection_manager.get_socket(mocket.MOCK_HOST_1, 80, "http:")
144+
assert "MemoryError 1" in str(context)
142145

143146

144147
def test_get_socket_connect_os_error():
@@ -149,13 +152,14 @@ def test_get_socket_connect_os_error():
149152
mock_socket_1,
150153
mock_socket_2,
151154
]
152-
mock_socket_1.connect.side_effect = OSError("OSError")
155+
mock_socket_1.connect.side_effect = OSError("OSError 1")
153156

154157
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
155158

156159
# try to connect a socket that returns a OSError
157-
with pytest.raises(OSError):
160+
with pytest.raises(OSError) as context:
158161
connection_manager.get_socket(mocket.MOCK_HOST_1, 80, "http:")
162+
assert "OSError 1" in str(context)
159163

160164

161165
def test_get_socket_runtime_error_ties_again_at_least_one_free():
@@ -190,9 +194,9 @@ def test_get_socket_runtime_error_ties_again_only_once():
190194
mock_socket_2 = mocket.Mocket()
191195
mock_pool.socket.side_effect = [
192196
mock_socket_1,
193-
RuntimeError("error 1"),
194-
RuntimeError("error 2"),
195-
RuntimeError("error 3"),
197+
RuntimeError("RuntimeError 1"),
198+
RuntimeError("RuntimeError 2"),
199+
RuntimeError("RuntimeError 3"),
196200
mock_socket_2,
197201
]
198202

@@ -207,8 +211,9 @@ def test_get_socket_runtime_error_ties_again_only_once():
207211
free_sockets_mock.assert_not_called()
208212

209213
# try to get a socket that returns a RuntimeError twice
210-
with pytest.raises(RuntimeError):
214+
with pytest.raises(RuntimeError) as context:
211215
connection_manager.get_socket(mocket.MOCK_HOST_2, 80, "http:")
216+
assert "RuntimeError 2" in str(context)
212217
free_sockets_mock.assert_called_once()
213218

214219

@@ -237,13 +242,15 @@ def test_fake_ssl_context_connect_error( # pylint: disable=unused-argument
237242
mock_pool = mocket.MocketPool()
238243
mock_socket_1 = mocket.Mocket()
239244
mock_pool.socket.return_value = mock_socket_1
240-
mock_socket_1.connect.side_effect = RuntimeError("RuntimeError")
245+
mock_socket_1.connect.side_effect = RuntimeError("RuntimeError 1")
241246

242247
radio = mocket.MockRadio.ESP_SPIcontrol()
243248
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
244249
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
245250

246-
with pytest.raises(OSError):
251+
with pytest.raises(OSError) as context:
247252
connection_manager.get_socket(
248253
mocket.MOCK_HOST_1, 443, "https:", ssl_context=ssl_context
249254
)
255+
assert "12" in str(context)
256+
assert "RuntimeError 1" in str(context)

0 commit comments

Comments
 (0)