class TestCommandTranscoder(TestCase): def setUp(self): self.base_command = BaseCommand() self.command_transcoder = CommandTranscoder() def test_encode_command(self): self.assertDictEqual(self.base_command.as_dict(), self.command_transcoder.encode_command(self.base_command)) def test_decode_command(self): dictionary = self.base_command.__dict__ self.assertEqual(self.base_command, self.command_transcoder.decode_command(dictionary))
def _dequeue_command(self) -> BaseCommand: """ Pops a command from the incoming message queue. :return: None """ in_full.acquire() in_mutex.acquire() print(self._in_queue) command = CommandTranscoder.decode_command( self._in_queue.pop(0) ) in_mutex.release() in_free.release() return command
def _receive_result(self): socket = JSONSocket( self._server_address, self._server_port + 1 ) try: dictionary = socket.receive_dict() except Exception as e: print(e) return None if "_type" in dictionary.keys(): if dictionary["_type"] in CommandTranscoder.type_class_map.keys(): response = CommandTranscoder.decode_command(dictionary) return response return dictionary