def consume(self, message_type): """ Consume the data in this stream by yielding `message_type` messages, or raising if the stream was closed with an error. """ while True: item = self.queue.get() if isinstance(item, GrpcError): raise item elif item is STREAM_END: break compressed, message_data = item if compressed: message_data = decompress(message_data) message = message_type() message.ParseFromString(message_data) yield message
def test_unsupported_algorithm(self): payload = b"\x00" * 1000 with pytest.raises(UnsupportedEncoding): decompress(payload) # not correctly encoded
def test_fallback_algorithm(self): payload = b"\x00" * 1000 assert decompress(gzip.compress(payload)) == payload
def test_preferred_algorithm(self): payload = b"\x00" * 1000 assert decompress(zlib.compress(payload)) == payload