Best Python code snippet using hypothesis
appointment_slots.py
Source:appointment_slots.py
1import datetime2from django.utils import timezone3import pytz4def validate_appo(str_rep, appointment_start, duration):5 start = appointment_start6 appointment_start = appointment_start.replace(second=0, microsecond=0)7 tz = pytz.timezone('Asia/Kolkata')8 today = tz.localize(datetime.datetime.now()).replace(9 hour=0, minute=0, second=0, microsecond=0)10 slot_start = int((appointment_start-today).total_seconds()//60)11 slot_end = int((appointment_start-today+duration).total_seconds()//60)12 for i in range(slot_start, slot_end+1):13 if str_rep[i] != 0:14 return False15 return True16def get_str_rep(doctor):17 """18 0 time out of clinic19 B time in clinic but doctor on break20 A appointment set21 """22 from calendar import monthrange23 from accounts.models import Break24 from appointment.models import Appointment25 from accounts.serializers import BreakSerializer26 from appointment.serializers import AppointmentSerializer27 start = doctor.start_time28 end = doctor.end_time29 duration = doctor.appoinment_duration30 str_rep = "0"*24*60*731 tz = pytz.timezone('Asia/Kolkata')32 today = tz.localize(datetime.datetime.now()).replace(33 hour=0, minute=0, second=0, microsecond=0)34 break_qs = Break.objects.filter(35 doctor=doctor, time_start__gte=today, time_end__lte=today+datetime.timedelta(days=7))36 appo_qs = Appointment.objects.filter(37 doctor=doctor, time_start__gte=today, time_start__lte=today+datetime.timedelta(days=7))38 # breaks = BreakSerializer(39 # break_qs, fields=['time_start', 'time_end', 'repeat'], many=True).data40 # breaks = BreakSerializer(41 # data=breaks, fields=['time_start', 'time_end', 'repeat'], many=True)42 # appos = AppointmentSerializer(43 # appo_qs, fields=['time_start'], many=True).data44 # appos = AppointmentSerializer(45 # data=appos, fields=['time_start'], many=True)46 duration_repete = datetime.timedelta(days=1).total_seconds()//6047 clinic_end = (today.replace(48 hour=end.hour, minute=end.minute)-today).total_seconds()//60-149 clinic_start = (today.replace(hour=start.hour,50 minute=start.minute)-today).total_seconds()//60-151 str_rep = str_replace(str_rep, 0, int(clinic_start), '-')52 for i in range(6):53 str_rep = str_replace(str_rep, int(54 i*duration_repete+clinic_end), int((i+1)*duration_repete+clinic_start), '-')55 str_rep = str_replace(str_rep, int(56 6*duration_repete+clinic_end), len(str_rep)-1, '-')57 for i, break_ in enumerate(break_qs):58 print('processing break :', i)59 if break_.repeat == 'N':60 # is_valid = is_valid_break(start, end, break_)61 # if not is_valid:62 # return False63 if break_.start_time.date() < today.date():64 print('break creation problem')65 print('skipped sice it is old break')66 print(break_.start_time.date())67 print(break_.end_time.date())68 continue69 slot_start = (break_.start_time-today).total_seconds()//6070 slot_end = (break_.end_time-today).total_seconds()//6071 str_rep = str_replace(str_rep, int(slot_start), int(slot_end), 'b')72 continue73 if break_.repeat == "D":74 # is_valid = is_valid_break(start, end, break_)75 # if not is_valid:76 # return False77 duration_repete = datetime.timedelta(days=1).total_seconds()//6078 slot_start = (break_.time_start.replace(79 year=today.year, month=today.month, day=today.day)-today).total_seconds()//6080 slot_end = (break_.time_end.replace(81 day=today.day, month=today.month, year=today.year)-today).total_seconds()//6082 for i in range(7):83 str_rep = str_replace(str_rep, int(84 i*duration_repete+slot_start), int(i*duration_repete+slot_end), 'b')85 if break_.repeat == "W":86 # is_valid = is_valid_break(start, end, break_)87 # if not is_valid:88 # return False89 days_from_today = (90 (7+break_.time_start.weekday()-today.weekday()) % 7)91 print('days_from_today', days_from_today)92 duratio_from_today = datetime.timedelta(93 days=days_from_today).total_seconds()//6094 print('duratio_from_today', duratio_from_today)95 slot_start = (break_.time_start.replace(96 year=today.year, day=today.day, month=today.month)-today).total_seconds()//6097 print('slot_start', slot_start)98 slot_end = (break_.end_time.replace(99 day=today.day, month=today.month, year=today.year)-today).total_seconds()//60100 print('slot_end', slot_end)101 str_rep = str_replace(str_rep, int(102 duratio_from_today+slot_start), int(duratio_from_today+slot_end), 'b')103 continue104 if break_.repeat == "M":105 # is_valid = is_valid_break(start, end, break_)106 # if not is_valid:107 # return False108 try:109 break_start = break_.start_time.replace(110 year=today.year, month=today.month)111 break_end = break_.end_time.replace(112 year=today.year, month=today.month)113 except:114 print('break creation problem')115 print('current month does not have specified date')116 continue117 print(break_end.date())118 print((today+datetime.timedelta(days=7)).date())119 if today.date() > break_start.date() and break_start.date() < (today+datetime.timedelta(days=7)).date():120 print('skipped this break because it is not part of comming week')121 continue122 slot_start = (break_start-today).total_seconds()//60123 slot_end = (break_end-today).total_seconds()//60124 print(slot_start, slot_end)125 str_rep = str_replace(str_rep, int(slot_start), int(slot_end), 'b')126 for i, appo in enumerate(appo_qs):127 print('processing appo :', i)128 appo.time_start = appo.time_start.replace(129 second=0, microsecond=0)130 if appo.time_start.date() < today.date() or appo.time_start.date() > (today+datetime.timedelta(days=7)).date():131 print('appo creation problem')132 print('old oopo')133 print(appo.time_start.date())134 continue135 slot_start = (appo.time_start-today).total_seconds()//60136 slot_end = (appo.time_start-today+duration).total_seconds()//60137 str_rep = str_replace(str_rep, int(slot_start), int(slot_end), 'a')138 continue139 return str_rep140def is_valid_break(start, end, break_):141 # if break_['start_time'].date() != break_['end_time'].date():142 # print('break creation problem')143 # print('break date is not matching')144 # print(break_['start_time'].date())145 # print(break_['end_time'].date())146 # return False147 # if break_['start_time'].date() > (timezone.now()+datetime.timedelta(days=7)).date():148 # print('break creation problem')149 # print('future break')150 # print(break_['start_time'].date())151 # print(break_['end_time'].date())152 # return False153 # if break_['start_time'] > break_['end_time'] or break_['start_time'].time() < start or break_['end_time'].time() > end:154 # print('break creation problem')155 # print('invalid break start time must be bigger than end time')156 # print('break must be set between clinic time')157 # print(break_['start_time'])158 # print(break_['end_time'])159 # print(break_['start_time'].time())160 # print(start)161 # print(break_['end_time'].time())162 # print(end)163 # print('invalid break')164 # return False165 return True166def check_break(str_rep, start, end, repete):167 import pytz168 tz = pytz.timezone('Asia/Kolkata')169 today = tz.localize(datetime.datetime.now()).replace(170 hour=0, minute=0, second=0, microsecond=0)171 mnc = (start.replace(day=today.day, month=today.month, year=today.year)-today)172 start_min = int((start.replace(day=today.day, month=today.month,173 year=today.year)-today).total_seconds()//60)174 end_min = int((end.replace(day=today.day, month=today.month,175 year=today.year)-today).total_seconds()//60)176 repete_duration = int(datetime.timedelta(days=1).total_seconds()//60)177 if repete == 'D':178 for i in range(7):179 for j in range(start_min, end_min+1):180 asx = str_rep[i*repete_duration+j]181 if str_rep[i*repete_duration+j] != '0' and str_rep[i*repete_duration+j].lower() != 'b':182 print("i j", i, j, start_min, end_min, i*repete_duration+j)183 return False184 else:185 for j in range(start_min, end_min+1):186 if str_rep[start_min+j] != '0' and str_rep[start_min+j].lower() != 'b':187 return False188 return True189def str_replace(str_rep, start, end, key):190 list_rep = list(str_rep)191 list_rep[start+1:end] = [key]*(end-start-1)192 list_rep[start] = key.upper()193 list_rep[end] = key.upper()194 return "".join(list_rep)195def str_to_slots(str_rep, appointment_duration):196 l = list()197 today = datetime.datetime.today().replace(198 hour=0, minute=0, second=0, microsecond=0)199 i = 0200 print(appointment_duration)201 duration_counter = int(appointment_duration.total_seconds()//60)202 print(duration_counter)203 add_in_break = False204 while i < len(str_rep):205 if i == 470:206 print('n')207 if str_rep[i] == '0':208 duration_counter = int(appointment_duration.total_seconds()//60)209 temp = i210 while i < len(str_rep) and duration_counter > 0 and str_rep[i] == '0':211 i += 1212 duration_counter -= 1213 print(temp, i, duration_counter)214# print('dc',duration_counter)215 if duration_counter == 0:216 empty_slot = {}217 empty_slot['type'] = 'E'218 empty_slot['start_index'] = today + \219 datetime.timedelta(minutes=temp)220 empty_slot['end_index'] = today+datetime.timedelta(minutes=i-1)221 l.append(empty_slot)222 duration_counter = int(223 appointment_duration.total_seconds()//60)224 elif duration_counter >= 1:225 if (i == len(str_rep) or str_rep[i] == 'A' or str_rep[i] == '-'):226 break_ = {}227 break_['type'] = 'B'228 break_['start_index'] = today + \229 datetime.timedelta(minutes=temp)230 break_['end_index'] = today+datetime.timedelta(minutes=i-1)231 l.append(break_)232 duration_counter = int(233 appointment_duration.total_seconds()//60)234 elif str_rep[i] == 'B':235 add_in_break = True236 duration_counter = int(237 appointment_duration.total_seconds()//60)238 continue239# print('dsuj',i,len(str_rep))240 if (i == 0 or str_rep[i-1] != str_rep[i] or str_rep[i-1] == 'B') and str_rep[i] == 'B':241 break_ = {}242 break_['type'] = 'B'243 if add_in_break:244 break_['start_index'] = today+datetime.timedelta(minutes=temp)245 add_in_break = False246 else:247 break_['start_index'] = today+datetime.timedelta(minutes=i)248 while i < len(str_rep) and str_rep[i].lower() == 'b':249 i += 1250 i -= 1251 break_['end_index'] = today+datetime.timedelta(minutes=i)252 l.append(break_)253 if (i == 0 or str_rep[i-1] != str_rep[i]) and str_rep[i] == 'A':254 appo = {}255 appo['type'] = 'A'256 appo['start_index'] = today+datetime.timedelta(minutes=i)257 appo['end_index'] = today + \258 datetime.timedelta(minutes=str_rep.index('A', i+1))259 i = str_rep.index('A', i+1)260 l.append(appo)261 i += 1262 for item in l:263 if item['type'] == 'B':264 print('***********************Break**********************************')265 print(item['start_index'])266 print(item['end_index'])267 print()268 print()269 if item['type'] == 'A':270 print('***********************Appointment**********************************')271 print(item['start_index'])272 print(item['end_index'])273 print()274 print()275 if item['type'] == 'E':276 print('***********************Empty**********************************')277 print(item['start_index'])278 print(item['end_index'])279 print()280 print()281 return l282if __name__ == '__main__':283 appointment_data = {284 "start_time": datetime.datetime.strptime("2021-06-24 08:40:00", "%Y-%m-%d %H:%M:%S").time(),285 "end_time": datetime.datetime.strptime("2021-06-24 18:40:00", "%Y-%m-%d %H:%M:%S").time(),286 "appoinment_duration": datetime.timedelta(minutes=30),287 "breaks": [288 {289 "start_time": datetime.datetime.strptime("2000-06-30 13:40:00", "%Y-%m-%d %H:%M:%S"),290 "end_time": datetime.datetime.strptime("2000-06-30 14:20:00", "%Y-%m-%d %H:%M:%S"),291 "repete": "M",292 "reason": "jdncdsm",293 },294 {295 "start_time": datetime.datetime.strptime("2021-06-28 16:30:00", "%Y-%m-%d %H:%M:%S"),296 "end_time": datetime.datetime.strptime("2021-06-28 17:20:00", "%Y-%m-%d %H:%M:%S"),297 "repete": "N",298 "reason": "jdncdsm",299 },300 {301 "start_time": datetime.datetime.strptime("2020-07-02 09:30:00", "%Y-%m-%d %H:%M:%S"),302 "end_time": datetime.datetime.strptime("2020-07-02 17:30:00", "%Y-%m-%d %H:%M:%S"),303 "repete": "N",304 "reason": "jdncdsm",305 },306 {307 "start_time": datetime.datetime.strptime("2020-07-01 12:30:00", "%Y-%m-%d %H:%M:%S"),308 "end_time": datetime.datetime.strptime("2020-07-01 17:15:00", "%Y-%m-%d %H:%M:%S"),309 "repete": "N",310 "reason": "jdncdsm",311 }312 ],313 "appointment": [314 {315 "time_start": datetime.datetime.strptime("2021-06-29 17:30:00", "%Y-%m-%d %H:%M:%S"),316 },317 {318 "time_start": datetime.datetime.strptime("2021-06-30 15:30:00", "%Y-%m-%d %H:%M:%S")319 },320 {321 "time_start": datetime.datetime.strptime("2021-07-02 12:30:00", "%Y-%m-%d %H:%M:%S")322 },323 {324 "time_start": datetime.datetime.strptime("2021-07-02 09:30:00", "%Y-%m-%d %H:%M:%S")325 }326 ]327 }328 asd = get_str_rep(appointment_data)329 str_to_slots(asd, datetime.timedelta(minutes=30))330# import time331# import datetime332# import pytz333# def get_str_rep(data):334# """335# 0 time out of clinic336# 1 time in clinic but doctor on break337# 2 appointment set338# """339# from calendar import monthrange340# start=data['clinic_start']341# end=data['clinic_end']342# du=data['duration']343# str_rep="0"*24*60*7344# breaks=data['breaks']345# appos=data['appointment']346# for i,break_ in enumerate(breaks):347# print('processing break :',i)348# break_['time_start']=break_['time_start'].replace(second=0,microsecond=0)349# break_['time_start']=break_['time_start'].replace(second=0,microsecond=0)350# if break_['repete']=='N':351# is_valid=is_valid_break(start,end,du,break_)352# if is_valid=='CON':353# continue354# if not is_valid:355# return False356# if break_['time_start'].date()<datetime.datetime.now().date():357# print('break creation problem')358# print('old break')359# print(break_['time_start'].date())360# print(break_['time_end'].date())361# continue362# slot_start=(break_['time_start']-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()//60363# slot_end=(break_['time_end']-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()//60364# str_rep=str_rep_fun(str_rep,int(slot_start),int(slot_end),'1')365# continue366# if break_['repete']=="D":367# is_valid=is_valid_break(start,end,du,break_)368# if is_valid=='CON':369# continue370# if not is_valid:371# return False372# today=datetime.date.today()373# duration_repete=datetime.timedelta(days=1).total_seconds()//60374# slot_start=(break_['time_start'].replace(day=today.day,month=today.month,year=today.year)-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()//60375# slot_end=(break_['time_end'].replace(day=today.day,month=today.month,year=today.year)-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()//60376# for i in range(7):377# str_rep=str_rep_fun(str_rep, int(i*duration_repete+slot_start), int(i*duration_repete+slot_end), '1')378# if break_['repete']=="W":379# is_valid=is_valid_break(start,end,du,break_)380# if is_valid=='CON':381# continue382# if not is_valid:383# return False384# today=datetime.date.today()385# days_from_today=((7+break_['time_start'].weekday()-today.weekday())%7);386# print('days_from_today',days_from_today)387# duratio_from_today=datetime.timedelta(days=days_from_today).total_seconds()//60388# print('duratio_from_today',duratio_from_today)389# slot_start=(break_['time_start'].replace(year=today.year,day=today.day,month=today.month)-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()//60390# print('slot_start',slot_start)391# slot_end=(break_['time_end'].replace(day=today.day,month=today.month,year=today.year)-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()//60392# print('slot_end',slot_end)393# str_rep=str_rep_fun(str_rep, int(duratio_from_today+slot_start), int(duratio_from_today+slot_end), '1')394# continue395# if break_['repete']=="M":396# is_valid=is_valid_break(start,end,du,break_)397# if is_valid=='CON':398# continue399# if not is_valid:400# return False401# today=datetime.datetime.now()402# try:403# break_start = break_['time_start'].replace(year=today.year,month=today.month,second=0,microsecond=0)404# break_end = break_['time_end'].replace(year=today.year,month=today.month,second=0,microsecond=0)405# except:406# print('break creation problem')407# print('current month does not have specified date')408# continue409# slot_start = (break_start-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()//60410# slot_end = (break_end-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()//60411# print(slot_start,slot_end)412# str_rep = str_rep_fun(str_rep, int(slot_start), int(slot_end), '1')413# for i,appo in enumerate(appos):414# print('processing appo :', i)415# appo['start_time'] = appo['start_time'].replace(second=0, microsecond=0)416# if appo['start_time'].date() < datetime.datetime.now().date() or appo['start_time'].date() > (datetime.datetime.now()+datetime.timedelta(days=7)).date():417# print('appo creation problem')418# print('old oopo')419# print(appo['start_time'].date())420# continue421# slot_start = (appo['start_time']-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)).total_seconds()//60422# slot_end = (appo['start_time']-datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)+datetime.timedelta(minutes=du)).total_seconds()//60423# str_rep = str_rep_fun(str_rep,int(slot_start),int(slot_end),'2')424# continue425# return str_rep426# appointment_data = {427# "clinic_start": datetime.datetime.strptime("2021-06-24 08:40:00","%Y-%m-%d %H:%M:%S").time(),428# "clinic_end": datetime.datetime.strptime("2021-06-24 18:40:00","%Y-%m-%d %H:%M:%S").time(),429# "duration": 30,430# "breaks": [431# {432# "time_start": datetime.datetime.strptime("2000-06-25 13:40:00","%Y-%m-%d %H:%M:%S"),433# "time_end": datetime.datetime.strptime("2000-06-25 14:20:00","%Y-%m-%d %H:%M:%S"),434# "repete": "M",435# "reason": "jdncdsm",436# },437# {438# "time_start": datetime.datetime.strptime("2021-06-27 16:30:00","%Y-%m-%d %H:%M:%S"),439# "time_end": datetime.datetime.strptime("2021-06-27 17:20:00","%Y-%m-%d %H:%M:%S"),440# "repete": "N",441# "reason": "jdncdsm",442# },443# {444# "time_start": datetime.datetime.strptime("2020-06-15 09:30:00","%Y-%m-%d %H:%M:%S"),445# "time_end": datetime.datetime.strptime("2020-06-15 19:30:00","%Y-%m-%d %H:%M:%S"),446# "repete": "N",447# "reason": "jdncdsm",448# },449# {450# "time_start": datetime.datetime.strptime("2020-06-19 05:30:00","%Y-%m-%d %H:%M:%S"),451# "time_end": datetime.datetime.strptime("2020-06-19 19:15:00","%Y-%m-%d %H:%M:%S"),452# "repete": "N",453# "reason": "jdncdsm",454# }455# ],456# "appointment": [457# {458# "start_time": datetime.datetime.strptime("2021-06-25 17:30:00","%Y-%m-%d %H:%M:%S"),459# },460# {461# "start_time": datetime.datetime.strptime("2021-06-25 15:30:00","%Y-%m-%d %H:%M:%S")462# },463# {464# "start_time": datetime.datetime.strptime("2021-06-28 12:30:00","%Y-%m-%d %H:%M:%S")465# },466# {467# "start_time": datetime.datetime.strptime("2021-06-20 09:30:00","%Y-%m-%d %H:%M:%S")468# }469# ]470# }471# def is_valid_break(start,end,du,break_):472# if break_['time_start'].date()!=break_['time_end'].date():473# print('break creation problem')474# print('break date is not matching')475# print(break_['time_start'].date())476# print(break_['time_end'].date())477# return 'RET';478# if break_['time_start'].date()>(datetime.datetime.now()+datetime.timedelta(days=7)).date():479# print('break creation problem')480# print('future break')481# print(break_['time_start'].date())482# print(break_['time_end'].date())483# return 'CON'484# if break_['time_start']>break_['time_end'] or break_['time_start'].time()<start or break_['time_end'].time()>end:485# print('break creation problem')486# print('invalid break')487# print(break_['time_start'])488# print(break_['time_end'])489# print(break_['time_start'].time())490# print(start)491# print(break_['time_end'].time())492# print(end)493# print('invalid break')494# return 'RET';495# return True496# def str_rep_fun(str_rep,start,end,key):497# list_rep=list(str_rep)498# list_rep[start:end+1]=[key]*(end-start+1)499# return "".join(list_rep)500# def str_to_slots(str_rep):501# l=list()502# today=datetime.datetime.today().replace(hour=0,minute=0,second=0,microsecond=0)503# for i in range(len(str_rep)):504# if (i==0 or str_rep[i-1]!=str_rep[i]) and str_rep[i]=='1':505# break_={}506# break_['type']='B'507# break_['start_index']=today+datetime.timedelta(minutes=i)508# if (i!=0 and str_rep[i]!=str_rep[i-1] and str_rep[i-1]=='1'):509# break_['end_index']=today+datetime.timedelta(minutes=i-1)510# l.append(break_)511# if i==len(str_rep)-1 and str_rep[i]=='1':512# break_['end_index']=today+datetime.timedelta(minutes=i)513# l.append(break_)514# if (i==0 or str_rep[i-1]!=str_rep[i]) and str_rep[i]=='2':515# appo={}516# appo['type']='A'517# appo['start_index']=today+datetime.timedelta(minutes=i)518# if (i!=0 and str_rep[i]!=str_rep[i-1] and str_rep[i-1]=='2'):519# appo['end_index']=today+datetime.timedelta(minutes=i-1)520# l.append(appo)521# if i==len(str_rep)-1 and str_rep[i]=='2':522# appo['end_index']=today+datetime.timedelta(minutes=i)523# l.append(appo)524# for item in l:525# if item['type']=='B':526# print('***********************Break**********************************')527# print(item['start_index'])528# print(item['end_index'])529# print()530# print()531# if item['type']=='A':532# print('***********************Appointment**********************************')533# print(item['start_index'])534# print(item['end_index'])535# print()536# print()537# if __name__=='__main__':538# asd=get_str_rep(appointment_data)...
test_for_break.py
Source:test_for_break.py
1import numpy as np2import tensorflow as tf3import unittest4class TestForBreak(unittest.TestCase):5 def setUp(self):6 self.x = tf.ones([1])7 self.y = tf.ones([1]) * 28 def test_break(self):9 @tf.function10 def func(x):11 a = tf.constant(0)12 for i in range(4): # éè¦æ¿æ¢ä¸ºtf.range13 if a <= 2: # ä¸æ¯æpython forä¸å
å«æ§å¶æµçbreak/continue14 a = a + 115 continue16 else:17 x += 1018 break19 x = x + 120 return a21 22 out = func(self.x)23 print(out)24 """25 File "test_for_break.py", line 16, in func *26 for i in range(4):27 NotImplementedError: break and return statements which depend on a TF condition are not supported in Python for loops. Did you intend to make it a TF loop?28 See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/autograph/g3doc/reference/limitations.md#consistency-of-control-flow-types for more info.29 """30 31 print(tf.autograph.to_code(func.python_function))32 """33 def tf__func(x):34 with ag__.FunctionScope('func', 'fscope', ag__.ConversionOptions(recursive=True, user_requested=True, optional_features=(), internal_convert_user_code=True)) as fscope:35 do_return = False36 retval_ = ag__.UndefinedReturnValue()37 a = ag__.converted_call(ag__.ld(tf).constant, (0,), None, fscope)38 break_ = False39 def get_state_2():40 return (a, break_, x)41 def set_state_2(vars_):42 nonlocal a, x, break_43 (a, break_, x) = vars_44 def loop_body(itr):45 nonlocal a, x, break_46 i = itr47 continue_ = False48 (break_,)49 def get_state():50 return (a, break_, continue_, x)51 def set_state(vars_):52 nonlocal a, continue_, x, break_53 (a, break_, continue_, x) = vars_54 def if_body():55 nonlocal a, continue_, x, break_56 a = (ag__.ld(a) + 1)57 continue_ = True58 def else_body():59 nonlocal a, continue_, x, break_60 x = ag__.ld(x)61 x += 1062 break_ = True63 continue_ = True64 ag__.if_stmt((ag__.ld(a) <= 2), if_body, else_body, get_state, set_state, ('a', 'break_', 'continue_', 'x'), 4)65 def get_state_1():66 return (x,)67 def set_state_1(vars_):68 nonlocal x69 (x,) = vars_70 def if_body_1():71 nonlocal x72 x = (ag__.ld(x) + ag__.ld(i))73 def else_body_1():74 nonlocal x75 pass76 ag__.if_stmt(ag__.not_(continue_), if_body_1, else_body_1, get_state_1, set_state_1, ('x',), 1)77 def extra_test():78 nonlocal a, x, break_79 return ag__.not_(break_)80 i = ag__.Undefined('i')81 continue_ = ag__.Undefined('continue_')82 ag__.for_stmt(ag__.converted_call(ag__.ld(range), (4,), None, fscope), extra_test, loop_body, get_state_2, set_state_2, ('a', 'break_', 'x'), {'iterate_names': 'i'})83 try:84 do_return = True85 retval_ = ag__.ld(a)86 except:87 do_return = False88 raise89 return fscope.ret(retval_, do_return)90 """91 92class TestNestFor(unittest.TestCase):93 def setUp(self):94 self.x = tf.ones([1])95 self.y = tf.ones([1]) * 296 def test_break(self):97 @tf.function98 def func(x):99 s = 0100 for i in range(4): # éè¦æ¿æ¢ä¸ºtf.range101 x = x - 1102 for i in range(4):103 x = x - 10104 return s105 106 out = func(self.x)107 print(out)108 109 print(tf.autograph.to_code(func.python_function))110 111if __name__ == "__main__":...
test_break.py
Source:test_break.py
1import pytest2import vroom3def test_break_init():4 with pytest.raises(vroom._vroom.VroomInputException):5 vroom.Break(4)6 with pytest.raises(vroom._vroom.VroomInputException):7 vroom.Break(4, service=500)8 break_ = vroom.Break(vroom.Break(4, [(0, 1000)], 500, "hello"))9 assert break_.id == 410 assert break_.time_windows == [vroom.TimeWindow(0, 1000)]11 assert break_.service == 50012 assert break_.description == "hello"13def test_break_attributes():14 break_ = vroom.Break(4, [(0, 1000), (2000, 3000)])15 assert break_.is_valid_start(500)16 assert not break_.is_valid_start(1500)17 assert break_.is_valid_start(2500)18 break_.id = 719 assert break_.id == 720 break_.time_windows = [(1000, 2000)]21 assert break_.time_windows == [vroom.TimeWindow(1000, 2000)]22 break_.service = 923 assert break_.service == 924 break_.description = "goodbye"...
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!!