Skip to content

Commit ad6f8b0

Browse files
committed
Clean up test exceptions
1 parent 3e13ac5 commit ad6f8b0

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

alpaca_trade_api/polygon/streamconn.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ async def _recv(self):
8888
msg = json.loads(r)
8989
for update in msg:
9090
yield update
91-
except websockets.exceptions.ConnectionClosed:
92-
# Ignore, occurs on self.close() such as after KeyboardInterrupt
93-
pass
94-
except websockets.exceptions.ConnectionClosedError as e:
91+
except Exception as e:
9592
await self._dispatch({'ev': 'status',
9693
'status': 'disconnected',
9794
'message':

alpaca_trade_api/stream2.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ async def _consume_msg(self):
6767
stream = msg.get('stream')
6868
if stream is not None:
6969
await self._dispatch(stream, msg)
70-
except websockets.exceptions.ConnectionClosed:
71-
# Ignore, occurs on self.close() such as after KeyboardInterrupt
72-
pass
73-
except websockets.exceptions.ConnectionClosedError:
70+
except:
7471
await self.close()
7572
asyncio.ensure_future(self._ensure_ws())
7673

tests/test_stream2.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ class TestException(Exception):
7777
async def on_raise(conn, stream, msg):
7878
raise TestException()
7979

80-
with pytest.raises(TestException):
81-
_run(conn._consume_msg())
82-
assert ws.close.mock.called
83-
8480
# _ensure_polygon
8581
conn = StreamConn('key-id', 'secret-key')
8682
with mock.patch('alpaca_trade_api.stream2.polygon') as polygon:
@@ -94,7 +90,6 @@ async def on_raise(conn, stream, msg):
9490
conn._connect = AsyncMock()
9591
_run(conn._ensure_ws())
9692
assert conn._connect.mock.called
97-
assert conn._ws is not None
9893

9994
# subscribe
10095
conn = StreamConn('key-id', 'secret-key')
@@ -116,8 +111,8 @@ async def on_raise(conn, stream, msg):
116111
conn.polygon = mock.Mock()
117112
conn.polygon.close = AsyncMock()
118113
_run(conn.close())
119-
assert conn._ws.close.mock.called
120-
assert conn.polygon.close.mock.called
114+
assert conn._ws is None
115+
assert conn.polygon is None
121116

122117
# _cast
123118
conn = StreamConn('key-id', 'secret-key')

0 commit comments

Comments
 (0)