Best Python code snippet using prospector_python
picraftzero_testcases.py
Source:picraftzero_testcases.py
...24 printer.name = "print_local_joystick"25 printer.source = joystick_right.values26def print_remote_joystick(joystick_id = 0):27 printer.name = "print_remote_joystick"28 printer.source = filter_messages(messages.values, type='JOYSTICK', id=joystick_id)29def print_combined_joysticks(joystick_id = 0):30 printer.name = "print_combined_joysticks"31 printer.source = join_values(filter_messages(messages.values, type='JOYSTICK', id=joystick_id), joystick_right.values)32def print_local_joystick_scaled():33 printer.name = "print_local_joystick_scaled"34 printer.source = scaled_pair(joystick_right.values, 180, 0, -100, 100)35def print_local_joystick_mixed():36 printer.name = "print_local_joystick_mixed"37 printer.source = steering_mixer(joystick_right.values)38def print_local_joysticks():39 printer.name = "joystick_right.values"40 printer.source = joystick_right.values41 printer2.name = "joystick_left.values"42 printer2.source = joystick_left.values43def my_steering_mixer(yaw, throttle):44 max_power = 10045 yaw = yaw if yaw else 046 throttle = throttle if throttle else 047 left = throttle + yaw48 right = throttle - yaw49 scale = float(max_power) / max(1, abs(left), abs(right))50 # must return a 2 element tuple51 return int(left * scale), int(right * scale)52def print_local_joystick_custom_steering_mixer():53 printer.name = "print_local_joystick_custom_steering_mixer"54 printer.source = custom_source_tool(my_steering_mixer, joystick_right.values)55def print_pantilt_three_combined_streams():56 # Map input values from local and remote joysticks (scaled)57 # Accepts remote 'PANTILT' messages that (scaling not required)58 printer.name = "print_pantilt_three_combined_streams"59 printer.source = join_values(60 scaled_pair(joystick_left.values, 0, 180, -100, 100),61 scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), 0, 180, -100, 100),62 filter_messages(messages.values, type='PANTILT', id=0)63 )64def triple_input_filter():65 printer.name = "triple_input_filter"66 printer.source = join_values(67 joystick_left.values,68 filter_messages(messages.values, type='JOYSTICK', id=1),69 filter_messages(messages.values, type='PANTILT', id=0),70 )71def triple_input_filter_all_input_scaled():72 printer.name = "triple_input_filter_all_input_scaled"73 printer.source = join_values(74 scaled_pair(joystick_left.values, -10, 10, -100, 100),75 scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=0), -50, 50, -100, 100),76 scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), -10, 10, -100, 100),77 )78def triple_input_filter_all_input_scaled_pantilt_conversion():79 printer.name = "triple_input_filter_all_input_scaled_pantilt_conversion"80 printer.source = pantilt_converter(81 join_values(82 scaled_pair(joystick_left.values, -10, 10, -100, 100),83 scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=0), -50, 50, -100, 100),84 scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), -10, 10, -100, 100),85 )86 )87def dual_triple_input_filter_all_input_scaled_pantilt_conversion():88 printer.name = "dual_triple_input_filter_all_input_scaled_pantilt_conversion__ONE"89 printer.source = pantilt_converter(90 join_values(91 scaled_pair(joystick_left.values, -10, 10, -100, 100),92 scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=0), -50, 50, -100, 100),93 scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), -10, 10, -100, 100),94 )95 )96 printer2.name = "dual_triple_input_filter_all_input_scaled_pantilt_conversion__TWO"97 printer2.source = pantilt_converter(98 join_values(99 scaled_pair(joystick_left.values, -10, 10, -100, 100),100 scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=0), -50, 50, -100, 100),101 scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), -10, 10, -100, 100),102 )103 )104# ---105# HArdware interation tests106def local_joystick_wheelbase():107 wheelbase.source = steering_mixer(joystick_right.values)108 #wheelbase.source = joystick_right.values109def local_joystick_pantilt():110 pan_tilt.source = pantilt_converter(joystick_left.values)111def remote_joystick_wheelbase():112 wheelbase.source = steering_mixer(filter_messages(messages.values, type='JOYSTICK', id=0) )113def remote_joystick_pantilt():114 pan_tilt.source = pantilt_converter(filter_messages(messages.values, type='JOYSTICK', id=1))115def local_joystick_wheelbase_pantilt():116 wheelbase.source = steering_mixer(joystick_right.values)117 pan_tilt.source = pantilt_converter(joystick_left.values)118def dual_joystick_wheelbase():119 wheelbase.source = join_values(120 joystick_right.values,121 filter_messages(messages.values, type='JOYSTICK', id=0),122 )123def dual_joystick_pantilt():124 pan_tilt.source = join_values(125 joystick_left.values,126 filter_messages(messages.values, type='JOYSTICK', id=1),127 )128def dual_joystick_wheelbase_pantilt():129 wheelbase.source = join_values(130 joystick_right.values,131 filter_messages(messages.values, type='JOYSTICK', id=0),132 )133 pan_tilt.source = join_values(134 joystick_left.values,135 filter_messages(messages.values, type='JOYSTICK', id=1),136 )137def triple_input_pantilt_no_scaling_no_conversion():138 pan_tilt.source = join_values(139 joystick_left.values,140 filter_messages(messages.values, type='JOYSTICK', id=1),141 filter_messages(messages.values, type='PANTILT', id=0),142 )143def triple_input_pantilt_scaling_no_conversion():144 pan_tilt.source = join_values(145 filter_messages(messages.values, type='JOYSTICK', id=1),146 filter_messages(messages.values, type='PANTILT', id=0),147 scaled_pair(joystick_left.values, 0, 180, -100, 100),148 )149# Mock Robots150def mock_robot_builtin_pantilt_conversion():151 printer.name = "mock_robot_builtin_pantilt_conversion___WHEELS"152 printer.source = steering_mixer(153 join_values(154 filter_messages(messages.values, type='JOYSTICK', id=0),155 joystick_right.values156 )157 )158 printer2.name = "mock_robot_builtin_pantilt_conversion__PANTILT"159 printer2.source = join_values(160 filter_messages(messages.values, type='PANTILT', id=0),161 pantilt_converter(162 join_values(163 scaled_pair(joystick_left.values, -10, 10, -100, 100),164 filter_messages(messages.values, type='JOYSTICK', id=1),165 )166 )167 )168def mock_robot():169 printer.name = "mock_robot___WHEELS"170 printer.source = steering_mixer(171 join_values(172 filter_messages(messages.values, type='JOYSTICK', id=0),173 joystick_right.values174 )175 )176 printer2.name = "mock_robot__PANTILT"177 printer2.source = join_values(178 filter_messages(messages.values, type='PANTILT', id=0),179 scaled_pair(180 join_values(joystick_left.values, filter_messages(messages.values, type='JOYSTICK', id=1)), 180, 0, -100, 100),181 )182# ------------------------------------------------183# Robots184def simple_robot_local_joystick():185 wheelbase.source = steering_mixer(joystick_right.values)186 pan_tilt.source = pantilt_converter(joystick_left.values)187def simple_robot_dual_joystick():188 wheelbase.source = steering_mixer(join_values(189 joystick_right.values,190 filter_messages(messages.values, type='JOYSTICK', id=0))191 )192 pan_tilt.source = pantilt_converter(join_values(193 joystick_left.values,194 filter_messages(messages.values, type='JOYSTICK', id=1)))195def robot():196 wheelbase.source = steering_mixer(197 join_values(198 filter_messages(messages.values, type='JOYSTICK', id=0),199 joystick_right.values200 )201 )202 pan_tilt.source = join_values(203 filter_messages(messages.values, type='PANTILT', id=0),204 scaled_pair(205 join_values(joystick_left.values, filter_messages(messages.values, type='JOYSTICK', id=1)), 180, 0, -100, 100),206 # filter_messages(messages.values, type='PANTILT', id=0),207 # scaled_pair(joystick_left.values, 0, 180, -100, 100),208 # scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), 0, 180, -100, 100),209 )210# ---211# Start the music, light the lights...212#triple_input_filter()213#triple_input_filter_all_input_scaled()214#triple_input_filter_all_input_scaled_pantilt_conversion()215#dual_triple_input_filter_all_input_scaled_pantilt_conversion()216#print_local_joystick()217#print_local_joysticks()218#print_remote_joystick()219#print_combined_joysticks()220#print_local_joystick_scaled()221#print_local_joystick_mixed()222#print_local_joystick_custom_steering_mixer()...
runBot.py
Source:runBot.py
...20 def __loop(self):21 while self.status_work_bot:22 all_messages = self.__get_messages()23 if all_messages:24 filter_messages = self.__filter_messages(all_messages)25 if filter_messages:26 self.__response_handler(filter_messages)27 time.sleep(self.TIME_BETWEEN_REQUESTS)28 def __get_messages(self) -> list:29 """ ÐолÑÑение вÑеÑ
ÑообÑений """30 return self.telegram_api.update()31 def __filter_messages(self, messages: list) -> list:32 """ ÐÑÑилÑÑÑоваÑÑ ÑообÑÐµÐ½Ð¸Ñ """33 filter_messages = list()34 for message in messages[::-1]:35 d_user = self.db_users.filter_by(id=message['message']['from']['id']).first()36 if not d_user:37 logger.info(f"unknown user : {message['message']['from']}")38 continue39 if message['update_id'] <= d_user.updateId:40 continue41 if not d_user.updateId == 0:42 filter_messages.append(message)43 d_user.updateId = message['update_id']44 db_session.commit()45 return filter_messages...
test_monitor.py
Source:test_monitor.py
...78 @classmethod79 def tearDownClass(cls):80 cls.MESSAGES.clear()81 _delete_working_dir()82 def filter_messages(self, *types: MessageType, method: str = None) -> List[Tuple[str, Message]]:83 def gen_messages():84 callstack = []85 # for variant in filter(lambda m: m.type in types, self.MESSAGES):86 for variant in self.MESSAGES:87 if variant.type == message_pb2.METHOD_ENTER:88 callstack.append(variant.method_enter.method)89 elif variant.type == message_pb2.METHOD_EXIT:90 callstack.pop()91 if variant.type not in types:92 continue93 if method:94 if method not in callstack:95 continue96 which = variant.WhichOneof("payload")97 self.assertIsNotNone(which)98 payload = getattr(variant, which)99 self.assertIsNotNone(payload)100 yield which, MessageToDict(payload, including_default_value_fields=True)101 return list(gen_messages())102 def test_definitions(self):103 msgs = self.filter_messages(message_pb2.CLASS_DEF)104 self.assertEqual(len(msgs), 1)105 self.assertEqual(msgs[0], oracles.definitions)106 def test_allocations(self):107 msgs = self.filter_messages(108 message_pb2.ALLOC_OBJECT, message_pb2.ALLOC_ARRAY,109 method="testAllocations"110 )111 self.assertEqual(msgs, oracles.allocations)112 def test_deallocations(self):113 msgs = self.filter_messages(message_pb2.DEALLOC)114 # ensure at least some dealloc events were emitted115 self.assertGreater(len(msgs), 16)116 def test_callstack(self):117 msgs = self.filter_messages(message_pb2.METHOD_ENTER, message_pb2.METHOD_EXIT, method="testMethodCalls")118 self.assertEqual(msgs, oracles.callstack)119 def test_getfield(self):120 msgs = self.filter_messages(121 message_pb2.GETFIELD,122 method="testGetField"123 )124 self.assertEqual(msgs, oracles.getfield)125 def test_putfield(self):126 msgs = self.filter_messages(127 message_pb2.PUTFIELD_PRIMITIVE, message_pb2.PUTFIELD_OBJECT,128 method="<init>"129 )130 self.assertEqual(msgs, oracles.putfield)131 def test_local_vars(self):132 msgs = self.filter_messages(133 message_pb2.LOAD, message_pb2.STORE_OBJECT, message_pb2.STORE_PRIMITIVE,134 method="testLocalVars")135 self.assertEqual(msgs, oracles.local_vars)136 def test_arrays(self):137 msgs = self.filter_messages(138 message_pb2.LOAD_ARRAY, message_pb2.STORE_OBJECT_IN_ARRAY, message_pb2.STORE_PRIMITIVE_IN_ARRAY,139 method="testArrays")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!