Best Python code snippet using locust
press.py.svn-base
Source:press.py.svn-base
1#!/usr/bin/python2# Filename : auto_test.py designed for SSD testing automatically3# Warning : the output of auto_test.py will recovery its previous4import os5import shutil6# current directionary, work dic7cur_dir = os.getcwd()8# output dictionary path9output = cur_dir + '/output'10# logs dictionary containing all logs11logs = cur_dir + '/logs'12# test.log recording final test result13test_log = logs + '/test.log'14log_1 = logs + '/log_1.log'15log_2 = logs + '/log_2.log'16log_3 = logs + '/log_3.log'17log_4 = logs + '/log_4.log'18log_5 = logs + '/log_5.log'19log_6 = logs + '/log_6.log'20# results.log recording the output of the testing programs21res_log = logs + '/results.log'22#cases written by c23cases_cc = [];24# total cases25total_cases = 026fail_cases = 027# shell print with color28def color(s, succ=True):29 if succ:30 string = s + 'is PASS!!!'31 s = string.center(40, "*")32 return "%s[32;2m%s%s[0m" % (chr(27), s, chr(27)) #green33 else:34 string = s + 'is FAIL!!!'35 s = string.center(40, "*")36 return "%s[31;2m%s%s[0m" % (chr(27), s, chr(27)) #red37#clear log files38try: 39 shutil.rmtree(logs)40except OSError:41 print "logs dictionary does not exist" 42try:43 os.mkdir(logs)44except OSError:45 print "can not mkdir logs dictionary"46#clear the whole ssd47if os.system("./../clear_all >> res_log") == 0:48 print "open_newcard runs successfully"49else:50 print "open_newcard can not run"51for i in range(1,100):52 if os.system("./test_multi_channel_all_operation >> log_1") == 0:53 print "test_multi_channel_all_operation runs successfully"54 else:55 print "test_multi_channel_all_operation can not run" 56 57 if os.system("./../clear_all >> res_log_1") == 0:58 print "clear_all runs successfully" 59 else:60 print "clear_all can not run"61 62 if os.system("./test_multi_channel_all_operation_1 >> log_2") == 0:63 print "test_multi_channel_all_operation_1 runs successfully"64 else:65 print "test_multi_channel_all_operation_1 can not run"66 if os.system("./../clear_all >> res_log_2") == 0:67 print "clear_all runs successfully" 68 else:69 print "clear_all can not run"70 if os.system("./test_multi_channel_all_operation_2 >> log_3") == 0:71 print "test_multi_channel_all_operation_2 runs successfully"72 else:73 print "test_multi_channel_all_operation_2 can not run"74 if os.system("./../clear_all >> res_log_3") == 0:75 print "clear_all runs successfully" 76 else:77 print "clear_all can not run"78 if os.system("./test_multi_channel_all_operation_3 >> log_4") == 0:79 print "test_multi_channel_all_operation_3 runs successfully"80 else:81 print "test_multi_channel_all_operation_3 can not run"82 if os.system("./../clear_all >> res_log_4") == 0:83 print "clear_all runs successfully" 84 else:85 print "clear_all can not run"86 87 for j in range(1,10)88 if os.system("./test_multi_channel_full_channel_compare >> log_5") == 0:89 print "test_multi_channel_full_channel_compare_1 runs successfully"90 else:91 print "test_multi_channel_full_channel_compare_1 can not run"92 if os.system("./../clear_all >> res_log_5") == 0:93 print "clear_all runs successfully" 94 else:95 print "clear_all can not run"96 if os.system("./test_multi_channel_write_read_delete_norandab >> log_6") == 0:97 print "test_multi_channel_write_read_delete_norandab runs successfully"98 else:99 print "test_multi_channel_write_read_delete_norandab can not run"100 101 if os.system("./../clear_all >> res_log_6") == 0:102 print "clear_all runs successfully"103 else:104 print "clear_all can not run"105print "the test is over"106 # if os.system("./../clear_all_tmp >> res_log") == 0:107 # print "clear_all runs successfully" 108 # else:109 # print "clear_all can not run"110#try:111# test_file = file(test_log, 'a')112# print >> test_file, "caseName\tResults"113# res_file = file(res_log, 'r')114 #lines = res_file.readlines()115# for line in res_file:116# if line.find("SUCC") != -1:117# print >> test_file, "%3s\t%s" % (line.strip().split()[2], line.strip().split()[-1])118# print color(line.strip().split()[2])119# elif line.find("FAIL") != -1:120# print >> test_file, "%3s\t%s" % (line.strip().split()[2], line.strip().split()[-1])121# print color(line.strip().split()[2])122#finally:123# res_file.close()124# test_file.close()...
press.py
Source:press.py
1#!/usr/bin/python2# Filename : auto_test.py designed for SSD testing automatically3# Warning : the output of auto_test.py will recovery its previous4import os5import shutil6# current directionary, work dic7cur_dir = os.getcwd()8# output dictionary path9output = cur_dir + '/output'10# logs dictionary containing all logs11logs = cur_dir + '/logs'12# test.log recording final test result13test_log = logs + '/test.log'14log_1 = logs + '/log_1.log'15log_2 = logs + '/log_2.log'16log_3 = logs + '/log_3.log'17log_4 = logs + '/log_4.log'18log_5 = logs + '/log_5.log'19log_6 = logs + '/log_6.log'20# results.log recording the output of the testing programs21res_log = logs + '/results.log'22#cases written by c23cases_cc = [];24# total cases25total_cases = 026fail_cases = 027# shell print with color28def color(s, succ=True):29 if succ:30 string = s + 'is PASS!!!'31 s = string.center(40, "*")32 return "%s[32;2m%s%s[0m" % (chr(27), s, chr(27)) #green33 else:34 string = s + 'is FAIL!!!'35 s = string.center(40, "*")36 return "%s[31;2m%s%s[0m" % (chr(27), s, chr(27)) #red37#clear log files38try: 39 shutil.rmtree(logs)40except OSError:41 print "logs dictionary does not exist" 42try:43 os.mkdir(logs)44except OSError:45 print "can not mkdir logs dictionary"46#clear the whole ssd47if os.system("./../clear_all >> res_log") == 0:48 print "open_newcard runs successfully"49else:50 print "open_newcard can not run"51for i in range(1,100):52 if os.system("./test_multi_channel_all_operation >> log_1") == 0:53 print "test_multi_channel_all_operation runs successfully"54 else:55 print "test_multi_channel_all_operation can not run" 56 57 if os.system("./../clear_all >> res_log_1") == 0:58 print "clear_all runs successfully" 59 else:60 print "clear_all can not run"61 62 if os.system("./test_multi_channel_all_operation_1 >> log_2") == 0:63 print "test_multi_channel_all_operation_1 runs successfully"64 else:65 print "test_multi_channel_all_operation_1 can not run"66 if os.system("./../clear_all >> res_log_2") == 0:67 print "clear_all runs successfully" 68 else:69 print "clear_all can not run"70 if os.system("./test_multi_channel_all_operation_2 >> log_3") == 0:71 print "test_multi_channel_all_operation_2 runs successfully"72 else:73 print "test_multi_channel_all_operation_2 can not run"74 if os.system("./../clear_all >> res_log_3") == 0:75 print "clear_all runs successfully" 76 else:77 print "clear_all can not run"78 if os.system("./test_multi_channel_all_operation_3 >> log_4") == 0:79 print "test_multi_channel_all_operation_3 runs successfully"80 else:81 print "test_multi_channel_all_operation_3 can not run"82 if os.system("./../clear_all >> res_log_4") == 0:83 print "clear_all runs successfully" 84 else:85 print "clear_all can not run"86 87 for j in range(1,10)88 if os.system("./test_multi_channel_full_channel_compare >> log_5") == 0:89 print "test_multi_channel_full_channel_compare_1 runs successfully"90 else:91 print "test_multi_channel_full_channel_compare_1 can not run"92 if os.system("./../clear_all >> res_log_5") == 0:93 print "clear_all runs successfully" 94 else:95 print "clear_all can not run"96 if os.system("./test_multi_channel_write_read_delete_norandab >> log_6") == 0:97 print "test_multi_channel_write_read_delete_norandab runs successfully"98 else:99 print "test_multi_channel_write_read_delete_norandab can not run"100 101 if os.system("./../clear_all >> res_log_6") == 0:102 print "clear_all runs successfully"103 else:104 print "clear_all can not run"105print "the test is over"106 # if os.system("./../clear_all_tmp >> res_log") == 0:107 # print "clear_all runs successfully" 108 # else:109 # print "clear_all can not run"110#try:111# test_file = file(test_log, 'a')112# print >> test_file, "caseName\tResults"113# res_file = file(res_log, 'r')114 #lines = res_file.readlines()115# for line in res_file:116# if line.find("SUCC") != -1:117# print >> test_file, "%3s\t%s" % (line.strip().split()[2], line.strip().split()[-1])118# print color(line.strip().split()[2])119# elif line.find("FAIL") != -1:120# print >> test_file, "%3s\t%s" % (line.strip().split()[2], line.strip().split()[-1])121# print color(line.strip().split()[2])122#finally:123# res_file.close()124# test_file.close()...
clean_scala.py
Source:clean_scala.py
1# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/07_clean_scala.ipynb (unless otherwise specified).2__all__ = ['rm_execution_count', 'clean_output_data_vnd', 'colab_json', 'clean_cell_output', 'cell_metadata_keep',3 'nb_metadata_keep', 'clean_cell', 'clean_cell', 'clean_nb', 'clean_cr', 'BSLASH', 'nbdev_clean_nbs']4# Cell5import io,sys,json,glob,re6from fastcore.script import call_parse,Param7from nbdev.imports import Config8from pathlib import Path9# Cell10def rm_execution_count(o):11 "Remove execution count in `o`"12 if 'execution_count' in o: o['execution_count'] = None13# Cell14colab_json = "application/vnd.google.colaboratory.intrinsic+json"15def clean_output_data_vnd(o):16 "Remove `application/vnd.google.colaboratory.intrinsic+json` in data entries"17 if 'data' in o:18 data = o['data']19 if colab_json in data:20 new_data = {k:v for k,v in data.items() if k != colab_json}21 o['data'] = new_data22# Cell23def clean_cell_output(cell):24 "Remove execution count in `cell`"25 if 'outputs' in cell:26 for o in cell['outputs']:27 rm_execution_count(o)28 clean_output_data_vnd(o)29 o.get('metadata', o).pop('tags', None)30# Cell31cell_metadata_keep = ["hide_input"]32nb_metadata_keep = ["kernelspec", "jekyll", "jupytext", "doc"]33# Cell34def clean_cell(cell, clear_all=False):35 "Clean `cell` by removing superfluous metadata or everything except the input if `clear_all`"36 rm_execution_count(cell)37 if 'outputs' in cell:38 if clear_all: cell['outputs'] = []39 else: clean_cell_output(cell)40 if cell['source'] == ['']: cell['source'] = []41 cell['metadata'] = {} if clear_all else {k:v for k,v in cell['metadata'].items() if k in cell_metadata_keep}42# Cell43def clean_cell(cell, clear_all=False):44 "Clean `cell` by removing superfluous metadata or everything except the input if `clear_all`"45 rm_execution_count(cell)46 if 'outputs' in cell:47 if clear_all: cell['outputs'] = []48 else: clean_cell_output(cell)49 if cell['source'] == ['']: cell['source'] = []50 cell['metadata'] = {} if clear_all else {k:v for k,v in cell['metadata'].items() if k in cell_metadata_keep}51# Cell52def clean_nb(nb, clear_all=False):53 "Clean `nb` from superfluous metadata, passing `clear_all` to `clean_cell`"54 for c in nb['cells']: clean_cell(c, clear_all=clear_all)55 nb['metadata'] = {k:v for k,v in nb['metadata'].items() if k in nb_metadata_keep }56# Cell57def _print_output(nb):58 "Print `nb` in stdout for git things"59 _output_stream = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')60 x = json.dumps(nb, sort_keys=True, indent=1, ensure_ascii=False)61 _output_stream.write(x)62 _output_stream.write("\n")63 _output_stream.flush()64# Cell65BSLASH = '\x5c'66def clean_cr(s): return re.sub(fr'{BSLASH}{BSLASH}r(\\n)?', r'\\n', s)67# Cell68@call_parse69def nbdev_clean_nbs(fname:Param("A notebook name or glob to convert", str)=None,70 clear_all:Param("Clean all metadata and outputs", bool)=False,71 disp:Param("Print the cleaned outputs", bool)=False,72 read_input_stream:Param("Read input stram and not nb folder")=False):73 "Clean all notebooks in `fname` to avoid merge conflicts"74 #Git hooks will pass the notebooks in the stdin75 if read_input_stream and sys.stdin:76 input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')77 nb = json.load(input_stream)78 clean_nb(nb, clear_all=clear_all)79 _print_output(nb)80 return81 if fname is None:82 try: path = Config().path("nbs_path")83 except Exception as e: path = Path.cwd()84 files = path.glob('**/*.ipynb') if fname is None else glob.glob(fname)85 for f in files:86 if not str(f).endswith('.ipynb'): continue87 nb_s = open(f, 'r', encoding='utf-8').read()88 nb = json.loads(clean_cr(nb_s))89 clean_nb(nb, clear_all=clear_all)90 if disp: _print_output(nb)91 else:92 x = json.dumps(nb, sort_keys=True, indent=1, ensure_ascii=False)93 with io.open(f, 'w', encoding='utf-8') as f:94 f.write(x)...
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!!