Best Python code snippet using Airtest
i3status.py
Source:i3status.py
...26import sys27import json28import re29import glob30def get_cpufreq():31 """Returns CPU clock speed (min, max)"""32 33 with open('/proc/cpuinfo') as f:34 ms = (re.match('cpu MHz\t\t: (.*)$', l) for l in f.readlines())35 return "{:.1f} GHz".format(max(float(m.groups()[0]) / 1000 for m in ms if m is not None))36def get_proc_count():37 return len(glob.glob('/proc/[0-9]*'))38def print_line(message):39 """ Non-buffered printing to stdout. """40 sys.stdout.write(message + '\n')41 sys.stdout.flush()42def read_line():43 """ Interrupted respecting reader for stdin. """44 # try reading a line, removing any extra whitespace45 try:46 line = sys.stdin.readline().strip()47 # i3status sends EOF, or an empty line48 if not line:49 sys.exit(3)50 return line51 # exit on ctrl-c52 except KeyboardInterrupt:53 sys.exit()54if __name__ == '__main__':55 # Skip the first line which contains the version header.56 print_line(read_line())57 # The second line contains the start of the infinite array.58 print_line(read_line())59 while True:60 line, prefix = read_line(), ''61 # ignore comma at start of lines62 if line.startswith(','):63 line, prefix = line[1:], ','64 # insert information into the start of the json, but could be anywhere65 j = json.loads(line)66 j.insert(0, {'full_text' : '%s' % get_cpufreq(), 'name' : 'freqs'})67 j.insert(0, {'full_text' : '%s ps' % get_proc_count(), 'name': 'proccount'})68 # and echo back new encoded json...
tasks_wrapper.py
Source:tasks_wrapper.py
1import time 2from proj.tasks import *3from proj.celery import celery4import requests5@celery.task6def requests_func():7 #for i in range(0,3):8 #str = get_data.delay()9 #str = get_cpufreq.delay()10 str = getndump_inverter_data.delay()11 while(str.ready() == False):12 time.sleep(3)13 print str.get()...
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!!