def test_invalid_json_error(): def callback(_, __): """ empty callback func :param _: :param __: :return: """ print('done') sub = Subscription(stream_id, stream_partition, 'api_key', callback) def on_gap(_, __): """ should not detect a gap :param _: :param __: :return: """ raise Exception('GapDetectError') sub.on('gap', on_gap) msg1 = create_msg() msg3 = create_msg(3, 2) sub.handle_message(msg1) error = InvalidJsonError(stream_id, 'invalid json', 'test error msg', create_msg(2, 1)) sub.handle_error(error) sub.handle_message(msg3)
def test_handle_error(): err = Exception('Test error') def callback(_, __): """ should not be called :param _: :param __: :return: """ raise Exception('handleErrorFailed') sub = Subscription(stream_id, stream_partition, 'api_key', callback) def test(msg): assert isinstance(msg, Exception) assert str(msg) == 'Test error' sub.on('error', test) sub.handle_error(err)