Best Python code snippet using tox_python
bench.py
Source: bench.py
1import os2import re3import subprocess4import sys5import time6# RUN = "iccma19"7RUN = "gen"8RESULTS = f"results_{RUN}"9TIMEDOUT = "TIMEDOUT"10COMPLETE = "cmp"11PREFERRED = "prf"12STABLE = "stb"13SEMANTICS = (COMPLETE, PREFERRED, STABLE)14s_to_ac = {15 COMPLETE: "cmp",16 PREFERRED: "prf",17 STABLE: "stb"18}19s_to_m = {20 COMPLETE: "EE-CO",21 PREFERRED: "EE-PR",22 STABLE: "EE-ST"23}24def bench_one(cmd, out, timeout, overwrite=False):25 if not overwrite and os.path.isfile(out):26 print(f"file {out} already exists and cannot be overwritten")27 return28 with open(out, "w+") as f:29 try:30 start = time.time_ns()31 subprocess.run(cmd, stdout=f, timeout=timeout)32 end = time.time_ns()33 except subprocess.TimeoutExpired as t:34 f.write('\n')35 f.write(TIMEDOUT)36 else:37 f.write('\n')38 f.write(str(end - start))39 f.write('\n')40def bench_aaf_cadical(path_to_aaf_cadical, filename, stub, semantic, timeout, overwrite, results):41 bench_one(cmd=(os.path.join(path_to_aaf_cadical, "bin", f"aaf-{s_to_ac[semantic]}.exe"), filename),42 out=os.path.join(path_to_aaf_cadical, results, f"{stub}.{semantic}"),43 timeout=timeout,44 overwrite=overwrite)45def bench_mutoksia(path_to_mutoksia, filename, stub, semantic, timeout, overwrite, results):46 bench_one(cmd=(os.path.join(path_to_mutoksia, "bin", "mu-toksia.exe"), "-p", s_to_m[semantic], "-f", filename, "-fo", "apx"),47 out=os.path.join(path_to_mutoksia, results, f"{stub}.{semantic}"),48 timeout=timeout,49 overwrite=overwrite)50def main():51 overwrite = (len(sys.argv) == 2 and sys.argv[1] == "-o")52 # path_to_aaf_cadical = sys.argv[1]53 # path_to_mutoksia = sys.argv[2]54 # path_to_generated = sys.argv[3]55 # timeout = sys.argv[4]56 path_to_aaf_cadical = r"C:\Users\asib1\Documents\Asib\uni\ba_baumann\benching\aaf-cadical"57 path_to_mutoksia = r"C:\Users\asib1\Documents\Asib\uni\ba_baumann\benching\mutoksia"58 path_to_generated = r"C:\Users\asib1\Documents\Asib\uni\ba_baumann\benching\aafs"59 path_to_iccma19 = r"C:\Users\asib1\Documents\Asib\uni\ba_baumann\iccma19\instances"60 timeout = 60061 # bench(overwrite, path_to_aaf_cadical, path_to_generated, path_to_mutoksia, timeout, "results_test")62 if RUN == "gen":63 r = "results_gen"64 p = path_to_generated65 elif RUN == "iccma19":66 r = "results_iccma19"67 p = path_to_iccma1968 69 bench(overwrite, path_to_aaf_cadical, p, path_to_mutoksia, timeout, r)70def bench(overwrite, path_to_aaf_cadical, path_to_aafs, path_to_mutoksia, timeout, results):71 for file in os.listdir(os.fsencode(path_to_aafs)):72 filename = os.fsdecode(file)73 filepath = os.path.join(path_to_aafs, filename)74 match = re.search(r"(.+)\.apx", filename)75 if match and filepath.endswith(".apx"):76 stub = match[1]77 for semantic in SEMANTICS:78 bench_aaf_cadical(path_to_aaf_cadical, filepath, stub, semantic, timeout, overwrite, results)79 bench_mutoksia(path_to_mutoksia, filepath, stub, semantic, timeout, overwrite, results)80if __name__ == '__main__':...
make_plot.py
Source: make_plot.py
1import matplotlib.pyplot as plt2def parse_bitrate(source):3 with open(source) as file:4 lines = file.readlines()5 bitrates = [float(line.split()[2]) for line in lines]6 return bitrates7def parse_psnr(source):8 with open(source) as file:9 lines = file.readlines()10 psnr = [float(line.split('=')[-1]) for line in lines]11 qp = [int(line.split('=')[1].split()[0]) for line in lines]12 return psnr, qp13path_to_black = "results/black"14path_to_generated = "results/generated"15bitrate_filename = "bitrate.txt"16psnr_filename = "results.txt"17count_last = 418bitrates_black = parse_bitrate(f"{path_to_black}/{bitrate_filename}")19psnr_black, qp = parse_psnr(f"{path_to_black}/{psnr_filename}")20bitrates_black = bitrates_black[-count_last:]21psnr_black = psnr_black[-count_last:]22qp = qp[-count_last:]23print(bitrates_black, psnr_black)24bitrates = parse_bitrate(f"{path_to_generated}/{bitrate_filename}")25psnr, _ = parse_psnr(f"{path_to_generated}/{psnr_filename}")26bitrates = bitrates[-count_last:]27psnr = psnr[-count_last:]28print(bitrates, psnr)29plt.plot(bitrates_black, psnr_black, label="black")30plt.plot(bitrates, psnr, label=f"generated")31plt.scatter(bitrates_black, psnr_black)32plt.scatter(bitrates, psnr)33for i in range(len(psnr)):34 plt.text(bitrates_black[i], psnr_black[i], qp[i], fontsize=9)35 plt.text(bitrates[i], psnr[i], qp[i], fontsize=9)36# plt.title(f'Sasha')37plt.xlabel('Bitrate')38plt.ylabel('PSNR')39plt.legend()40plt.grid()...
settings.py
Source: settings.py
1import os.path2SAMPLERATE = 441003SRC_FOLDER = os.path.abspath(os.path.join("realisations", "cpp"))4PATH_TO_GENERATED = os.path.abspath("tmp/generated")5GENERATED_CPP = os.path.join(PATH_TO_GENERATED, "cpp")6PATH_TO_CPP = os.path.abspath("cpp")7TEMPLATES_FOLDER = os.path.join(PATH_TO_CPP, "templates")8FOLDER_TO_COMPILE = os.path.abspath("tmp/to_compile")9RESULTS_FOLDER = os.path.abspath("results")...
Check out the latest blogs from LambdaTest on this topic:
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
Even though several frameworks are available in the market for automation testing, Selenium is one of the most renowned open-source frameworks used by experts due to its numerous features and benefits.
JUnit is one of the most popular unit testing frameworks in the Java ecosystem. The JUnit 5 version (also known as Jupiter) contains many exciting innovations, including support for new features in Java 8 and above. However, many developers still prefer to use the JUnit 4 framework since certain features like parallel execution with JUnit 5 are still in the experimental phase.
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!!