How to use connect_to_server method in Slash

Best Python code snippet using slash

financial_test.py

Source:financial_test.py Github

copy

Full Screen

...9 raise ValueError("No input")10 ar1 = sys.argv[1].lower()11 ar2 = sys.argv[2]12 return ar1, ar213def connect_to_server(ar1):14 url = f'https://finance.yahoo.com/quote/{ar1}/financials?p={ar1}'15 page = requests.get(url, headers={'User-Agent': 'Custom'})16 if page.status_code != 200:17 raise ValueError("URL doesn't exist")18 return page19def test_connect_to_server_0():20 with pytest.raises(ValueError, match="URL doesn't exist"):21 connect_to_server('лол')22def test_connect_to_server_1():23 connect_to_server('lol') == requests.get('https://finance.yahoo.com/quote/lol/financials?p=lol', headers={'User-Agent': 'Custom'})24def page_parser(page, ar1, ar2):25 soup = BeautifulSoup(page.text, "html.parser")26 value = soup.find_all('div', class_ = 'D(tbr) fi-row Bgc($hoverBgColor):h')27 res = []28 for val in value:29 if (val.span.text == ar2):30 res.append(val.span.text)31 nums1 = val.find_all('div', class_ = 'Ta(c) Py(6px) Bxz(bb) BdB Bdc($seperatorColor) Miw(120px) Miw(100px)--pnclg Bgc($lv1BgColor) fi-row:h_Bgc($hoverBgColor) D(tbc)')32 nums2 = val.find_all('div', class_ = 'Ta(c) Py(6px) Bxz(bb) BdB Bdc($seperatorColor) Miw(120px) Miw(100px)--pnclg D(tbc)')33 for num in nums1 + nums2:34 res.append(num.span.text)35 if not res:36 raise ValueError(f"Field {ar2} in {ar1} doesn't exist")37 return tuple(res)38def test_page_parser_0():39 assert page_parser(connect_to_server('MSFT'), 'MSFT', 'Total Revenue') == ('Total Revenue', '184,903,000', '143,015,000', '110,360,000', '168,088,000', '125,843,000')40def test_page_parser_1():41 assert page_parser(connect_to_server('aapl'), 'aapl', 'Total Revenue') == ('Total Revenue', '378,323,000', '274,515,000', '265,595,000', '365,817,000', '260,174,000')42def test_page_parser_2():43 with pytest.raises(ValueError):44 page_parser(connect_to_server('nokk'), 'nokk', 'Total Revenue')45def test_page_parser_tuple():46 assert type(page_parser(connect_to_server('MSFT'), 'MSFT', 'Total Revenue')) == type(tuple('5'))47def result():48 try:49 ar1, ar2 = check_args()50 page = connect_to_server(ar1)51 result = page_parser(page, ar1, ar2)52 print(result)53 except ValueError as exp:54 print('\033[91mException!', exp)55if __name__ == '__main__':56 result()...

Full Screen

Full Screen

client.py

Source:client.py Github

copy

Full Screen

2import sys3SIZE = 10244PORT = 123455my_socket = socket.socket()6def connect_to_server():7 commend = input("[+] to connect press 'connect' and the IP address\n>>> ")8 if len(commend.split(' ')) > 1 and commend.split(' ')[0] == 'connect':9 connect = commend.split(' ')[0]10 server_ip = commend.split(' ')[1]11 12 try:13 my_socket.connect((server_ip, PORT))14 print("[+] connection successful")15 return 116 17 except:18 print("[!] connection unsuccessful")19 sys.exit()20 21 else:22 print("[!] Try again")23 connect_to_server()24def cli():25 commend = input("\n[+] to upload press 'upload' and the file path\n"26 "[+] to download press 'download' and the file name \n"27 "[+] to list all files press 'list'\n"28 ">>> ")29 30 if len(commend.split(' ')) == 1 and commend == 'list':31 list_files()32 elif len(commend.split(' ')) > 1:33 comm = commend.split(' ')[0] 34 file_path = commend.split(' ')[1]35 36 if comm == 'upload':37 upload(file_path)38 elif comm == 'download':39 download(file_path)40 elif comm == 'list':41 list_files()42 else:43 print("[!] Unknown command")44 cli()45 else:46 print("[!] Unknown command")47 cli()48def upload(file_path):49 my_socket.send(b'upload')50 my_socket.send(file_path.encode())51 52 with open(file_path, 'rb') as f:53 data = f.read(SIZE)54 55 while data:56 my_socket.send(data)57 data = f.read(SIZE)58 59 my_socket.close()60 print("[!] successful\n")61 connect_to_server()62def download(file_name): 63 my_socket.send(b'download')64 my_socket.send(file_name.encode())65 with open(f'/home/david/mefathim4/socket/client/{file_name}', 'wb') as f:66 data = my_socket.recv(SIZE)67 f.write(data)68 print('[!] successful\n')69 connect_to_server()70 71def list_files():72 my_socket.send(b'list')73 74 data = my_socket.recv(SIZE).decode()75 print(f'list of the files:\n{data}\n')76 77 connect_to_server()78if __name__=="__main__":79 print("[+] Welcome to FTP Client\n")80 81 connect_to_server()...

Full Screen

Full Screen

test_websocket_rpc.py

Source:test_websocket_rpc.py Github

copy

Full Screen

...18 await self._ws.log("hello world")19 async def add(self, data):20 """Add function."""21 return data + 1.022async def test_connect_to_server(socketio_server):23 """Test connecting to the server."""24 # test workspace is an exception, so it can pass directly25 ws = await connect_to_server({"name": "my plugin", "server_url": WS_SERVER_URL})26 with pytest.raises(Exception, match=r".*Permission denied for.*"):27 ws = await connect_to_server(28 {"name": "my plugin", "workspace": "test", "server_url": WS_SERVER_URL}29 )30 ws = await connect_to_server({"name": "my plugin", "server_url": WS_SERVER_URL})31 await ws.export(ImJoyPlugin(ws))32async def test_numpy_array(socketio_server):33 """Test numpy array."""34 ws = await connect_to_server(35 {"client_id": "test-plugin", "server_url": WS_SERVER_URL}36 )37 await ws.export(ImJoyPlugin(ws))38 workspace = ws.config.workspace39 token = await ws.generate_token()40 api = await connect_to_server(41 {42 "client_id": "client",43 "workspace": workspace,44 "token": token,45 "server_url": WS_SERVER_URL,46 }47 )48 plugin = await api.get_service("test-plugin:default")49 result = await plugin.add(2.1)50 assert result == 2.1 + 1.051 large_array = np.zeros([2048, 2048, 4], dtype="float32")52 result = await plugin.add(large_array)...

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 Slash 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