Best Python code snippet using pandera_python
stp_header_parser.py
Source: stp_header_parser.py
1import re2class stp_header_parser():3 def stp_header_parser(self, stp_filename='', is_debug=False):4 def get_unit_abbr(units):5 prefix = {'MILLI': 'm'}6 unit = {'METRE': 'm'}7 return prefix[units[0]]+unit[units[1]]8 9 def remove_comments(line):10 comment_pattern = re.compile('/\*.*?\*/')11 return comment_pattern.sub('', line)12 13 def line_extract(filehandle=None, str_startswith='', str_endswith=''):14 while True:15 line = filehandle.readline().strip()16 #if line.startswith(str_startswith):17 if str_startswith in line:18 line_extracted = ''19 while True:20 line_extracted += line21 if line.endswith(str_endswith):22 break23 else:24 line = filehandle.readline().strip()25 return line_extracted26 infos_name = [27 'ISO Standard',28 'Description',29 'Implementation Level',30 'Name',31 'Time_Stamp',32 'Author',33 'Organization',34 'Preprocessor Version',35 'Originating System',36 'Authorization',37 'Schema',38 'Unit'39 ]40 infos_value = []41 len_infos_name = len(infos_name)42 with open(stp_filename, 'r') as f:43 44 line = line_extract(f, 'ISO-', ';')45 if line:46 ISO_Standard = line[:-1]47 infos_value.append(ISO_Standard)48 line = line_extract(f, 'HEADER', ';')49 if line:50 if is_debug:51 print('>>> Header Start Mark Found <<<')52 line = line_extract(f, 'FILE_DESCRIPTION', ';')53 line = remove_comments(line)54 File_Description = eval(line[16:-1])55 infos_value += File_Description56 line = line_extract(f, 'FILE_NAME', ';')57 line = remove_comments(line)58 File_Name = eval(line[9:-1])59 infos_value += File_Name60 line = line_extract(f, 'FILE_SCHEMA', ';')61 line = remove_comments(line)62 File_Schema = eval(line[11:-1])63 infos_value.append(File_Schema)64 if line_extract(f, 'ENDSEC', ';'):65 if is_debug:66 print('>>> Header End Mark Found <<<')67 68 while True:69 line = line_extract(f, 'LENGTH_UNIT', ';')70 units = line.split('SI_UNIT')71 if(len(units) == 2):72 units = units[1].split('.')[1:4:2]73 units = get_unit_abbr(units)74 infos_value.append(units)75 break76 77 infos_dict = {78 index: list(parameter) for (79 index, parameter) in zip(80 range(len_infos_name), zip(81 infos_name, infos_value))}82 if is_debug:83 for key in infos_dict:84 print('{:02}\t{}'.format(key, infos_dict[key]))...
draw.py
Source: draw.py
1import matplotlib.pyplot as plt2import numpy as np3import os4def plot_multiple_flops_sec(str_startswith):5 for file in os.listdir("results"):6 if file.startswith(str_startswith):7 draw_flops_sec(*read_file(f"results/{file}"))8 plt.legend()9 plt.minorticks_on()10 plt.grid(color='b', linestyle='-', linewidth=0.2, alpha=0.5)11def plot_multiple_flops(str_startswith):12 for file in os.listdir("results"):13 if file.startswith(str_startswith):14 draw_flops(*read_file(f"results/{file}"))15 plt.legend()16 plt.minorticks_on()17 plt.grid(color='b', linestyle='-', linewidth=0.2, alpha=0.5)18def plot_multiple_times(str_startswith):19 for file in os.listdir("results"):20 if file.startswith(str_startswith):21 draw_time(*read_file(f"results/{file}"))22 plt.legend()23 plt.minorticks_on()24 plt.grid(color='b', linestyle='-', linewidth=0.2, alpha=0.5)25def read_file(filepath):26 ret = [[], [], []]27 with open(filepath, 'r') as target:28 lines = target.readlines()29 infos = ""30 if lines[0].startswith('##'):31 line = lines.pop(0)32 line = lines.pop(0)33 while not line.startswith('##'):34 infos += line35 line = lines.pop(0)36 for line in lines:37 if line.count(':') == 1:38 N, time = line.split(':')39 ret[0].append(float(N))40 ret[1].append(float(time))41 ret[2].append(float(time))42 else:43 N, *flop, time, _ = line.split(':')44 ret[0].append(float(N))45 ret[1].append(sum([float(x.replace(',', '')) for x in flop]))46 ret[2].append(float(time))47 # this assures that we have that sorted by N48 str_legend = " ".join(os.path.basename(filepath).split('_')[-3:])49 return list(zip(*sorted(zip(*ret), key=lambda x: x[0]))), str_legend50def draw_flops_sec(input_data, str_legend):51 print(str_legend)52 sizes, flops_sec, _, _ = avg_reduce(input_data)53 plt.plot(sizes, flops_sec, label=str_legend)54 plt.ylabel("Flops/sec")55 plt.xlabel("Problem size")56def draw_flops(input_data, str_legend):57 print(str_legend)58 sizes, _, _, flops = avg_reduce(input_data)59 plt.plot(sizes, flops, label=str_legend)60 plt.ylabel("Flops")61 plt.xlabel("Problem size")62def draw_time(input_data, str_legend):63 print(str_legend)64 sizes, _, sec, _ = avg_reduce(input_data)65 plt.plot(sizes, sec, label=str_legend)66 plt.ylabel("Time in s")67 plt.xlabel("Problem size")68def avg_reduce(input_data):69 dict = {}70 for n, flops, time in zip(*input_data):71 if n not in dict:72 dict[n] = []73 dict[n].append((flops, time))74 sizes, flops_sec, sec, flops = [], [], [], []75 for key, value in dict.items():76 sizes.append(key)77 flops_sec.append(78 sum([flop / time for flop, time in value]) / len(value))79 sec.append(sum([time for _, time in value]) / len(value))80 flops.append(sum([flops for flops, _ in value]) / len(value))...
strfunctions_mod.py
Source: strfunctions_mod.py
1#!/usr/bin/env python32"""3strfunctions_mod.py4"""5import os6def prepend_slash_if_needed(middlepath):7 try:8 if not middlepath.startswith('./'):9 middlepath = middlepath.lstrip('.')10 middlepath = middlepath.lstrip('/')11 middlepath = '/' + middlepath12 return middlepath13 except AttributeError:14 pass15 except ValueError:16 pass17 return ''18def put_ellipsis_in_str_middle(line, linecharsize=80):19 if line is None:20 return ''21 if len(line) <= linecharsize:22 return line23 sizediff = len(line) - linecharsize24 half_sizediff = sizediff // 225 midpos = len(line) // 226 p1_midpos = midpos - half_sizediff27 p2_midpos = midpos + half_sizediff28 p1 = line[: p1_midpos]29 p2 = line[p2_midpos:]30 newline = p1 + '...' + p231 return newline32def any_dir_in_path_startswith(fpath, str_startswith):33 if fpath is None:34 return False35 try:36 pp = fpath.split('/')37 except (AttributeError, TypeError):38 # examples: a number will generate an AttributeError; a binary will generate a TypeError39 return False40 for foldername in pp:41 if foldername.startswith(str_startswith):42 return True43 return False44def clean_rename_filename_to(filename):45 if filename is None:46 return None47 name, ext = os.path.splitext(filename)48 newname = name.lstrip(' \t').rstrip(' \t\r\n').replace(':', ';')49 newext = ext.lstrip(' \t').rstrip(' \t\r\n').replace(':', ';').replace('?', '_')50 if newext is None or newext == '' or newext == '.':51 newfilename = newname52 return newfilename53 if not newext.startswith('.'):54 newext = '.' + newext55 newfilename = newname + newext56 return newfilename57# noinspection PyTypeChecker58def adhoc_test():59 def print_result(phrase, p_str_startswith):60 print('for [', phrase, '] starting with [', p_str_startswith, '], return is', bool_ret)61 f = 'mp3s bla bla'62 str_startswith = 'mp3s '63 bool_ret = any_dir_in_path_startswith(f, str_startswith)64 print_result(f, str_startswith)65 f = 366 bool_ret = any_dir_in_path_startswith(f, str_startswith)67 print_result(f, str_startswith)68 f = bytes('fasdfalsdfa'.encode('utf8'))69 bool_ret = any_dir_in_path_startswith(f, str_startswith)70 print_result(f, str_startswith)71 f = 'z-del'72 str_startswith = f73 bool_ret = any_dir_in_path_startswith(f, str_startswith)74 print_result(f, str_startswith)75if __name__ == '__main__':...
Check out the latest blogs from LambdaTest on this topic:
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.
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!!