Skip to content

Commit 7987e30

Browse files
bnavigatorccordoba12delta003
authored
Python 3.8 fixes for endpoint and tests (#37)
* fix endpoint exception lists for Python 3.8 Author: @maximbaz according to #33 * fix test_writer_bad_message not only windows can have problems with serializing datetime Co-authored-by: Carlos Cordoba <[email protected]> Co-authored-by: Marko Bakovic <[email protected]>
1 parent 12d1f51 commit 7987e30

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

pyls_jsonrpc/endpoint.py

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def _handle_response(self, msg_id, result=None, error=None):
236236
if error is not None:
237237
log.debug("Received error response to message %s: %s", msg_id, error)
238238
request_future.set_exception(JsonRpcException.from_dict(error))
239+
return
239240

240241
log.debug("Received result for message %s: %s", msg_id, result)
241242
request_future.set_result(result)

test/test_endpoint.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def test_request_cancel(endpoint, consumer):
115115
'params': {'id': MSG_ID}
116116
})
117117

118-
with pytest.raises(exceptions.JsonRpcException) as exc_info:
118+
with pytest.raises((exceptions.JsonRpcException, futures.CancelledError)) as exc_info:
119119
assert future.result(timeout=2)
120-
assert exc_info.type == exceptions.JsonRpcRequestCancelled
120+
assert exc_info.type in (exceptions.JsonRpcRequestCancelled, futures.CancelledError)
121121

122122

123123
def test_consume_notification(endpoint, dispatcher):

test/test_streams.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def test_writer(wfile, writer):
9797

9898
def test_writer_bad_message(wfile, writer):
9999
# A datetime isn't serializable(or poorly serializable),
100-
# ensure the write method doesn't throw
100+
# ensure the write method doesn't throw, but the result could be empty
101+
# or the correct datetime
101102
import datetime
102103
writer.write(datetime.datetime(
103104
year=2019,
@@ -108,12 +109,10 @@ def test_writer_bad_message(wfile, writer):
108109
second=1,
109110
))
110111

111-
if os.name == 'nt':
112-
assert wfile.getvalue() == b''
113-
else:
114-
assert wfile.getvalue() == (
115-
b'Content-Length: 10\r\n'
116-
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
117-
b'\r\n'
118-
b'1546304461'
119-
)
112+
assert wfile.getvalue() in [
113+
b'',
114+
b'Content-Length: 10\r\n'
115+
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
116+
b'\r\n'
117+
b'1546304461'
118+
]

0 commit comments

Comments
 (0)