Best Python code snippet using hypothesis
CreateDB.py
Source: CreateDB.py
1#!/usr/bin/env python 2# -*- coding:utf-8 -*-3# @Author: Lancer4# @File CreateDB.py5# @Time 2019/7/22 12:096import os,sys,re,sqlite37'''8æåio_table.c代ç ä¸IOä½æ°æ®ä¸ºio_table.dbæ°æ®åºæ件9'''10table_pattern = re.compile(r"\{(.*)\}") #è·å{ } ä¸é´çæ°æ®é»è®¤ä¸ºioæ°æ®11name_pattern = re.compile(r"var_item_t\w*\[") #è·å表å åæ¯æ°åä¸å线12del_patterm = re.compile(r"var_item_t\w*=") #è·å表å åæ¯æ°åä¸å线13class CreateDB(object):14 def __init__(self):15 self.db_table_list = [] #åå¨æ¯å¼ 表表16 self.io_table_list = [ ] #åå¨ææ表çæ°æ®17 self.read_iotable_cfile()18 for i in range(len(self.io_table_list)):19 pass20 #print(self.io_table_list[i])21 self.write_all_table()22 def read_iotable_cfile(self):23 if True == os.path.exists('io_table.c'):24 with open('io_table.c', encoding='gbk') as f:25 lines = f.readlines()26 convert_lines = ""27 for line in lines:28 line = re.sub(r"/\*.*\*/","",line )29 line = re.sub(r'',"",line )30 convert_lines = convert_lines + line31 convert_lines = convert_lines.replace('\n','').replace('\t','').replace(' ','')32 convert_lines = re.sub(r"/\*.*\*/","",convert_lines)33 convert_lines = re.sub(r"#.*\"", "", convert_lines)34 name_test = name_pattern.findall(convert_lines)35 if name_test is not None:36 for i in range(len(name_test)):37 name_test[i] = re.sub("var_item_t","",name_test[i])38 name_test[i] = re.sub("\[","",name_test[i])39 #print(name_test[i],type(name_test[i]))40 self.db_table_list.append(name_test[i]) #è·å¾è¡¨å41 else:42 print("å¹é
表å失败")43 # è·å¾æ¯ä¸ªè¡¨çIOæ°æ®44 all_table = convert_lines.split(";")45 for i in range(len(all_table)):46 per_table = table_pattern.search(all_table[i])47 if per_table is not None:48 per_table = per_table.group()49 per_table = per_table.replace("{","").replace("}","")50 per_table = per_table.split(",")51 for i in range(len(per_table)):52 per_table[i] = per_table[i].strip()53 #per_table[i] = per_table[i].replace("(", "#").replace(")", "")54 #per_table[i] = per_table[i].replace("(", "#").replace(")", "").split("_")[-1]55 per_table.pop()56 self.io_table_list.append(per_table)57 else:58 pass59 #print("å¹é
{ }失败")60 else:61 print("io_table.c æ件ä¸åå¨")62 def write_all_table(self):63 if True == os.path.exists('test_io.db'):64 os.remove("test_io.db")65 # self.db_table_list = [] #åå¨æ¯å¼ 表表66 # self.io_table_list = [ ] #åå¨ææ表çæ°æ®67 if len(self.db_table_list) == len(self.io_table_list):68 for i in range(len(self.db_table_list)):69 self.write_per_table(self.db_table_list[i],self.io_table_list[i])70 print("åå
¥è¡¨:%s len:%d %d "%(self.db_table_list[i],len(self.io_table_list[i]), i ))71 print("åå
¥è¡¨ä¸ªæ°:%d æå"%(len(self.db_table_list)))72 else:73 print("å¹é
表个æ°å表å个æ°ä¸ä¸è´ 请æ£æ¥æä»¶æ ¼å¼ %d %d"%( len(self.db_table_list),len(self.io_table_list)))74 #åå
¥.dbæ°æ®75 def write_per_table(self,table_name, table_data_list):76 '''77 å°io_table.cæ件ä¸æ°æ®è½¬å为dbæ件78 '''79 con = sqlite3.connect("test_io.db")80 cur = con.cursor()81 try:82 cur.execute('''create table if not exists %s\83 (inddex char(5) NOT NULL,\84 io_name char(40) NOT NULL);'''%(table_name))85 for i in range(len(table_data_list)):86 if 0 != len(table_data_list[i]):87 cur.execute("insert into %s(inddex,io_name) values(?,?);"%(table_name), (i, table_data_list[i]))88 con.commit()89 cur.execute("select name from sqlite_master where type='table' order by name")90 #cur.execute("insert into driverinfo(inddex,io_name) values(?,?);",(dataass[0][0], dataass[0][1]))91 except sqlite3.Error as e:92 print("An error occurred: %s", e.args[0])93 finally:94 cur.close()95 con.close()96if __name__ == "__main__":97 demo = CreateDB()...
ptuukkan.py
Source: ptuukkan.py
...16 for c in line:17 if not c in " .#":18 return 019 return dim20def convert_lines(lines, dim):21 "Changes list lines from horizontal to vertical"22 i = 023 converted_lines = []24 while i < dim:25 converted_lines.append("".join(line[i] for line in lines))26 i += 127 return converted_lines28def fall_sand(vlines):29 "Simulates falling of sand for each line"30 fallen_lines = []31 for line in vlines:32 i = 033 splitted = line.split('#')34 for part in splitted:35 splitted[i] = part.replace(" ", "").rjust(len(part), " ")36 i += 137 fallen_lines.append("#".join(splitted))38 return fallen_lines39lines = []40for line in sys.stdin.readlines():41 lines.append(line.rstrip('\n'))42dim = validate_input(lines)43if dim == 0:44 exit("Invalid input")45vertical_lines = convert_lines(lines, dim)46fallen_lines = fall_sand(vertical_lines)47lines = convert_lines(fallen_lines, dim)48for line in lines:...
part1.py
Source: part1.py
...20 '#1 @ 1,3: 4x4',21 '#2 @ 3,1: 4x4',22 '#3 @ 5,5: 2x2',23]24inputs = convert_lines(test)25print(inputs)26# f = open("input.txt", "r")27# inputs = convert_lines(f.readlines())...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.
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!!