Best Python code snippet using tempest_python
client.py
Source:client.py
...7from utils import MUSIC_SERVER, UI_SERVER8from tracks import TrackList, TrackState9from json import dumps, loads10from dataclasses import asdict11async def create_websocket(server):12 uri = f"ws://{server}"13 return await websockets.connect(uri, ping_interval=None)14def log(string):15 print(string, flush=True)16# First ever beat17"""18track_names = [19 ":drum_cymbal_closed",20 ":drum_bass_soft",21 ":drum_snare_soft",22]23tracks = [24 [5,0,5,0,5,0,5,0,5,0,5,0,5,0,5,0],25 [5,0,0,5,5,5,0,0,5,5,5,5,0,0,0,0],26 [0,5,5,0,5,0,5,0,5,5,5,0,0,0,0,5],27]28"""29priviledge_commands = ["!reset"]30privildeged_users = ["theprimeagen"]31def is_priviledge_command(user: str, msg: str) -> bool:32 print("is_priviledge_command", msg, priviledge_commands, flush=True)33 return msg in priviledge_commands and user in privildeged_users34def run_priviledge_command(user: str, msg: str, track_list: TrackList) -> None:35 print("run_priviledge_command", user, msg, flush=True)36 if msg == "!reset":37 print("run_priviledge_command#reset", flush=True)38 track_list.reset()39def string_state(state: TrackState) -> str: 40 return dumps(asdict(state))41async def run_bot(twitch):42 music_server = await create_websocket(MUSIC_SERVER)43 ui_server = await create_websocket(UI_SERVER)44 track_list = TrackList()45 # clear previous state46 await music_server.send(track_list.get_music())47 await ui_server.send(string_state(track_list.get_state()))48 while True:49 # TODO: Make this async generator...50 user, msg = next(twitch)51 if user is not None and is_command_msg(msg):52 print("Got twitch message", msg, "from", user, flush=True)53 print("is_priv", user, msg, flush=True)54 if is_priviledge_command(user, msg):55 run_priviledge_command(user, msg, track_list)56 # assume a required state update57 await music_server.send(track_list.get_music())...
websocket_connection.py
Source:websocket_connection.py
1# Copyright 2019 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import os5import sys6import json7from command_executor import CommandExecutor8_THIS_DIR = os.path.abspath(os.path.dirname(__file__))9_PARENT_DIR = os.path.join(_THIS_DIR, os.pardir)10sys.path.insert(1, _PARENT_DIR)11import chrome_paths12sys.path.remove(_PARENT_DIR)13sys.path.insert(0,os.path.join(chrome_paths.GetSrc(), 'third_party',14 'catapult', 'telemetry', 'third_party',15 'websocket-client'))16import websocket17class WebSocketCommands:18 CREATE_WEBSOCKET = \19 '/session/:sessionId/chromium/create_websocket'20 SEND_OVER_WEBSOCKET = \21 '/session/:sessionId/chromium/send_command_from_websocket'22class WebSocketConnection(object):23 def __init__(self, server_url, session_id):24 self._server_url = server_url.replace('http', 'ws')25 self._session_id = session_id26 self._command_id = -127 cmd_params = {'sessionId': session_id}28 path = CommandExecutor.CreatePath(29 WebSocketCommands.CREATE_WEBSOCKET, cmd_params)30 self._websocket = websocket.create_connection(self._server_url + path)31 def SendCommand(self, cmd_params):32 cmd_params['id'] = self._command_id33 self._command_id -= 1...
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!!