Best Python code snippet using fMBT_python
__main__.py
Source: __main__.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3from sys import argv4from os.path import join5from json import load6from . import df7from .files import sync, peek_local, peek_remote8def status_str(file_local, file_remote, in_tranist):9 descr_str = "("10 delim = lambda x: "," if x[-1] != "(" else ""11 if file_local:12 descr_str += "L"13 if file_remote:14 descr_str += delim(descr_str) + "R"15 if in_tranist:16 descr_str += delim(descr_str) + "T"17 descr_str += ")"18 return descr_str19def run():20 if argv[1] == "verify":21 df_status = df.verify()22 print(df_status)23 if argv[1] == "ls":24 df_ls = df.list_items(argv[2])25 print(df_ls)26 if argv[1] == "lsl":27 ls_local = peek_local(argv[2])28 print("")29 print("Local FILES:")30 print("------------")31 for key, status in ls_local.items():32 if not status["collection"]:33 sstr = status_str(34 status["local"], status["remote"], status["in_transit"]35 )36 print(f"{key:<80} {sstr}")37 print("")38 print("Local FOLDERS:")39 print("------------")40 for key, status in ls_local.items():41 if status["collection"]:42 sstr = status_str(43 status["local"], status["remote"], status["in_transit"]44 )45 print(f"{key:<80} {sstr}")46 if argv[1] == "lsr":47 ls_local = peek_remote(argv[2])48 print("")49 print("Remote DATA RECORDS:")50 print("------------")51 for key, status in ls_local.items():52 if not status["collection"]:53 name = status["name"]54 metadata = status["metadata"]55 if status["in_transit"]:56 print(f"{key:<12} (T) {name:<16} {metadata}")57 else:58 print(f"{key:<16} {name:<16} {metadata}")59 print("")60 print("Remote COLLECTIONS:")61 print("------------")62 for key, status in ls_local.items():63 if status["collection"]:64 name = status["name"]65 print(f"{key:<12} {name:<16}")66 if argv[1] == "mk":67 with open(join(argv[2], "xfer.json"), "r") as f:68 xfer_descriptor = load(f)69 df_descriptor = xfer_descriptor["datafed"]70 owner = df_descriptor["owner"]71 coll = df.ensure_collection(df_descriptor["collection"], owner)72 if argv[1] == "id":73 if len(argv) > 3:74 coll_id = df.find_collection(argv[2], parent=argv[3])75 print(coll_id)76 else:77 coll_id = df.find_collection(argv[2])78 print(coll_id)79 if argv[1] == "sync":80 sync(argv[2])81if __name__ == "__main__":...
test_securesocket.py
Source: test_securesocket.py
1import asyncio2import socket3import unittest4from lightsocks.core.cipher import Cipher5from lightsocks.core.password import randomPassword6from lightsocks.core.securesocket import SecureSocket7class TestSecuresocket(unittest.TestCase):8 def setUp(self):9 self.ls_local, self.ls_server = socket.socketpair()10 password = randomPassword()11 self.loop = asyncio.new_event_loop()12 self.cipher = Cipher.NewCipher(password)13 self.securesocket = SecureSocket(loop=self.loop, cipher=self.cipher)14 self.msg = bytearray(b'hello world')15 self.encripted_msg = self.msg.copy()16 self.cipher.encode(self.encripted_msg)17 def tearDown(self):18 self.loop.close()19 self.ls_local.close()20 self.ls_server.close()21 def test_decodeRead(self):22 self.ls_local.send(self.encripted_msg)23 self.ls_server.setblocking(False)24 received_msg = self.loop.run_until_complete(25 self.securesocket.decodeRead(self.ls_server))26 self.assertEqual(received_msg, self.msg)27 def test_encodeWrite(self):28 self.ls_local.setblocking(False)29 self.loop.run_until_complete(30 self.securesocket.encodeWrite(self.ls_local, self.msg))31 received_msg = self.ls_server.recv(1024)32 self.assertEqual(bytearray(received_msg), self.encripted_msg)33 def test_decodeCopy(self):34 dstServer, ls_server_conn = socket.socketpair()35 ls_server_conn.setblocking(False)36 self.ls_server.setblocking(False)37 self.ls_local.sendall(self.encripted_msg * 10)38 self.ls_local.close()39 self.loop.run_until_complete(40 self.securesocket.decodeCopy(ls_server_conn, self.ls_server))41 received_msg = dstServer.recv(1024)42 self.assertEqual(bytearray(received_msg), self.msg * 10)43 dstServer.close()44 ls_server_conn.close()45 def test_encodeCopy(self):46 user_client, ls_local_conn = socket.socketpair()47 ls_local_conn.setblocking(False)48 self.ls_local.setblocking(False)49 user_client.sendall(self.msg * 10)50 user_client.close()51 self.loop.run_until_complete(52 self.securesocket.encodeCopy(self.ls_local, ls_local_conn))53 received_msg = self.ls_server.recv(1024)54 self.assertEqual(bytearray(received_msg), self.encripted_msg * 10)...
Check out the latest blogs from LambdaTest on this topic:
Collecting and examining data from multiple sources can be a tedious process. The digital world is constantly evolving. To stay competitive in this fast-paced environment, businesses must frequently test their products and services. While it’s easy to collect raw data from multiple sources, it’s far more complex to interpret it properly.
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
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!!