def test_message_encode(): msg = create_msg() encoded_msg = message_encode(msg) decoded_msg = message_decode(encoded_msg) assert msg.id == decoded_msg.id assert msg.source_address == decoded_msg.source_address assert msg.history == decoded_msg.history
def test_message_encode_shared_memory(): generator = DummyGenerator() msg = create_msg() encoded_msg = message_encode(msg, generator) decoded_msg = message_decode(encoded_msg) assert msg.id == decoded_msg.id assert msg.source_address == decoded_msg.source_address assert msg.history == decoded_msg.history generator.cleanup()
def test_prediction_payload_decode_encode(): preds = {"test": 1} msg = Message(preds.copy(), "localhost") assert isinstance(msg.payload, PredictionPayload) encoded_message = message_encode(msg) decoded_message = message_decode(encoded_message) decoded_message_data = decoded_message.get_payload() assert preds == decoded_message_data
def main_logic(self, *args, **kwargs): msg = self.q_handler.non_blocking_get() if msg: msg.record_exit(self.component_name, self.logger) encoded_msg = message_encode(msg) self.msg_handler.send(self.out_key, encoded_msg) return True else: return False
def test_frame_metadata_payload_decode_encode(): metadata_dictionary = {"id": 2} img = np.random.rand(576, 720, 3) msg = Message((img, metadata_dictionary.copy()), "localhost") assert isinstance(msg.payload, FrameMetadataPayload) encoded_message = message_encode(msg) decoded_message = message_decode(encoded_message) decoded_message_data = decoded_message.get_payload() assert decoded_message_data[1] == metadata_dictionary
def main_logic(self, *args, **kwargs): try: msg = self.queue.get(block=False) msg.record_exit(self.component_name, self.logger) encoded_msg = message_encode(msg) self.msg_handler.send(encoded_msg, self.out_key) time.sleep(0) return True except Empty: time.sleep(0) # yield the control of the thread return False