Best Python code snippet using playwright-python
py_walk.py
Source:py_walk.py
...36 serialize_message(imu_msg),37 serialize_message(jointstate_msg),38 serialize_message(pressure_left),39 serialize_message(pressure_right))40 result = deserialize_message(stepi, JointCommand)41 return result42 def step_relative(self, dt: float, step_msg: Twist, imu_msg, jointstate_msg, pressure_left, pressure_right):43 if dt == 0.0:44 # preventing weird spline interpolation errors on edge case45 dt = 0.00146 stepi = self.py_walk_wrapper.step_relative(47 dt,48 serialize_message(step_msg),49 serialize_message(imu_msg),50 serialize_message(jointstate_msg),51 serialize_message(pressure_left),52 serialize_message(pressure_right))53 result = deserialize_message(stepi, JointCommand)54 return result55 def step_open_loop(self, dt: float, cmdvel_msg: Twist):56 if dt == 0.0:57 # preventing weird spline interpolation errors on edge case58 dt = 0.00159 stepi = self.py_walk_wrapper.step_open_loop(dt, serialize_message(cmdvel_msg))60 result = deserialize_message(stepi, PoseArray)61 return result62 def get_left_foot_pose(self):63 foot_pose = self.py_walk_wrapper.get_left_foot_pose()64 result = deserialize_message(foot_pose, Pose)65 return result66 def get_right_foot_pose(self):67 foot_pose = self.py_walk_wrapper.get_right_foot_pose()68 result = deserialize_message(foot_pose, Pose)69 return result70 def set_parameters(self, param_dict):71 parameters = parse_parameter_dict(namespace="", parameter_dict=param_dict)72 for parameter in parameters:73 self.py_walk_wrapper.set_parameter(serialize_message(parameter))74 def get_phase(self):75 return self.py_walk_wrapper.get_phase()76 def get_freq(self):77 return self.py_walk_wrapper.get_freq()78 def get_odom(self):79 odom = self.py_walk_wrapper.get_odom()80 result = deserialize_message(odom, Odometry)81 return result82 def publish_debug(self):83 self.py_walk_wrapper.publish_debug()84 def test_memory_leak_from(self, twist_msg):85 self.py_walk_wrapper.test_memory_leak_from(serialize_message(twist_msg))86 def test_memory_leak_to(self):87 self.py_walk_wrapper.test_memory_leak_to()88 def test_memory_leak_methods(self, msg):...
message_server.py
Source:message_server.py
...5import json6import sys7def default_serialize_message(sender_name, recipient, message):8 return json.dumps([sender_name, recipient, message])9def default_deserialize_message(serialized_message):10 sender_name, recipient, message = json.loads(serialized_message)11 return sender_name, recipient, message12class MessageHandler(object):13 """14 The MessageHandler (or any object which inherits from MessageHandler) must15 implement handle_message and send_message.16 """17 def handle_message(self, sender, message):18 raise NotImplemented19 def send_message(self, recipient, message):20 raise NotImplemented21 def _initialize_message_handler(self, message_handler_id, message_server):22 self._message_handler_id = message_handler_id23 self._message_server = message_server24 def queue_message(self, recipient, message):25 self._message_server.queue_message(self._message_handler_id,26 recipient,27 message)28class MessageServer(asyncore.dispatcher):29 """30 A select()-based async message-passing server. This 31 """32 def __init__(self, host, port, message_handlers,33 serialize_message=default_serialize_message,34 max_message_size=8192,35 deserialize_message=default_deserialize_message):36 asyncore.dispatcher.__init__(self)37 self.max_message_size = max_message_size38 self.message_handlers = {}39 self.write_buffer = ''40 self.buffer_recipient = None41 self.host = host42 self.port = port43 self.deserialize_message = deserialize_message44 self.serialize_message = serialize_message45 self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)46 self.bind((host, port))47 for handler_name in message_handlers:48 handler_object = message_handlers[handler_name]49 self.set_handler(handler_name, handler_object)50 self.message_queue = collections.deque()51 def set_handler(self, handler_name, handler_object):52 handler_object._initialize_message_handler(handler_name, self)53 self.message_handlers[handler_name] = handler_object54 def handle_read(self):55 raw_message, (host, port) = self.recvfrom(self.max_message_size)56 try:57 sender_name, recipient, message = self.deserialize_message(raw_message)58 except Exception as err:59 print >> sys.stderr, "Error on message deserialzation: %s" % err60 else:61 sender = (host, port, sender_name)62 handler = self.message_handlers.get(recipient)63 if handler:64 handler.handle_message(sender, message)65 def writable(self):66 return self.write_buffer or self.message_queue67 def handle_write(self):68 if not self.write_buffer:69 self.buffer_recipient, self.write_buffer = self.message_queue.popleft()70 else:71 sent_bytes = self.sendto(self.write_buffer, self.buffer_recipient)...
test_serialization.py
Source:test_serialization.py
...45def test_serialize_deserialize(msgs, msg_type):46 """Test message serialization/deserialization."""47 for msg in msgs:48 msg_serialized = serialize_message(msg)49 msg_deserialized = deserialize_message(msg_serialized, msg_type)50 assert msg == msg_deserialized51def test_set_float32():52 """Test message serialization/deserialization of float32 type."""53 # During (de)serialization we convert to a C float before converting to a PyObject.54 # This can result in a loss of precision55 msg = BasicTypes()56 msg.float32_value = 1.125 # can be represented without rounding57 msg_serialized = serialize_message(msg)58 msg_deserialized = deserialize_message(msg_serialized, BasicTypes)59 assert msg.float32_value == msg_deserialized.float32_value60 msg = BasicTypes()61 msg.float32_value = 3.14 # can NOT be represented without rounding62 msg_serialized = serialize_message(msg)63 msg_deserialized = deserialize_message(msg_serialized, BasicTypes)...
rclpy_923.py
Source:rclpy_923.py
...19 rclpy.init()20 msg = std_msgs.msg.String()21 msg.data = 'foobar'22 msg_serialized = rclpy.serialization.serialize_message(msg)23 msg_deserialized = rclpy.serialization.deserialize_message(msg_serialized, std_msgs.msg.String)24 try:25 msg_deserialized = rclpy.serialization.deserialize_message(b"", std_msgs.msg.String)26 except Exception as e:27 print(e)28 #logging.error(traceback.format_exc())29 rclpy.shutdown()30if __name__ == '__main__':...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!