Best Python code snippet using avocado_python
main.py
Source:main.py
1import random as r2from math import log2, ceil3from sys import stdout4BYTE = 2565def create_random_file(amount_bytes, filename='file.bin'):6 '''7 This function create file8 :param amount_bytes: amount of random bytes9 :param filename: file will rewrite if it already exist10 :return: nothing11 '''12 file = open(filename, 'wb')13 for i in range(amount_bytes):14 file.write(bytearray([r.randint(0, 255)]))15 file.close()16def number_into_bytes(number, size):17 output = bytearray()18 while number > 0:19 output += bytearray([number % 256])20 number //= 25621 return bytearray(size - len(output)) + output22def archive_file_by_destroy_repeating(input_filename, output_filename='output.bin', log=None):23 input_file = open(input_filename, 'rb')24 output_file = open(output_filename, 'wb')25 bytes_from_file = bytearray(input_file.read())26 index_len = ceil(log2(len(bytes_from_file)) / 8)27 indexes_of_repeatings = bytearray()28 for byte in bytes_from_file:29 pass30 #todo: make this shit31def archive_file_by_indexing(input_filename, output_filename='output.bin', log=None):32 input_file = open(input_filename, 'rb')33 output_file = open(output_filename, 'wb')34 bytes_from_file = bytearray(input_file.read())35 index_len = ceil(log2(len(bytes_from_file)) / 8)36 print('amount bytes by 1 byte:', index_len, file=log)37 for value in range(BYTE):38 print('byte:', value, 'begin', file=log)39 output_file.write(bytearray([BYTE - 1]))40 for index_of_byte in range(len(bytes_from_file)):41 if bytes_from_file[index_of_byte] == value:42 print('position:', index_of_byte, 'writed', file=log)43 output_file.write(number_into_bytes(index_of_byte, index_len))44 input_file.close()45 output_file.close()46def file_reader(filename, mode, information='npc'):47 file = open(filename, 'r' + mode)48 text = file.read()49 print('_________________________')50 if 'n' in information:51 print(filename)52 if 'p' in information:53 print(text)54 if 'c' in information:55 print(len(text))56 print('_________________________')57 file.close()58if __name__ == '__main__':59 log = open('log.txt', 'w')60 create_random_file(100000)61 archive_file_by_indexing('file.bin', log=log)62 file_reader('file.bin', 'b', 'nc')63 file_reader('output.bin', 'b', 'nc')...
sew_files.py
Source:sew_files.py
1import sys, os2from pathlib import Path3import shutil4def bytes_from_file(filename, chunksize=8192):5 with open(filename, "rb") as f:6 while True:7 b = f.read()8 if b != b"":9 yield bytes(b)10 else:11 break12main_dir = os.getcwd()13#main_dir = sys.argv[1]14tmp_dirs = []15for file in os.listdir(main_dir):16 if os.path.isdir(main_dir + "/" + file):17 if "tmp_" in file:18 tmp_dirs.append(main_dir + "/" + file)19number_of_dirs = len(tmp_dirs)20with open(main_dir + "/" + "opt.ChVec1_tmp", "wb") as bin_file_ChVec1:21 for b in bytes_from_file(main_dir + "/" + "opt.ChVec1"):22 bin_file_ChVec1.write(b)23 for i in range(1, number_of_dirs + 1):24 for b in bytes_from_file(main_dir + "/tmp_"+str(i)+"/opt.ChVec1"):25 bin_file_ChVec1.write(b)...
bin_to_c_array.py
Source:bin_to_c_array.py
12import sys34def bytes_from_file(filename, chunksize=8192):5 with open(filename, "rb") as f:6 while True:7 chunk = f.read(chunksize)8 if chunk:9 for b in chunk:10 yield b11 else:12 break1314def main():15 with open(sys.argv[2], "w") as out:16 out.write("char " + sys.argv[3] + "[] = {")17 for b in bytes_from_file(sys.argv[1]):18 out.write(f"{b},")19 out.write("};");2021if __name__ == "__main__":
...
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!!