Best Python code snippet using hypothesis
excelField.py
Source:excelField.py
1# -*- coding: utf-8 -*-23import arcpy4import os5import xlwt6import xlrd7import numpy as np8import re910#ÑÑнкÑиÑ, пÑиводÑÑÐ°Ñ Ð·Ð½Ð°ÑÐµÐ½Ð¸Ñ Ðº ÑÐ¸Ð¿Ñ str11def to_unicode(l):12 for i in range(1, len(l)):13 if type(l[i]) == long:14 l[i] = unicode(int(l[i]))15 elif type(l[i]) == float:16 l[i] = unicode(int(l[i]))17 elif type(l[i]) == int:18 l[i] = unicode(l[i])19 elif type(l[i]) == str:20 l[i] = unicode(l[i]) 21 elif type(l[i]) == unicode:22 pass23 else:24 arcpy.AddMessage('invalid field type: '+l[i])25 l[i] = '!?: '+str(l[i])26 return l2728#ÑÑнкÑиÑ, ÑдалÑÑÑÐ°Ñ Ð½ÐµÐ·Ð½Ð°ÑаÑие знаÑениÑ29def clean(l):30 for i in range(1, len(l)):31 if l[i]=='-' or l[i]=='â' or l[i]==u'ÐÐÐ':32 l[i] = ''33 return l3435#ÑÑнкÑиÑ, вÑÑвлÑÑÑÐ°Ñ Ð¿ÑÑÑÑе ÑÑейки обÑзаÑелÑнÑÑ
Ð´Ð»Ñ Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ Ð¿Ð¾Ð»ÐµÐ¹ 36def full(l):37 for i in range(1, len(l)):38 if l[i]=='' or l[i] is None:39 l[i] = '!?: '40 return l4142#ÑÑнкÑиÑ, заменÑÑÑÐ°Ñ Ð·Ð½Ð°ÑÐµÐ½Ð¸Ñ Ð½Ð° ÑооÑвеÑÑÑвÑÑÑие ÐºÐ¾Ð´Ñ Ð°ÑÑибÑÑивного домена43def domen(l):44 for i in range(1, len(l)):45 if l[i].lower().find(u'не баланÑ') != -1:46 l[i] = 247 elif l[i].lower().find(u'баланÑ') != -1:48 l[i] = 149 elif l[i].lower().find(u'ÑелÑÑк') != -1:50 l[i] = 151 elif l[i].lower().find(u'гоÑод') != -1:52 l[i] = 253 elif l[i].lower().find(u'Ð´Ð¾Ð³Ð¾Ð²Ð¾Ñ Ð½Ð° Ñо по заÑвке аб') != -1:54 l[i] = 255 elif l[i].lower().find(u'Ð´Ð¾Ð³Ð¾Ð²Ð¾Ñ Ð½Ð° Ñо') != -1:56 l[i] = 157 elif l[i].lower().find(u'без договоÑа на Ñо') != -1:58 l[i] = 459 elif l[i].lower().find(u'беÑÑ
озÑйнÑе огÑ
') != -1:60 l[i] = 99961 elif l[i].lower().find(u'огÑ
ÑÑоÑонниÑ
оÑганизаÑий') != -1:62 l[i] = 563 elif l[i].lower().find(u'обÑекÑÑ Ð¼Ð¸Ð½Ð¸ÑÑеÑÑÑва обоÑонÑ') != -1:64 l[i] = 665 elif l[i].lower().find(u'Ð´Ð¾Ð³Ð¾Ð²Ð¾Ñ Ð°ÑендÑ') != -1:66 l[i] = 367 elif l[i] == '':68 pass 69 else:70 arcpy.AddMessage('not in the domain: '+l[i])71 l[i] = '!?: '+l[i]72 73 return l7475reestr_path_list = arcpy.GetParameterAsText(0).split(';')76dest_folder = arcpy.GetParameterAsText(1)7778wb = xlwt.Workbook()79ws = wb.add_sheet('reestr',cell_overwrite_ok=True)8081err_style = xlwt.easyxf('pattern: pattern solid, fore_colour red;')82err2_style = xlwt.easyxf('pattern: pattern solid, fore_colour yellow;')83err3_style = xlwt.easyxf('pattern: pattern solid, fore_colour green;')8485tit = ['routeN', 'SGSegmN', 'ITDname', 'RightOwner', 'InventNum', 'commens', 'Contractor', 'passN', 'recordN', 'ContrNum', 'SGplase', 'KEY']8687offset = 0 #Ñдвиг нÑмеÑаÑии ÑÑÑок ÑаблиÑÑ, пÑиÑоединÑемой к пÑедÑдÑÑей88not_first = 0 #паÑамеÑÑ, опÑеделÑÑÑий добавление заголовка ÑолÑко Ð´Ð»Ñ Ð¿ÐµÑвой ÑаблиÑÑ Ð¸Ð· вÑеÑ
ÑоединÑемÑÑ
8990for file_location in reestr_path_list:91 92 workbook = xlrd.open_workbook(file_location)93 sheet = workbook.sheet_by_index(0)94 95 col_list = []9697 col_list.append(to_unicode(full(clean(sheet.col_values(0)))))98 col_list.append(to_unicode(full(clean(sheet.col_values(3)))))99 col_list.append(to_unicode(full(clean(sheet.col_values(5)))))100 col_list.append(full(domen(clean(sheet.col_values(6)))))101 col_list.append(to_unicode(clean(sheet.col_values(7))))102 col_list.append(to_unicode(clean(sheet.col_values(8))))103 col_list.append(domen(clean(sheet.col_values(9))))104 col_list.append(to_unicode(full(clean(sheet.col_values(10)))))105 col_list.append(to_unicode(full(clean(sheet.col_values(11)))))106 col_list.append(to_unicode(clean(sheet.col_values(15))))107 col_list.append(full(domen(clean(sheet.col_values(16)))))108109 #копиÑÑем знаÑÐµÐ½Ð¸Ñ Ð² новÑÑ ÑаблиÑÑ, заменÑÑ Ð·Ð½Ð°ÑÐµÐ½Ð¸Ñ Ð½Ð° доменнÑе ÐºÐ¾Ð´Ñ Ð¸ пÑовеÑÑÑ Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð½Ð¾ÑÑÑ Ð¾Ð±ÑзаÑелÑнÑÑ
полей110 for i in range(0, len(col_list)):111 for j in range(0, len(col_list[i])-not_first):112 if unicode(col_list[i][j+not_first]).find('!?: ') != -1:113 ws.write(j+offset, i, col_list[i][j+not_first].replace('!?: ',''), err_style)114 else:115 ws.write(j+offset, i, col_list[i][j+not_first])116 117 #оÑмеÑаем желÑÑм ÑвеÑом неÑооÑвеÑÑÑвие инвенÑаÑного номеÑа баланÑовой пÑинадлежноÑÑи118 for i in range(0, len(col_list[3])-not_first):119 if col_list[3][i+not_first] == 1 and col_list[4][i+not_first] == '':120 ws.write(i+offset, 4, col_list[4][i+not_first], err2_style)121 elif col_list[3][i+not_first] == 2 and col_list[4][i+not_first] != '':122 ws.write(i+offset, 4, col_list[4][i+not_first], err2_style)123124 #оÑмеÑаем желÑÑм ÑвеÑом неÑооÑвеÑÑÑвие вида договоÑа баланÑовой пÑинадлежноÑÑи 125 for i in range(0, len(col_list[3])-not_first): 126 if col_list[3][i+not_first] == 1 and col_list[6][i+not_first] != '':127 if unicode(col_list[6][i+not_first]).find('!?: ')!= -1:128 ws.write(i+offset, 6, col_list[6][i+not_first].replace('!?: ',''), err2_style)129 else:130 ws.write(i+offset, 6, col_list[6][i+not_first], err2_style)131 elif col_list[3][i+not_first] == 2 and col_list[6][i+not_first] == '':132 ws.write(i+offset, 6, col_list[6][i+not_first], err2_style)133134 #оÑмеÑаем желÑÑм ÑвеÑом неÑооÑвеÑÑÑвие номеÑа договоÑа баланÑовой пÑинадлежноÑÑи 135 for i in range(0, len(col_list[3])-not_first): 136 if col_list[3][i+not_first] == 1 and col_list[9][i+not_first] != '':137 ws.write(i+offset, 9, col_list[9][i+not_first], err2_style)138 elif col_list[3][i+not_first] == 2 and col_list[9][i+not_first] == '':139 ws.write(i+offset, 9, col_list[9][i+not_first], err2_style)140141 #заполнÑем поле KEY конкаÑенаÑией номеÑа паÑпоÑÑа и номеÑа запиÑи, оÑмеÑÐ°Ñ Ð·ÐµÐ»ÐµÐ½Ñм неÑникалÑнÑе знаÑениÑ142 key_list = []143 for i in range(0, len(col_list[7])-not_first):144 key_value = col_list[7][i+not_first]+'+'+col_list[8][i+not_first]145 if key_value in key_list:146 ws.write(i+offset, 11, key_value, err3_style)147 else:148 ws.write(i+offset, 11, key_value)149 key_list.append(key_value)150 151 #менÑем заголовок ÑаблиÑÑ Ð½Ð° имена полей аÑÑибÑÑивной ÑаблиÑÑ152 if not_first == 0:153 for i in range(0, len(tit)):154 ws.write(0, i, tit[i])155 156 offset += len(col_list[0]) - not_first157 not_first = 1158
...
test_solid_aliases.py
Source:test_solid_aliases.py
...13 @lambda_solid()14 def first():15 return ['first']16 @lambda_solid(input_defs=[InputDefinition(name="prev")])17 def not_first(prev):18 return prev + ['not_first']19 pipeline = PipelineDefinition(20 solid_defs=[first, not_first],21 dependencies={22 'not_first': {'prev': DependencyDefinition('first')},23 SolidInvocation('not_first', alias='second'): {24 'prev': DependencyDefinition('not_first')25 },26 SolidInvocation('not_first', alias='third'): {'prev': DependencyDefinition('second')},27 },28 )29 result = execute_pipeline(pipeline)30 assert result.success31 solid_result = result.result_for_solid('third')32 assert solid_result.output_value() == ['first', 'not_first', 'not_first', 'not_first']33def test_only_aliased_solids():34 @lambda_solid()35 def first():36 return ['first']37 @lambda_solid(input_defs=[InputDefinition(name="prev")])38 def not_first(prev):39 return prev + ['not_first']40 pipeline = PipelineDefinition(41 solid_defs=[first, not_first],42 dependencies={43 SolidInvocation('first', alias='the_root'): {},44 SolidInvocation('not_first', alias='the_consequence'): {45 'prev': DependencyDefinition('the_root')46 },47 },48 )49 result = execute_pipeline(pipeline)50 assert result.success51 solid_result = result.result_for_solid('the_consequence')52 assert solid_result.output_value() == ['first', 'not_first']...
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!!