def test_make_result_answer(self, fetcher_message, count): fetcher_messages = list(repeat(fetcher_message, count)) message = make_result_answer(*fetcher_messages) cmc_msg = CMCMessage.from_bytes(message) assert len(fetcher_messages) == count assert cmc_msg.header.name == "fetch" assert cmc_msg.header.state == CMCHeader.State.RESULT assert cmc_msg.header.log_level.strip() == "" assert cmc_msg.header.payload_length == len(message) - len(cmc_msg.header) assert cmc_msg.header.payload_length == count * len(fetcher_message) assert not set(cmc_msg.payload) ^ set(fetcher_messages)
def test_make_log_answer(self): log_message = "the log message" level = logging.WARN message = make_log_answer(log_message, level) cmc_msg = CMCMessage.from_bytes(message) assert cmc_msg.header.name == "fetch" assert cmc_msg.header.state == CMCHeader.State.LOG assert cmc_msg.header.log_level.strip() == "warning" assert cmc_msg.header.payload_length == len(message) - len(cmc_msg.header) assert cmc_msg.header.payload_length == len(log_message)
def test_from_bytes(self, eor): assert CMCMessage.from_bytes(bytes(eor)) == eor
def test_from_bytes(self, message): assert CMCMessage.from_bytes(bytes(message)) == message