How to use __getitem__ method in pyatom

Best Python code snippet using pyatom_python

api.py

Source:api.py Github

copy

Full Screen

1from sakura.hub.web.apitools import api_init, pack2from sakura.hub.code import list_code_revisions, list_operator_subdirs3from sakura.common.events import EventsAggregator4api = api_init()5EVENTS = EventsAggregator()6# Caution: this GuiToHubAPI class is instanciated once for each web connection!7@api8class GuiToHubAPI:9 def __init__(self, context):10 self.context = context11 # Events12 ########################################13 @property14 def event_listener_id(self):15 # use the web session ID to uniquely identify this event listener16 return self.context.session.id17 def events_monitor(self, obj, obj_id):18 EVENTS.monitor(self.event_listener_id, obj.all_events, obj_id)19 @api.events.unmonitor20 def events_unmonitor(self, obj_id):21 EVENTS.unmonitor(self.event_listener_id, obj_id)22 @api.events.next_events23 def events_next_events(self, timeout):24 evts = EVENTS.next_events(self.event_listener_id, timeout)25 for evt in evts:26 print('notify to GUI', *evt)27 return evts28 ########################################29 # Daemons30 @api.daemons.list31 def list_daemons(self):32 return pack(self.context.daemons)33 ########################################34 # Operator classes35 @property36 def op_classes(self):37 return self.context.op_classes.filter_for_current_user()38 @api.op_classes.list39 def list_operators_classes(self):40 return pack(self.op_classes)41 @api.op_classes.__getitem__.info42 def get_operator_class_info(self, cls_id):43 return pack(self.op_classes[cls_id])44 @api.op_classes.register45 def register_op_class(self, **cls_repo_info):46 return self.op_classes.register(self.context, **cls_repo_info)47 @api.op_classes.__getitem__.unregister48 def unregister_op_class(self, cls_id):49 return self.op_classes[cls_id].unregister()50 @api.op_classes.__getitem__.update_default_revision51 def update_op_class_default_revision(self, cls_id, code_ref, commit_hash):52 return self.op_classes[cls_id].update_default_revision(code_ref, commit_hash)53 ########################################54 # Operator instances55 # instantiate an operator and return the instance info56 @api.operators.create57 def create_operator_instance(self, dataflow_id, cls_id, gui_data = '', local_streams=None):58 return self.dataflows[dataflow_id].create_operator_instance(59 cls_id, gui_data=gui_data, local_streams=local_streams)60 # delete operator instance and links involved61 @api.operators.__getitem__.delete62 def delete_operator_instance(self, op_id):63 return self.context.op_instances[op_id].delete_instance()64 # returns info about operator instance: cls_name, inputs, outputs, parameters65 @api.operators.__getitem__.info66 def get_operator_instance_info(self, op_id):67 return pack(self.context.op_instances[op_id])68 @api.operators.__getitem__.monitor69 def operator_instance_monitor(self, op_id, obj_id):70 self.events_monitor(self.context.op_instances[op_id], obj_id)71 @api.operators.__getitem__.reload72 def update_op_revision(self, op_id):73 return self.context.op_instances[op_id].reload()74 @api.operators.__getitem__.update_revision75 def update_op_revision(self, op_id, code_ref, commit_hash, all_ops_of_cls=False):76 return self.context.op_instances[op_id].update_revision(code_ref, commit_hash, all_ops_of_cls)77 @api.operators.__getitem__.parameters.__getitem__.set_value78 def set_parameter_value(self, op_id, param_id, value):79 return self.context.op_params.lookup(op_id, param_id).set_value(value)80 @api.operators.__getitem__.inputs.__getitem__.info81 def get_operator_input_info(self, op_id, in_id):82 return pack(self.context.op_instances[op_id].input_plugs[in_id])83 @api.operators.__getitem__.inputs.__getitem__.get_range84 def get_operator_input_range(self, op_id, in_id, row_start, row_end):85 return pack(self.context.op_instances[op_id].input_plugs[in_id].get_range(row_start, row_end))86 @api.operators.__getitem__.inputs.__getitem__.chunks87 def get_operator_input_chunks(self, op_id, in_id, allow_approximate=False):88 yield from self.context.op_instances[op_id].input_plugs[in_id].chunks(allow_approximate=allow_approximate)89 @api.operators.__getitem__.outputs.__getitem__.info90 def get_operator_output_info(self, op_id, out_id):91 return pack(self.context.op_instances[op_id].output_plugs[out_id])92 @api.operators.__getitem__.outputs.__getitem__.get_range93 def get_operator_output_range(self, op_id, out_id, row_start, row_end):94 return pack(self.context.op_instances[op_id].output_plugs[out_id].get_range(row_start, row_end))95 @api.operators.__getitem__.outputs.__getitem__.chunks96 def get_operator_output_chunks(self, op_id, out_id, allow_approximate=False):97 yield from self.context.op_instances[op_id].output_plugs[out_id].chunks(allow_approximate=allow_approximate)98 @api.operators.__getitem__.outputs.__getitem__.get_link_id99 def get_operator_outputplug_link_id(self, op_id, out_id):100 return self.context.op_instances[op_id].get_ouputplug_link_id(out_id)101 @api.operators.__getitem__.fire_event102 def fire_operator_event(self, op_id, *args, **kwargs):103 return self.context.op_instances[op_id].sync_handle_event(*args, **kwargs)104 @api.operators.__getitem__.opengl_apps.__getitem__.info105 def get_opengl_app_info(self, op_id, ogl_id):106 return pack(self.context.op_instances[op_id].opengl_apps[ogl_id])107 @api.operators.__getitem__.opengl_apps.__getitem__.fire_event108 def fire_opengl_app_event(self, op_id, ogl_id, *args, **kwargs):109 return self.context.op_instances[op_id].opengl_apps[ogl_id].fire_event(*args, **kwargs)110 @api.operators.__getitem__.opengl_apps.__getitem__.monitor111 def opengl_app_monitor(self, op_id, ogl_id, obj_id):112 self.events_monitor(self.context.op_instances[op_id].opengl_apps[ogl_id], obj_id)113 ########################################114 # Operator files115 @api.operators.__getitem__.get_file_content116 def get_operator_file_content(self, op_id, file_path):117 return self.context.op_instances[op_id].get_file_content(file_path)118 @api.operators.__getitem__.get_file_tree119 def get_operator_file_tree(self, op_id):120 return self.context.op_instances[op_id].get_file_tree()121 @api.operators.__getitem__.save_file_content122 def save_operator_file_content(self, op_id, file_path, file_content):123 return self.context.op_instances[op_id].save_file_content(file_path, file_content)124 @api.operators.__getitem__.create_file125 def new_operator_file(self, op_id, file_path, file_content):126 return self.context.op_instances[op_id].new_file(file_path, file_content)127 @api.operators.__getitem__.create_directory128 def new_operator_directory(self, op_id, dir_path):129 return self.context.op_instances[op_id].new_directory(dir_path)130 @api.operators.__getitem__.move_file131 def move_operator_file(self, op_id, file_src, file_dst):132 return self.context.op_instances[op_id].move_file(file_src, file_dst)133 @api.operators.__getitem__.delete_file134 def delete_operator_file(self, op_id, file_path):135 return self.context.op_instances[op_id].delete_file(file_path)136 ########################################137 # Links138 @api.links.__getitem__.info139 def get_link_info(self, link_id):140 return pack(self.context.links[link_id])141 @api.links.create142 def create_link(self, src_op_id, src_out_id, dst_op_id, dst_in_id):143 return self.context.create_link(src_op_id, src_out_id, dst_op_id, dst_in_id)144 @api.links.__getitem__.delete145 def delete_link(self, link_id):146 return self.context.links[link_id].delete_link()147 @api.links.__getitem__.monitor148 def link_monitor(self, link_id, obj_id):149 self.events_monitor(self.context.links[link_id], obj_id)150 @api.links.list_possible151 def get_possible_links(self, src_op_id, dst_op_id):152 return self.context.get_possible_links(src_op_id, dst_op_id)153 ########################################154 # Gui155 @api.operators.__getitem__.set_gui_data156 def set_operator_instance_gui_data(self, op_id, gui_data):157 self.context.op_instances[op_id].set_gui_data(gui_data)158 @api.operators.__getitem__.get_gui_data159 def get_operator_instance_gui_data(self, op_id):160 return self.context.op_instances[op_id].gui_data161 @api.links.__getitem__.set_gui_data162 def set_link_gui_data(self, link_id, gui_data):163 self.context.links[link_id].gui_data = gui_data164 @api.links.__getitem__.get_gui_data165 def get_link_gui_data(self, link_id):166 return self.context.links[link_id].gui_data167 ########################################168 # Datastores169 @property170 def datastores(self):171 self.context.datastores.refresh_offline_datastores()172 return self.context.datastores.filter_for_current_user()173 @api.datastores.list174 def list_datastores(self):175 return pack(self.datastores)176 @api.datastores.__getitem__.info177 def get_datastore_info(self, datastore_id):178 return self.datastores[datastore_id].get_full_info()179 @api.datastores.__getitem__.grants.request180 def request_datastore_grant(self, datastore_id, grant_name, text):181 return self.datastores[datastore_id].handle_grant_request(grant_name, text)182 @api.datastores.__getitem__.grants.deny183 def deny_datastore_grant(self, datastore_id, login):184 return self.datastores[datastore_id].deny_grant_request(login)185 @api.datastores.__getitem__.update186 def update_datastore_info(self, datastore_id, **kwargs):187 self.datastores[datastore_id].parse_and_update_attributes(**kwargs)188 @api.datastores.__getitem__.grants.update189 def update_datastore_grant(self, datastore_id, login, grant_name):190 return self.datastores[datastore_id].update_grant(login, grant_name)191 @api.datastores.__getitem__.list_expected_columns_tags192 def list_expected_columns_tags(self, datastore_id):193 return self.datastores[datastore_id].list_expected_columns_tags()194 ########################################195 # Databases196 @property197 def databases(self):198 self.context.datastores.refresh_offline_datastores()199 return self.context.databases.filter_for_current_user()200 @api.databases.list201 def list_databases(self):202 return pack(self.databases)203 @api.databases.__getitem__.info204 def get_database_info(self, database_id):205 return self.databases[database_id].get_full_info()206 @api.databases.create207 def new_database(self, datastore_id, name, **kwargs):208 # optional arguments of kwargs: short_desc, creation_date, tags, contacts209 # returns the database_id210 datastore = self.datastores[datastore_id]211 return self.databases.create_db(datastore, name, **kwargs)212 @api.databases.__getitem__.update213 def update_database_info(self, database_id, **kwargs):214 # optional arguments of kwargs: name, short_desc, creation_date, tags, contacts215 self.databases[database_id].parse_and_update_attributes(**kwargs)216 @api.databases.__getitem__.grants.update217 def update_database_grant(self, database_id, login, grant_name):218 self.databases[database_id].update_grant(login, grant_name)219 @api.databases.__getitem__.grants.request220 def request_database_grant(self, database_id, grant_name, text):221 return self.databases[database_id].handle_grant_request(grant_name, text)222 @api.databases.__getitem__.grants.deny223 def deny_database_grant(self, database_id, login):224 return self.databases[database_id].deny_grant_request(login)225 @api.databases.__getitem__.delete226 def delete_database(self, database_id):227 return self.context.databases[database_id].delete_database()228 ########################################229 # Tables230 @api.tables.__getitem__.info231 def get_table_info(self, table_id):232 return pack(self.context.tables[table_id])233 @api.tables.create234 def new_table(self, database_id, name, columns, **kwargs):235 # optional arguments of kwargs: short_desc, creation_date236 # returns the table_id237 database = self.databases[database_id]238 return self.context.tables.create_table(239 database, name, columns, **kwargs)240 @api.tables.__getitem__.update241 def update_table_info(self, table_id, **kwargs):242 # optional arguments of kwargs: name, description, creation_date243 self.context.tables[table_id].set(**kwargs)244 @api.tables.__getitem__.add_rows245 def add_rows_into_table(self, table_id, data):246 return self.context.tables[table_id].add_rows(data)247 @api.tables.__getitem__.get_rows248 def get_rows_from_table(self, table_id, row_start, row_end):249 return pack(self.context.tables[table_id].get_range(row_start, row_end))250 @api.tables.__getitem__.chunks251 def get_chunks_from_table(self, table_id, allow_approximate=False):252 yield from self.context.tables[table_id].chunks(allow_approximate=allow_approximate)253 @api.tables.__getitem__.delete254 def delete_table(self, table_id):255 return self.context.tables[table_id].delete_table()256 ########################################257 # Dataflow258 @property259 def dataflows(self):260 return self.context.dataflows.filter_for_current_user()261 @api.dataflows.__getitem__.info262 def get_dataflow_info(self, dataflow_id):263 return self.dataflows[dataflow_id].get_full_info()264 @api.dataflows.list265 def list_dataflows(self):266 return self.dataflows.pack()267 @api.dataflows.create268 def new_dataflow(self, name, **kwargs):269 return self.dataflows.create_dataflow(name = name, **kwargs)270 @api.dataflows.__getitem__.monitor271 def dataflow_monitor(self, dataflow_id, obj_id):272 self.events_monitor(self.context.dataflows[dataflow_id], obj_id)273 @api.dataflows.__getitem__.update274 def update_dataflow_info(self, dataflow_id, **kwargs):275 self.dataflows[dataflow_id].parse_and_update_attributes(**kwargs)276 @api.dataflows.__getitem__.grants.update277 def update_dataflow_grant(self, dataflow_id, login, grant_name):278 return self.dataflows[dataflow_id].update_grant(login, grant_name)279 @api.dataflows.__getitem__.grants.request280 def request_dataflow_grant(self, dataflow_id, grant_name, text):281 return self.dataflows[dataflow_id].handle_grant_request(grant_name, text)282 @api.dataflows.__getitem__.grants.deny283 def deny_dataflow_grant(self, dataflow_id, login):284 return self.dataflows[dataflow_id].deny_grant_request(login)285 @api.dataflows.__getitem__.set_gui_data286 def set_dataflow_gui_data(self, dataflow_id, gui_data):287 self.dataflows[dataflow_id].gui_data = gui_data288 @api.dataflows.__getitem__.get_gui_data289 def get_dataflow_gui_data(self, dataflow_id):290 return self.dataflows[dataflow_id].gui_data291 @api.dataflows.__getitem__.delete292 def delete_dataflow(self, dataflow_id):293 return self.dataflows[dataflow_id].delete_dataflow()294 ########################################295 # Project296 @property297 def projects(self):298 return self.context.projects.filter_for_current_user()299 @api.projects.__getitem__.info300 def get_project_info(self, project_id):301 return self.projects[project_id].get_full_info()302 @api.projects.list303 def list_projects(self):304 return self.projects.pack()305 @api.projects.create306 def new_project(self, name, **kwargs):307 return self.projects.create_project(name = name, **kwargs)308 @api.projects.__getitem__.update309 def update_project_info(self, project_id, **kwargs):310 self.projects[project_id].parse_and_update_attributes(**kwargs)311 @api.projects.__getitem__.grants.update312 def update_project_grant(self, project_id, login, grant_name):313 return self.projects[project_id].update_grant(login, grant_name)314 @api.projects.__getitem__.grants.request315 def request_project_grant(self, project_id, grant_name, text):316 return self.projects[project_id].handle_grant_request(grant_name, text)317 @api.projects.__getitem__.grants.deny318 def deny_project_grant(self, project_id, login):319 return self.projects[project_id].deny_grant_request(login)320 @api.projects.__getitem__.delete321 def delete_project(self, project_id):322 return self.projects[project_id].delete_project()323 ########################################324 # Project pages325 @property326 def pages(self):327 return self.context.pages.filter_for_current_user()328 @api.pages.create329 def create_project_page(self, project_id, page_name):330 return self.projects[project_id].create_page(page_name)331 @api.pages.__getitem__.info332 def get_project_page_info(self, page_id):333 return self.pages[page_id].pack()334 @api.pages.__getitem__.update335 def update_project_page(self, page_id, page_name=None, page_content=None):336 return self.pages[page_id].update_page(page_name=page_name, page_content=page_content)337 @api.pages.__getitem__.delete338 def delete_project_page(self, page_id):339 return self.pages[page_id].delete_page()340 # Session management341 ####################342 @api.renew_session343 def renew_session(self):344 return self.context.session.renew()345 # User management346 #################347 @api.users.create348 def new_user(self, **user_info):349 print(user_info)350 return self.context.users.new_user(**user_info)351 @api.login352 def login(self, login_or_email, password):353 log = self.context.login(login_or_email, password)354 return log355 @api.other_login356 def other_login(self, type, ticket, service):357 log = self.context.other_login(type, ticket, service)358 return log359 @api.login_options360 def login_options(self):361 opts = self.context.login_options()362 return opts363 @api.logout364 def logout(self):365 self.context.session.user = None366 @api.recover_password367 def recover_password(self, login_or_email):368 self.context.users.recover_password(login_or_email)369 @api.change_passord370 def change_password(self, login_or_email, current_password_or_rec_token, new_password):371 self.context.users.change_password(372 login_or_email, current_password_or_rec_token, new_password)373 # Note: you can use 'api.users.current' as a shortcut to 'api.users[<current_login>]'374 # in the following API calls.375 @api.users.__getitem__.info376 def get_user_info(self, login):377 return self.context.users[login].get_full_info()378 @api.users.__getitem__.update379 def update_user_info(self, login, **kwargs):380 return self.context.users[login].update_attributes(**kwargs)381 @api.users.__getitem__.privileges.request382 def request_user_privilege(self, login, privilege):383 return self.context.users[login].request_privilege(privilege)384 @api.users.__getitem__.privileges.add385 def add_user_privilege(self, login, privilege):386 return self.context.users[login].add_privilege(privilege)387 @api.users.__getitem__.privileges.remove388 def remove_user_privilege(self, login, privilege):389 return self.context.users[login].remove_privilege(privilege)390 @api.users.__getitem__.privileges.deny391 def deny_user_privilege(self, login, privilege):392 return self.context.users[login].deny_privilege(privilege)393 @api.users.list394 def list_all_users(self):395 return tuple(u.pack() for u in self.context.users.select())396 # Transfers management397 ######################398 @api.transfers.start399 def start_transfer(self):400 return self.context.start_transfer() # return transfer_id401 @api.transfers.__getitem__.get_status402 def get_transfer_status(self, transfer_id):403 return self.context.get_transfer_status(transfer_id)404 @api.transfers.__getitem__.abort405 def abort_transfer(self, transfer_id):406 return self.context.abort_transfer(transfer_id)407 # Misc features408 ###############409 @api.misc.list_code_revisions410 def list_code_revisions(self, repo_url, **opts):411 return list_code_revisions(repo_url, **opts)412 @api.misc.list_operator_subdirs413 def list_operator_subdirs(self, repo_url, code_ref):414 return list_operator_subdirs(repo_url, code_ref)415 # Global features416 #################417 @api.monitor418 def global_monitor(self, obj_id):...

Full Screen

Full Screen

telemetry.py

Source:telemetry.py Github

copy

Full Screen

...68 "Spectator_Car_Index" : packet.spectatorCarIndex,69 "Sli_Pro_Native_Support" : packet.sliProNativeSupport,70 "Num_Marshal_Zones" : packet.numMarshalZones,71 "Marshal_Zones" : packet.marshalZones,72 "Marshal_Zone_Start" : packet.marshalZones.__getitem__(carindex).zoneStart,73 "Marshal_Zone_Flag" : packet.marshalZones.__getitem__(carindex).zoneFlag,74 "Safety_Car_Status_ID" : packet.safetyCarStatus,75 "Safety_Car_Status" : ["No safety car", "full safety car", "virtual safety car"][packet.safetyCarStatus],76 "Network_Game" : packet.networkGame,77 })787980 if isinstance(packet, PacketLapData_V1): 81 telemetry.update({82 "Last_Lap_Time" : packet.lapData.__getitem__(carindex).lastLapTime,83 "Current_Lap_Time": packet.lapData.__getitem__(carindex).currentLapTime,84 "Best_Lap_Time" : packet.lapData.__getitem__(carindex).bestLapTime,85 "Sector_1_Time" : packet.lapData.__getitem__(carindex).sector1Time,86 "Sector_2_Time" : packet.lapData.__getitem__(carindex).sector2Time,87 "Lap_Distance" : packet.lapData.__getitem__(carindex).lapDistance,88 "Total_Distance" : packet.lapData.__getitem__(carindex).totalDistance,89 "Safety_Car_Delta" : packet.lapData.__getitem__(carindex).safetyCarDelta,90 "Car_Position" : packet.lapData.__getitem__(carindex).carPosition,91 "Current_Lap_Num" : packet.lapData.__getitem__(carindex).currentLapNum,92 "Pit_Status_ID" : packet.lapData.__getitem__(carindex).pitStatus,93 "Pit_Status" : ["None", "Pitting", "In Pit Area"][packet.lapData.__getitem__(carindex).pitStatus],94 "Sector_ID" : packet.lapData.__getitem__(carindex).sector,95 "Sector" : ["Sector1", "Sector2", "Sector3"][packet.lapData.__getitem__(carindex).sector],96 "Current_Lap_Invalid" : packet.lapData.__getitem__(carindex).currentLapInvalid,97 "Penalties" : packet.lapData.__getitem__(carindex).penalties,98 "Grid_Position" : packet.lapData.__getitem__(carindex).gridPosition,99 "Driver_Status_ID" : packet.lapData.__getitem__(carindex).driverStatus,100 "Driver_Status" : ["In Garage", "Flying Lap", "In Lap", "Out Lap", "On Track"][packet.lapData.__getitem__(carindex).driverStatus],101 "Result_Status_ID" : packet.lapData.__getitem__(carindex).resultStatus,102 "Result_Status" : ["Invalid", "Inactive", "Active", "Finished", "Disqualified", "Not Classified", "Retired"][packet.lapData.__getitem__(carindex).resultStatus],103 })104 105106 if isinstance(packet, PacketParticipantsData_V1):107 telemetry.update({108 "Num_Active_Cars" : packet.numActiveCars,109 "AI_Controlled" : packet.participants.__getitem__(carindex).aiControlled,110 "Driver_ID" : packet.participants.__getitem__(carindex).driverId,111 "Team_ID" : packet.participants.__getitem__(carindex).teamId, 112 })113114 try:115 telemetry.update({"Driver" : DriverIDs[packet.participants.__getitem__(carindex).driverId]})116 except:117 telemetry.update({"Driver" : "Player"})118119 try:120 telemetry.update({"Team" : TeamIDs[packet.participants.__getitem__(carindex).teamId]})121 except:122 telemetry.update({"Team" : "Not in a team"})123124 telemetry.update({125 "Race_Number" : packet.participants.__getitem__(carindex).raceNumber,126 "Nationality_ID" : packet.participants.__getitem__(carindex).nationality,127 })128129 try:130 telemetry.update({"Nationality" : NationalityIDs[packet.participants.__getitem__(carindex).nationality]})131 except:132 telemetry.update({"Nationality" : "No Nationality"})133134 telemetry.update({135 "Name" : packet.participants.__getitem__(carindex).name,136 "Your_Telemetry_ID" : packet.participants.__getitem__(carindex).yourTelemetry,137 "Your_Telemetry" : ["Restricted", "Public"][packet.participants.__getitem__(carindex).yourTelemetry], 138 })139140141 if isinstance(packet, PacketCarSetupData_V1):142 telemetry.update({143 "Front_Wing" : packet.carSetups.__getitem__(carindex).frontWing,144 "Rear_Wing" : packet.carSetups.__getitem__(carindex).rearWing,145 "On_Throttle" : packet.carSetups.__getitem__(carindex).onThrottle,146 "Off_Throttle" : packet.carSetups.__getitem__(carindex).offThrottle,147 "Front_Camber" : packet.carSetups.__getitem__(carindex).frontCamber,148 "Rear_Camber" : packet.carSetups.__getitem__(carindex).rearCamber,149 "Front_Toe" : packet.carSetups.__getitem__(carindex).frontToe,150 "Rear_Toe" : packet.carSetups.__getitem__(carindex).rearToe,151 "Front_Suspension" : packet.carSetups.__getitem__(carindex).frontSuspension,152 "Rear_Suspension" : packet.carSetups.__getitem__(carindex).rearSuspension,153 "Front_Anti_Roll_Bar" : packet.carSetups.__getitem__(carindex).frontAntiRollBar,154 "Rear_Anti_Roll_Bar" : packet.carSetups.__getitem__(carindex).rearAntiRollBar,155 "Front_Suspension_Height" : packet.carSetups.__getitem__(carindex).frontSuspensionHeight,156 "Rear_Suspension_Height" : packet.carSetups.__getitem__(carindex).rearSuspensionHeight,157 "Brake_Pressure" : packet.carSetups.__getitem__(carindex).brakePressure,158 "Brake_Bias" : packet.carSetups.__getitem__(carindex).brakeBias,159 "Front_Tyre_Pressure" : packet.carSetups.__getitem__(carindex).frontTyrePressure,160 "Rear_Tyre_Pressure" : packet.carSetups.__getitem__(carindex).rearTyrePressure,161 "Ballast" : packet.carSetups.__getitem__(carindex).ballast,162 "Fuel_Load" : packet.carSetups.__getitem__(carindex).fuelLoad,163 })164165166 if isinstance(packet, PacketCarTelemetryData_V1):167 telemetry.update({168 "Speed" : packet.carTelemetryData.__getitem__(carindex).speed,169 "Throttle" : packet.carTelemetryData.__getitem__(carindex).throttle,170 "Steer" : packet.carTelemetryData.__getitem__(carindex).steer,171 "Brake" : packet.carTelemetryData.__getitem__(carindex).brake,172 "Clutch" : packet.carTelemetryData.__getitem__(carindex).clutch,173 "Gear" : packet.carTelemetryData.__getitem__(carindex).gear,174 "Engine_RPM" : packet.carTelemetryData.__getitem__(carindex).engineRPM,175 "DRS" : packet.carTelemetryData.__getitem__(carindex).drs,176 "Rev_Lights_Percent" : packet.carTelemetryData.__getitem__(carindex).revLightsPercent,177 "Brakes_Temperature" : packet.carTelemetryData.__getitem__(carindex).brakesTemperature,178 "Tyres_Surface_Temperature" : packet.carTelemetryData.__getitem__(carindex).tyresSurfaceTemperature,179 "Tyres_Inner_Temperature" : packet.carTelemetryData.__getitem__(carindex).tyresInnerTemperature,180 "Engine_Temperature" : packet.carTelemetryData.__getitem__(carindex).engineTemperature,181 "Tyres_Pressure" : packet.carTelemetryData.__getitem__(carindex).tyresPressure,182 "Surface_Type_ID" : packet.carTelemetryData.__getitem__(carindex).surfaceType,183 })184 185 for x in range(4):186 telemetry.update({187 "Tyre_{}_Surface_Temperature".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).tyresSurfaceTemperature[x],188 "Tyre_{}_Inner_Temperature".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).tyresInnerTemperature[x],189 "Tyre_{}_Brakes_Temperature".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).brakesTemperature[x],190 "Tyre_{}_Pressure".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).tyresPressure[x],191 "Tyre_{}_Surface_Type_ID".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).surfaceType[x],192 "Tyre_{}_Surface_Type".format(tyres[x]) : SurfaceTypes[packet.carTelemetryData.__getitem__(carindex).surfaceType[x]],193 })194195196 if isinstance(packet, PacketCarStatusData_V1):197 telemetry.update({198 "Traction_Control" : packet.carStatusData.__getitem__(carindex).tractionControl,199 "Anti_Lock_Brakes" : packet.carStatusData.__getitem__(carindex).antiLockBrakes,200 "Fuel_Mix_ID" : packet.carStatusData.__getitem__(carindex).fuelMix,201 "Fuel_Mix" : ["Lean", "Standart", "Rich", "Max"][packet.carStatusData.__getitem__(carindex).fuelMix],202 "Front_Brake_Bias" : packet.carStatusData.__getitem__(carindex).frontBrakeBias,203 "Pit_Limiter_Status" : packet.carStatusData.__getitem__(carindex).pitLimiterStatus,204 "Fuel_In_Tank" : packet.carStatusData.__getitem__(carindex).fuelInTank,205 "Fuel_Capacity" : packet.carStatusData.__getitem__(carindex).fuelCapacity,206 "Fuel_Remaining_Laps" : packet.carStatusData.__getitem__(carindex).fuelRemainingLaps,207 "Max_RPM" : packet.carStatusData.__getitem__(carindex).maxRPM,208 "Idle_RPM" : packet.carStatusData.__getitem__(carindex).idleRPM,209 "Max_Gears" : packet.carStatusData.__getitem__(carindex).maxGears,210 "DRS_Allowed" : packet.carStatusData.__getitem__(carindex).drsAllowed,211 "Tyres_Wear" : packet.carStatusData.__getitem__(carindex).tyresWear,212 "Actual_Tyre_Compound_ID" : packet.carStatusData.__getitem__(carindex).actualTyreCompound,213 "Actual_Tyre_Compound" : {16:"F1 Modern C5", 17:"F1 Modern C4", 18:"F1 Modern C3", 19:"F1 Modern C2", 20:"F1 Modern C1", 7:"F1 Modern Intermidiate", 8:"F1 Modern Wet", 9:"F1 Classic Dry",10:"F1 Classic Wet", 11: "F2 Super Soft", 12 : "F2 Soft", 14 : "F2 Medium", 15: "F2 Wet"}[packet.carStatusData.__getitem__(carindex).actualTyreCompound],214 "Tyre_Visual_Compound_ID" : packet.carStatusData.__getitem__(carindex).tyreVisualCompound,215 "Tyre_Visual_Compound" : {16:"F1 Modern Soft", 17:"F1 Modern Medium", 18:"F1 Modern Hard", 7:"F1 Modern Intermidiate", 8:"F1 Modern Wet", 9:"F1 Classic Dry",10:"F1 Classic Wet", 11: "F2 Super Soft", 12 : "F2 Soft", 14 : "F2 Medium", 15: "F2 Wet"}[packet.carStatusData.__getitem__(carindex).tyreVisualCompound],216 "Tyres_Damage" : packet.carStatusData.__getitem__(carindex).tyresDamage,217 "Front_Left_Wing_Damage" : packet.carStatusData.__getitem__(carindex).frontLeftWingDamage,218 "Front_Right_Wing_Damage" : packet.carStatusData.__getitem__(carindex).frontRightWingDamage,219 "Rear_Wing_Damage" : packet.carStatusData.__getitem__(carindex).rearWingDamage,220 "Engine_Damage" : packet.carStatusData.__getitem__(carindex).engineDamage,221 "Gearbox_Damage" : packet.carStatusData.__getitem__(carindex).gearBoxDamage,222 "Vehicle_FIA_Flags_ID" : packet.carStatusData.__getitem__(carindex).vehicleFiaFlags,223 "Vehicle_FIA_Flags" : {-1:"Invalid", 0:"None", 1:"Green", 2:"Blue", 3:"Yellow", 4:"Red"}[packet.carStatusData.__getitem__(carindex).vehicleFiaFlags],224 "ERS_Store_Energy" : packet.carStatusData.__getitem__(carindex).ersStoreEnergy,225 "ERS_Deploy_Mode_ID" : packet.carStatusData.__getitem__(carindex).ersDeployMode,226 "ERS_Deploy_Mode" : ["None", "Low", "Medium", "High", "Overtake", "Hotlap"][packet.carStatusData.__getitem__(carindex).ersDeployMode],227 "ERS_Harvested_This_Lap_MGUK" : packet.carStatusData.__getitem__(carindex).ersHarvestedThisLapMGUK,228 "ERS_Harvested_This_Lap_MGUH" : packet.carStatusData.__getitem__(carindex).ersHarvestedThisLapMGUH,229 "ERS_Deployed_This_Lap" : packet.carStatusData.__getitem__(carindex).ersDeployedThisLap,230 })231232 for x in range(4):233 telemetry.update({234 "Tyre_{}_Wear".format(tyres[x]) : packet.carStatusData.__getitem__(carindex).tyresWear[x],235 "Tyre_{}_Damage".format(tyres[x]) : packet.carStatusData.__getitem__(carindex).tyresDamage[x],236 })237238239 240 if keyboard.is_pressed("esc"):241 print("_________________DRAWING GRAPH_______________")242 Graph.Graph(data)243244245 if lap != telemetry.get("Current_Lap_Num"):246247 data.append([lap, telemetry.get("Last_Lap_Time"), time, speed])248 249 time = [] ...

Full Screen

Full Screen

telemetry - backup.py

Source:telemetry - backup.py Github

copy

Full Screen

...56 "Spectator_Car_Index" : packet.spectatorCarIndex,57 "Sli_Pro_Native_Support" : packet.sliProNativeSupport,58 "Num_Marshal_Zones" : packet.numMarshalZones,59 "Marshal_Zones" : packet.marshalZones,60 "Marshal_Zone_Start" : packet.marshalZones.__getitem__(carindex).zoneStart,61 "Marshal_Zone_Flag" : packet.marshalZones.__getitem__(carindex).zoneFlag,62 "Safety_Car_Status_ID" : packet.safetyCarStatus,63 "Safety_Car_Status" : ["No safety car", "full safety car", "virtual safety car"][packet.safetyCarStatus],64 "Network_Game" : packet.networkGame,65 })666768 if isinstance(packet, PacketLapData_V1): 69 telemetry.update({70 "Last_Lap_Time" : packet.lapData.__getitem__(carindex).lastLapTime,71 "Current_Lap_Time": packet.lapData.__getitem__(carindex).currentLapTime,72 "Best_Lap_Time" : packet.lapData.__getitem__(carindex).bestLapTime,73 "Sector_1_Time" : packet.lapData.__getitem__(carindex).sector1Time,74 "Sector_2_Time" : packet.lapData.__getitem__(carindex).sector2Time,75 "Lap_Distance" : packet.lapData.__getitem__(carindex).lapDistance,76 "Total_Distance" : packet.lapData.__getitem__(carindex).totalDistance,77 "Safety_Car_Delta" : packet.lapData.__getitem__(carindex).safetyCarDelta,78 "Car_Position" : packet.lapData.__getitem__(carindex).carPosition,79 "Current_Lap_Num" : packet.lapData.__getitem__(carindex).currentLapNum,80 "Pit_Status_ID" : packet.lapData.__getitem__(carindex).pitStatus,81 "Pit_Status" : ["None", "Pitting", "In Pit Area"][packet.lapData.__getitem__(carindex).pitStatus],82 "Sector_ID" : packet.lapData.__getitem__(carindex).sector,83 "Sector" : ["Sector1", "Sector2", "Sector3"][packet.lapData.__getitem__(carindex).sector],84 "Current_Lap_Invalid" : packet.lapData.__getitem__(carindex).currentLapInvalid,85 "Penalties" : packet.lapData.__getitem__(carindex).penalties,86 "Grid_Position" : packet.lapData.__getitem__(carindex).gridPosition,87 "Driver_Status_ID" : packet.lapData.__getitem__(carindex).driverStatus,88 "Driver_Status" : ["In Garage", "Flying Lap", "In Lap", "Out Lap", "On Track"][packet.lapData.__getitem__(carindex).driverStatus],89 "Result_Status_ID" : packet.lapData.__getitem__(carindex).resultStatus,90 "Result_Status" : ["Invalid", "Inactive", "Active", "Finished", "Disqualified", "Not Classified", "Retired"][packet.lapData.__getitem__(carindex).resultStatus],91 })92 9394 if isinstance(packet, PacketParticipantsData_V1):95 telemetry.update({96 "Num_Active_Cars" : packet.numActiveCars,97 "AI_Controlled" : packet.participants.__getitem__(carindex).aiControlled,98 "Driver_ID" : packet.participants.__getitem__(carindex).driverId,99 "Team_ID" : packet.participants.__getitem__(carindex).teamId, 100 })101102 try:103 telemetry.update({"Driver" : DriverIDs[packet.participants.__getitem__(carindex).driverId]})104 except:105 telemetry.update({"Driver" : "Player"})106107 try:108 telemetry.update({"Team" : TeamIDs[packet.participants.__getitem__(carindex).teamId]})109 except:110 telemetry.update({"Team" : "Not in a team"})111112 telemetry.update({113 "Race_Number" : packet.participants.__getitem__(carindex).raceNumber,114 "Nationality_ID" : packet.participants.__getitem__(carindex).nationality,115 })116117 try:118 telemetry.update({"Nationality" : NationalityIDs[packet.participants.__getitem__(carindex).nationality]})119 except:120 telemetry.update({"Nationality" : "No Nationality"})121122 telemetry.update({123 "Name" : packet.participants.__getitem__(carindex).name,124 "Your_Telemetry_ID" : packet.participants.__getitem__(carindex).yourTelemetry,125 "Your_Telemetry" : ["Restricted", "Public"][packet.participants.__getitem__(carindex).yourTelemetry], 126 })127128129 if isinstance(packet, PacketCarSetupData_V1):130 telemetry.update({131 "Front_Wing" : packet.carSetups.__getitem__(carindex).frontWing,132 "Rear_Wing" : packet.carSetups.__getitem__(carindex).rearWing,133 "On_Throttle" : packet.carSetups.__getitem__(carindex).onThrottle,134 "Off_Throttle" : packet.carSetups.__getitem__(carindex).offThrottle,135 "Front_Camber" : packet.carSetups.__getitem__(carindex).frontCamber,136 "Rear_Camber" : packet.carSetups.__getitem__(carindex).rearCamber,137 "Front_Toe" : packet.carSetups.__getitem__(carindex).frontToe,138 "Rear_Toe" : packet.carSetups.__getitem__(carindex).rearToe,139 "Front_Suspension" : packet.carSetups.__getitem__(carindex).frontSuspension,140 "Rear_Suspension" : packet.carSetups.__getitem__(carindex).rearSuspension,141 "Front_Anti_Roll_Bar" : packet.carSetups.__getitem__(carindex).frontAntiRollBar,142 "Rear_Anti_Roll_Bar" : packet.carSetups.__getitem__(carindex).rearAntiRollBar,143 "Front_Suspension_Height" : packet.carSetups.__getitem__(carindex).frontSuspensionHeight,144 "Rear_Suspension_Height" : packet.carSetups.__getitem__(carindex).rearSuspensionHeight,145 "Brake_Pressure" : packet.carSetups.__getitem__(carindex).brakePressure,146 "Brake_Bias" : packet.carSetups.__getitem__(carindex).brakeBias,147 "Front_Tyre_Pressure" : packet.carSetups.__getitem__(carindex).frontTyrePressure,148 "Rear_Tyre_Pressure" : packet.carSetups.__getitem__(carindex).rearTyrePressure,149 "Ballast" : packet.carSetups.__getitem__(carindex).ballast,150 "Fuel_Load" : packet.carSetups.__getitem__(carindex).fuelLoad,151 })152153154 if isinstance(packet, PacketCarTelemetryData_V1):155 telemetry.update({156 "Speed" : packet.carTelemetryData.__getitem__(carindex).speed,157 "Throttle" : packet.carTelemetryData.__getitem__(carindex).throttle,158 "Steer" : packet.carTelemetryData.__getitem__(carindex).steer,159 "Brake" : packet.carTelemetryData.__getitem__(carindex).brake,160 "Clutch" : packet.carTelemetryData.__getitem__(carindex).clutch,161 "Gear" : packet.carTelemetryData.__getitem__(carindex).gear,162 "Engine_RPM" : packet.carTelemetryData.__getitem__(carindex).engineRPM,163 "DRS" : packet.carTelemetryData.__getitem__(carindex).drs,164 "Rev_Lights_Percent" : packet.carTelemetryData.__getitem__(carindex).revLightsPercent,165 "Brakes_Temperature" : packet.carTelemetryData.__getitem__(carindex).brakesTemperature,166 "Tyres_Surface_Temperature" : packet.carTelemetryData.__getitem__(carindex).tyresSurfaceTemperature,167 "Tyres_Inner_Temperature" : packet.carTelemetryData.__getitem__(carindex).tyresInnerTemperature,168 "Engine_Temperature" : packet.carTelemetryData.__getitem__(carindex).engineTemperature,169 "Tyres_Pressure" : packet.carTelemetryData.__getitem__(carindex).tyresPressure,170 "Surface_Type_ID" : packet.carTelemetryData.__getitem__(carindex).surfaceType,171 })172 173 for x in range(4):174 telemetry.update({175 "Tyre_{}_Surface_Temperature".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).tyresSurfaceTemperature[x],176 "Tyre_{}_Inner_Temperature".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).tyresInnerTemperature[x],177 "Tyre_{}_Brakes_Temperature".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).brakesTemperature[x],178 "Tyre_{}_Pressure".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).tyresPressure[x],179 "Tyre_{}_Surface_Type_ID".format(tyres[x]) : packet.carTelemetryData.__getitem__(carindex).surfaceType[x],180 "Tyre_{}_Surface_Type".format(tyres[x]) : SurfaceTypes[packet.carTelemetryData.__getitem__(carindex).surfaceType[x]],181 })182183184 if isinstance(packet, PacketCarStatusData_V1):185 telemetry.update({186 "Traction_Control" : packet.carStatusData.__getitem__(carindex).tractionControl,187 "Anti_Lock_Brakes" : packet.carStatusData.__getitem__(carindex).antiLockBrakes,188 "Fuel_Mix_ID" : packet.carStatusData.__getitem__(carindex).fuelMix,189 "Fuel_Mix" : ["Lean", "Standart", "Rich", "Max"][packet.carStatusData.__getitem__(carindex).fuelMix],190 "Front_Brake_Bias" : packet.carStatusData.__getitem__(carindex).frontBrakeBias,191 "Pit_Limiter_Status" : packet.carStatusData.__getitem__(carindex).pitLimiterStatus,192 "Fuel_In_Tank" : packet.carStatusData.__getitem__(carindex).fuelInTank,193 "Fuel_Capacity" : packet.carStatusData.__getitem__(carindex).fuelCapacity,194 "Fuel_Remaining_Laps" : packet.carStatusData.__getitem__(carindex).fuelRemainingLaps,195 "Max_RPM" : packet.carStatusData.__getitem__(carindex).maxRPM,196 "Idle_RPM" : packet.carStatusData.__getitem__(carindex).idleRPM,197 "Max_Gears" : packet.carStatusData.__getitem__(carindex).maxGears,198 "DRS_Allowed" : packet.carStatusData.__getitem__(carindex).drsAllowed,199 "Tyres_Wear" : packet.carStatusData.__getitem__(carindex).tyresWear,200 "Actual_Tyre_Compound_ID" : packet.carStatusData.__getitem__(carindex).actualTyreCompound,201 "Actual_Tyre_Compound" : {16:"F1 Modern C5", 17:"F1 Modern C4", 18:"F1 Modern C3", 19:"F1 Modern C2", 20:"F1 Modern C1", 7:"F1 Modern Intermidiate", 8:"F1 Modern Wet", 9:"F1 Classic Dry",10:"F1 Classic Wet", 11: "F2 Super Soft", 12 : "F2 Soft", 14 : "F2 Medium", 15: "F2 Wet"}[packet.carStatusData.__getitem__(carindex).actualTyreCompound],202 "Tyre_Visual_Compound_ID" : packet.carStatusData.__getitem__(carindex).tyreVisualCompound,203 "Tyre_Visual_Compound" : {16:"F1 Modern Soft", 17:"F1 Modern Medium", 18:"F1 Modern Hard", 7:"F1 Modern Intermidiate", 8:"F1 Modern Wet", 9:"F1 Classic Dry",10:"F1 Classic Wet", 11: "F2 Super Soft", 12 : "F2 Soft", 14 : "F2 Medium", 15: "F2 Wet"}[packet.carStatusData.__getitem__(carindex).tyreVisualCompound],204 "Tyres_Damage" : packet.carStatusData.__getitem__(carindex).tyresDamage,205 "Front_Left_Wing_Damage" : packet.carStatusData.__getitem__(carindex).frontLeftWingDamage,206 "Front_Right_Wing_Damage" : packet.carStatusData.__getitem__(carindex).frontRightWingDamage,207 "Rear_Wing_Damage" : packet.carStatusData.__getitem__(carindex).rearWingDamage,208 "Engine_Damage" : packet.carStatusData.__getitem__(carindex).engineDamage,209 "Gearbox_Damage" : packet.carStatusData.__getitem__(carindex).gearBoxDamage,210 "Vehicle_FIA_Flags_ID" : packet.carStatusData.__getitem__(carindex).vehicleFiaFlags,211 "Vehicle_FIA_Flags" : {-1:"Invalid", 0:"None", 1:"Green", 2:"Blue", 3:"Yellow", 4:"Red"}[packet.carStatusData.__getitem__(carindex).vehicleFiaFlags],212 "ERS_Store_Energy" : packet.carStatusData.__getitem__(carindex).ersStoreEnergy,213 "ERS_Deploy_Mode_ID" : packet.carStatusData.__getitem__(carindex).ersDeployMode,214 "ERS_Deploy_Mode" : ["None", "Low", "Medium", "High", "Overtake", "Hotlap"][packet.carStatusData.__getitem__(carindex).ersDeployMode],215 "ERS_Harvested_This_Lap_MGUK" : packet.carStatusData.__getitem__(carindex).ersHarvestedThisLapMGUK,216 "ERS_Harvested_This_Lap_MGUH" : packet.carStatusData.__getitem__(carindex).ersHarvestedThisLapMGUH,217 "ERS_Deployed_This_Lap" : packet.carStatusData.__getitem__(carindex).ersDeployedThisLap,218 })219220 for x in range(4):221 telemetry.update({222 "Tyre_{}_Wear".format(tyres[x]) : packet.carStatusData.__getitem__(carindex).tyresWear[x],223 "Tyre_{}_Damage".format(tyres[x]) : packet.carStatusData.__getitem__(carindex).tyresDamage[x],224 })225226 for item in telemetry.items():227 print("{} : {}".format(item[0], item[1]))228 print()229 if keyboard.is_pressed("esc"): ...

Full Screen

Full Screen

seq_tests.py

Source:seq_tests.py Github

copy

Full Screen

...12class Sequence:13 'Sequence using __getitem__'14 def __init__(self, seqn):15 self.seqn = seqn16 def __getitem__(self, i):17 return self.seqn[i]18class IterFunc:19 'Sequence using iterator protocol'20 def __init__(self, seqn):21 self.seqn = seqn22 self.i = 023 def __iter__(self):24 return self25 def next(self):26 if self.i >= len(self.seqn): raise StopIteration27 v = self.seqn[self.i]28 self.i += 129 return v30class IterGen:31 'Sequence using iterator protocol defined with a generator'32 def __init__(self, seqn):33 self.seqn = seqn34 self.i = 035 def __iter__(self):36 for val in self.seqn:37 yield val38class IterNextOnly:39 'Missing __getitem__ and __iter__'40 def __init__(self, seqn):41 self.seqn = seqn42 self.i = 043 def next(self):44 if self.i >= len(self.seqn): raise StopIteration45 v = self.seqn[self.i]46 self.i += 147 return v48class IterNoNext:49 'Iterator missing next()'50 def __init__(self, seqn):51 self.seqn = seqn52 self.i = 053 def __iter__(self):54 return self55class IterGenExc:56 'Test propagation of exceptions'57 def __init__(self, seqn):58 self.seqn = seqn59 self.i = 060 def __iter__(self):61 return self62 def next(self):63 3 // 064class IterFuncStop:65 'Test immediate stop'66 def __init__(self, seqn):67 pass68 def __iter__(self):69 return self70 def next(self):71 raise StopIteration72from itertools import chain, imap73def itermulti(seqn):74 'Test multiple tiers of iterators'75 return chain(imap(lambda x:x, iterfunc(IterGen(Sequence(seqn)))))76class CommonTest(unittest.TestCase):77 # The type to be tested78 type2test = None79 def test_constructors(self):80 l0 = []81 l1 = [0]82 l2 = [0, 1]83 u = self.type2test()84 u0 = self.type2test(l0)85 u1 = self.type2test(l1)86 u2 = self.type2test(l2)87 uu = self.type2test(u)88 uu0 = self.type2test(u0)89 uu1 = self.type2test(u1)90 uu2 = self.type2test(u2)91 v = self.type2test(tuple(u))92 class OtherSeq:93 def __init__(self, initseq):94 self.__data = initseq95 def __len__(self):96 return len(self.__data)97 def __getitem__(self, i):98 return self.__data[i]99 s = OtherSeq(u0)100 v0 = self.type2test(s)101 self.assertEqual(len(v0), len(s))102 s = "this is also a sequence"103 vv = self.type2test(s)104 self.assertEqual(len(vv), len(s))105 # Create from various iteratables106 for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)):107 for g in (Sequence, IterFunc, IterGen,108 itermulti, iterfunc):109 self.assertEqual(self.type2test(g(s)), self.type2test(s))110 self.assertEqual(self.type2test(IterFuncStop(s)), self.type2test())111 self.assertEqual(self.type2test(c for c in "123"), self.type2test("123"))112 self.assertRaises(TypeError, self.type2test, IterNextOnly(s))113 self.assertRaises(TypeError, self.type2test, IterNoNext(s))114 self.assertRaises(ZeroDivisionError, self.type2test, IterGenExc(s))115 def test_truth(self):116 self.assert_(not self.type2test())117 self.assert_(self.type2test([42]))118 def test_getitem(self):119 u = self.type2test([0, 1, 2, 3, 4])120 for i in xrange(len(u)):121 self.assertEqual(u[i], i)122 self.assertEqual(u[long(i)], i)123 for i in xrange(-len(u), -1):124 self.assertEqual(u[i], len(u)+i)125 self.assertEqual(u[long(i)], len(u)+i)126 self.assertRaises(IndexError, u.__getitem__, -len(u)-1)127 self.assertRaises(IndexError, u.__getitem__, len(u))128 self.assertRaises(ValueError, u.__getitem__, slice(0,10,0))129 u = self.type2test()130 self.assertRaises(IndexError, u.__getitem__, 0)131 self.assertRaises(IndexError, u.__getitem__, -1)132 self.assertRaises(TypeError, u.__getitem__)133 a = self.type2test([10, 11])134 self.assertEqual(a[0], 10)135 self.assertEqual(a[1], 11)136 self.assertEqual(a[-2], 10)137 self.assertEqual(a[-1], 11)138 self.assertRaises(IndexError, a.__getitem__, -3)139 self.assertRaises(IndexError, a.__getitem__, 3)140 def test_getslice(self):141 l = [0, 1, 2, 3, 4]142 u = self.type2test(l)143 self.assertEqual(u[0:0], self.type2test())144 self.assertEqual(u[1:2], self.type2test([1]))145 self.assertEqual(u[-2:-1], self.type2test([3]))146 self.assertEqual(u[-1000:1000], u)147 self.assertEqual(u[1000:-1000], self.type2test([]))148 self.assertEqual(u[:], u)149 self.assertEqual(u[1:None], self.type2test([1, 2, 3, 4]))150 self.assertEqual(u[None:3], self.type2test([0, 1, 2]))151 # Extended slices152 self.assertEqual(u[::], u)153 self.assertEqual(u[::2], self.type2test([0, 2, 4]))154 self.assertEqual(u[1::2], self.type2test([1, 3]))155 self.assertEqual(u[::-1], self.type2test([4, 3, 2, 1, 0]))156 self.assertEqual(u[::-2], self.type2test([4, 2, 0]))157 self.assertEqual(u[3::-2], self.type2test([3, 1]))158 self.assertEqual(u[3:3:-2], self.type2test([]))159 self.assertEqual(u[3:2:-2], self.type2test([3]))160 self.assertEqual(u[3:1:-2], self.type2test([3]))161 self.assertEqual(u[3:0:-2], self.type2test([3, 1]))162 self.assertEqual(u[::-100], self.type2test([4]))163 self.assertEqual(u[100:-100:], self.type2test([]))164 self.assertEqual(u[-100:100:], u)165 self.assertEqual(u[100:-100:-1], u[::-1])166 self.assertEqual(u[-100:100:-1], self.type2test([]))167 self.assertEqual(u[-100L:100L:2L], self.type2test([0, 2, 4]))168 # Test extreme cases with long ints169 a = self.type2test([0,1,2,3,4])170 self.assertEqual(a[ -pow(2,128L): 3 ], self.type2test([0,1,2]))171 self.assertEqual(a[ 3: pow(2,145L) ], self.type2test([3,4]))172 self.assertRaises(TypeError, u.__getslice__)173 def test_contains(self):174 u = self.type2test([0, 1, 2])175 for i in u:176 self.assert_(i in u)177 for i in min(u)-1, max(u)+1:178 self.assert_(i not in u)179 self.assertRaises(TypeError, u.__contains__)180 def test_contains_fake(self):181 class AllEq:182 # Sequences must use rich comparison against each item183 # (unless "is" is true, or an earlier item answered)184 # So instances of AllEq must be found in all non-empty sequences.185 def __eq__(self, other):186 return True187 __hash__ = None # Can't meet hash invariant requirements188 self.assert_(AllEq() not in self.type2test([]))189 self.assert_(AllEq() in self.type2test([1]))190 def test_contains_order(self):191 # Sequences must test in-order. If a rich comparison has side192 # effects, these will be visible to tests against later members.193 # In this test, the "side effect" is a short-circuiting raise.194 class DoNotTestEq(Exception):195 pass196 class StopCompares:197 def __eq__(self, other):198 raise DoNotTestEq199 checkfirst = self.type2test([1, StopCompares()])200 self.assert_(1 in checkfirst)201 checklast = self.type2test([StopCompares(), 1])202 self.assertRaises(DoNotTestEq, checklast.__contains__, 1)203 def test_len(self):204 self.assertEqual(len(self.type2test()), 0)205 self.assertEqual(len(self.type2test([])), 0)206 self.assertEqual(len(self.type2test([0])), 1)207 self.assertEqual(len(self.type2test([0, 1, 2])), 3)208 def test_minmax(self):209 u = self.type2test([0, 1, 2])210 self.assertEqual(min(u), 0)211 self.assertEqual(max(u), 2)212 def test_addmul(self):213 u1 = self.type2test([0])214 u2 = self.type2test([0, 1])215 self.assertEqual(u1, u1 + self.type2test())216 self.assertEqual(u1, self.type2test() + u1)217 self.assertEqual(u1 + self.type2test([1]), u2)218 self.assertEqual(self.type2test([-1]) + u1, self.type2test([-1, 0]))219 self.assertEqual(self.type2test(), u2*0)220 self.assertEqual(self.type2test(), 0*u2)221 self.assertEqual(self.type2test(), u2*0L)222 self.assertEqual(self.type2test(), 0L*u2)223 self.assertEqual(u2, u2*1)224 self.assertEqual(u2, 1*u2)225 self.assertEqual(u2, u2*1L)226 self.assertEqual(u2, 1L*u2)227 self.assertEqual(u2+u2, u2*2)228 self.assertEqual(u2+u2, 2*u2)229 self.assertEqual(u2+u2, u2*2L)230 self.assertEqual(u2+u2, 2L*u2)231 self.assertEqual(u2+u2+u2, u2*3)232 self.assertEqual(u2+u2+u2, 3*u2)233 class subclass(self.type2test):234 pass235 u3 = subclass([0, 1])236 self.assertEqual(u3, u3*1)237 self.assert_(u3 is not u3*1)238 def test_iadd(self):239 u = self.type2test([0, 1])240 u += self.type2test()241 self.assertEqual(u, self.type2test([0, 1]))242 u += self.type2test([2, 3])243 self.assertEqual(u, self.type2test([0, 1, 2, 3]))244 u += self.type2test([4, 5])245 self.assertEqual(u, self.type2test([0, 1, 2, 3, 4, 5]))246 u = self.type2test("spam")247 u += self.type2test("eggs")248 self.assertEqual(u, self.type2test("spameggs"))249 def test_imul(self):250 u = self.type2test([0, 1])251 u *= 3252 self.assertEqual(u, self.type2test([0, 1, 0, 1, 0, 1]))253 def test_getitemoverwriteiter(self):254 # Verify that __getitem__ overrides are not recognized by __iter__255 class T(self.type2test):256 def __getitem__(self, key):257 return str(key) + '!!!'258 self.assertEqual(iter(T((1,2))).next(), 1)259 def test_repeat(self):260 for m in xrange(4):261 s = tuple(range(m))262 for n in xrange(-3, 5):263 self.assertEqual(self.type2test(s*n), self.type2test(s)*n)264 self.assertEqual(self.type2test(s)*(-4), self.type2test([]))265 self.assertEqual(id(s), id(s*1))266 def test_bigrepeat(self):267 import sys268 if sys.maxint <= 2147483647:269 x = self.type2test([0])270 x *= 2**16271 self.assertRaises(MemoryError, x.__mul__, 2**16)272 if hasattr(x, '__imul__'):273 self.assertRaises(MemoryError, x.__imul__, 2**16)274 def test_subscript(self):275 a = self.type2test([10, 11])276 self.assertEqual(a.__getitem__(0L), 10)277 self.assertEqual(a.__getitem__(1L), 11)278 self.assertEqual(a.__getitem__(-2L), 10)279 self.assertEqual(a.__getitem__(-1L), 11)280 self.assertRaises(IndexError, a.__getitem__, -3)281 self.assertRaises(IndexError, a.__getitem__, 3)282 self.assertEqual(a.__getitem__(slice(0,1)), self.type2test([10]))283 self.assertEqual(a.__getitem__(slice(1,2)), self.type2test([11]))284 self.assertEqual(a.__getitem__(slice(0,2)), self.type2test([10, 11]))285 self.assertEqual(a.__getitem__(slice(0,3)), self.type2test([10, 11]))286 self.assertEqual(a.__getitem__(slice(3,5)), self.type2test([]))287 self.assertRaises(ValueError, a.__getitem__, slice(0, 10, 0))288 self.assertRaises(TypeError, a.__getitem__, 'x')289 def test_count(self):290 a = self.type2test([0, 1, 2])*3291 self.assertEqual(a.count(0), 3)292 self.assertEqual(a.count(1), 3)293 self.assertEqual(a.count(3), 0)294 self.assertRaises(TypeError, a.count)295 class BadExc(Exception):296 pass297 class BadCmp:298 def __eq__(self, other):299 if other == 2:300 raise BadExc()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful