Best Python code snippet using Airtest
indata_outdata.py
Source:indata_outdata.py
...379 print "socket error happened:", msg380 sys.exit(1)381def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):382 return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)383def add_idx(idx, value):384 global idxes385 global target_vals386 idxes.append(idx)387 target_vals.append(value)388def add_idx_only(idx):389 global idxes390 idxes.append(idx)391def test():392 global idxes393 global target_vals394 FLOAT_MAX = 3.402823e+38395 FLOAT_MIN = -3.402823e38396 397 print "1st, test the maximum values"398 idxes = []399 target_vals = []400 target_val = FLOAT_MAX401 send_value(IN_Top_temp, target_val)402 time.sleep(0.5)403 send_value(IN_Btm_temp, target_val)404 time.sleep(0.5)405 send_value(IN_LV_Current, target_val)406 time.sleep(0.5)407 send_value(IN_Shadow_temp, target_val)408 time.sleep(0.5)409 send_value(IN_Sun_temp, target_val)410 time.sleep(0.5)411 send_value(IN_H2ppm, target_val)412 time.sleep(0.5)413 send_value(IN_H2Oppm, target_val)414 time.sleep(0.5)415 send_value(IN_OLTC_H2Oppm, target_val)416 time.sleep(0.5)417 send_value(IN_OLTC1_temp_high, target_val)418 time.sleep(0.5)419 send_value(IN_OLTC_pos, target_val)420 time.sleep(0.5)421 send_value(IN_Voltage, target_val)422 time.sleep(0.5)423 send_value(IN_Extra1, target_val)424 time.sleep(0.5)425 send_value(IN_C2H2ppm, target_val)426 time.sleep(0.5)427 send_value(IN_COppm, target_val)428 time.sleep(0.5)429 send_value(IN_CO2ppm, target_val)430 time.sleep(0.5)431 send_value(IN_C2H4ppm, target_val)432 time.sleep(0.5)433 send_value(IN_C2H6ppm, target_val)434 time.sleep(0.5)435 send_value(IN_CH4ppm, target_val)436 time.sleep(0.5)437 send_value(IN_O2ppm, target_val)438 time.sleep(0.5)439 send_value(IN_TDCGppm, target_val)440 time.sleep(0.5)441 send_value(IN_N2ppm, target_val)442 time.sleep(0.5)443 send_value(IN_TDGppm, target_val)444 time.sleep(0.5)445 send_value(IN_Cooler1_Current_high, target_val)446 add_idx(OUT_Top_temp, target_val)447 add_idx(OUT_Btm_temp, target_val)448 add_idx(OUT_LV_Current, target_val)449 add_idx(OUT_Shadow_temp, target_val)450 add_idx(OUT_Sun_temp, target_val)451 add_idx(OUT_H2ppm, target_val)452 add_idx(OUT_H2Oppm, target_val)453 add_idx(OUT_OLTC_H2Oppm, target_val)454 add_idx(OUT_OLTC1_temp, target_val)455 add_idx(OUT_OLTC_pos, target_val)456 add_idx(OUT_Voltage, target_val)457 add_idx(OUT_Extra1, target_val)458 add_idx(OUT_C2H2ppm, target_val)459 add_idx(OUT_COppm, target_val)460 add_idx(OUT_CO2ppm, target_val)461 add_idx(OUT_C2H4ppm, target_val)462 add_idx(OUT_C2H6ppm, target_val)463 add_idx(OUT_CH4ppm, target_val)464 add_idx(OUT_O2ppm, target_val)465 add_idx(OUT_TDCGppm, target_val)466 add_idx(OUT_N2ppm, target_val)467 add_idx(OUT_TDGppm, target_val)468 add_idx(OUT_Cooler1_Current, target_val)469 receive_value(idxes, target_vals)470 idxes = []471 add_idx_only(OUT_HV_Current)472 add_idx_only(OUT_TTB_Top_temp)473 add_idx_only(OUT_TTB_Btm_temp)474 #add_idx_only(OUT_H2ppm1)475 add_idx_only(OUT_H2ppm2)476 add_idx_only(OUT_H2ppm3)477 add_idx_only(OUT_TTB_OLTC1_temp)478 add_idx_only(OUT_HV_HotSpot)479 add_idx_only(OUT_LV_HotSpot)480 #add_idx_only(OUT_Bubbling_temp)481 '''482 add_idx_only(OUT_H2Oppm1)483 add_idx_only(OUT_H2Oppm2)484 add_idx_only(OUT_H2Oppm3)485 add_idx_only(OUT_C2H2ppm1)486 add_idx_only(OUT_C2H2ppm2)487 add_idx_only(OUT_C2H2ppm3)488 add_idx_only(OUT_COppm1)489 add_idx_only(OUT_COppm2)490 add_idx_only(OUT_COppm3)491 add_idx_only(OUT_CO2ppm1)492 add_idx_only(OUT_CO2ppm2)493 add_idx_only(OUT_CO2ppm3)494 add_idx_only(OUT_C2H4ppm1)495 add_idx_only(OUT_C2H4ppm2)496 add_idx_only(OUT_C2H4ppm3)497 add_idx_only(OUT_C2H6ppm1)498 add_idx_only(OUT_C2H6ppm2)499 add_idx_only(OUT_C2H6ppm3)500 add_idx_only(OUT_CH4ppm1)501 add_idx_only(OUT_CH4ppm2)502 add_idx_only(OUT_CH4ppm3)503 add_idx_only(OUT_O2ppm1)504 add_idx_only(OUT_O2ppm2)505 add_idx_only(OUT_O2ppm3)506 add_idx_only(OUT_TDCGppm1)507 add_idx_only(OUT_TDCGppm2)508 add_idx_only(OUT_TDCGppm3)509 add_idx_only(OUT_N2ppm1)510 add_idx_only(OUT_N2ppm2)511 add_idx_only(OUT_N2ppm3)512 add_idx_only(OUT_TDGppm1)513 add_idx_only(OUT_TDGppm2)514 add_idx_only(OUT_TDGppm3)515 '''516 add_idx_only(OUT_Ageing)517 add_idx_only(OUT_Ageing1)518 add_idx_only(OUT_Ageing2)519 #add_idx_only(OUT_Load)520 add_idx_only(OUT_Load1)521 #add_idx_only(OUT_Overload)522 add_idx_only(OUT_Overload1)523 add_idx_only(OUT_Overload2)524 add_idx_only(OUT_Overload3)525 add_idx_only(OUT_Overload4)526 527 receive_calculates(idxes)528 529 print "2nd, test the minimum values"530 idxes = []531 target_vals = []532 target_val = FLOAT_MIN533 send_value(IN_Top_temp, target_val)534 time.sleep(0.5)535 send_value(IN_Btm_temp, target_val)536 time.sleep(0.5)537 send_value(IN_LV_Current, target_val)538 time.sleep(0.5)539 send_value(IN_Shadow_temp, target_val)540 time.sleep(0.5)541 send_value(IN_Sun_temp, target_val)542 time.sleep(0.5)543 send_value(IN_H2ppm, target_val)544 time.sleep(0.5)545 send_value(IN_H2Oppm, target_val)546 time.sleep(0.5)547 send_value(IN_OLTC_H2Oppm, target_val)548 time.sleep(0.5)549 send_value(IN_OLTC1_temp_high, target_val)550 time.sleep(0.5)551 send_value(IN_OLTC_pos, target_val)552 time.sleep(0.5)553 send_value(IN_Voltage, target_val)554 time.sleep(0.5)555 send_value(IN_Extra1, target_val)556 time.sleep(0.5)557 send_value(IN_C2H2ppm, target_val)558 time.sleep(0.5)559 send_value(IN_COppm, target_val)560 time.sleep(0.5)561 send_value(IN_CO2ppm, target_val)562 time.sleep(0.5)563 send_value(IN_C2H4ppm, target_val)564 time.sleep(0.5)565 send_value(IN_C2H6ppm, target_val)566 time.sleep(0.5)567 send_value(IN_CH4ppm, target_val)568 time.sleep(0.5)569 send_value(IN_O2ppm, target_val)570 time.sleep(0.5)571 send_value(IN_TDCGppm, target_val)572 time.sleep(0.5)573 send_value(IN_N2ppm, target_val)574 time.sleep(0.5)575 send_value(IN_TDGppm, target_val)576 time.sleep(0.5)577 send_value(IN_Cooler1_Current_high, target_val)578 add_idx(OUT_Top_temp, target_val)579 add_idx(OUT_Btm_temp, target_val)580 add_idx(OUT_LV_Current, target_val)581 add_idx(OUT_Shadow_temp, target_val)582 add_idx(OUT_Sun_temp, target_val)583 add_idx(OUT_H2ppm, target_val)584 add_idx(OUT_H2Oppm, target_val)585 add_idx(OUT_OLTC_H2Oppm, target_val)586 add_idx(OUT_OLTC1_temp, target_val)587 add_idx(OUT_OLTC_pos, target_val)588 add_idx(OUT_Voltage, target_val)589 add_idx(OUT_Extra1, target_val)590 add_idx(OUT_C2H2ppm, target_val)591 add_idx(OUT_COppm, target_val)592 add_idx(OUT_CO2ppm, target_val)593 add_idx(OUT_C2H4ppm, target_val)594 add_idx(OUT_C2H6ppm, target_val)595 add_idx(OUT_CH4ppm, target_val)596 add_idx(OUT_O2ppm, target_val)597 add_idx(OUT_TDCGppm, target_val)598 add_idx(OUT_N2ppm, target_val)599 add_idx(OUT_TDGppm, target_val)600 add_idx(OUT_Cooler1_Current, target_val)601 receive_value(idxes, target_vals)602 idxes = []603 add_idx_only(OUT_HV_Current)604 add_idx_only(OUT_TTB_Top_temp)605 add_idx_only(OUT_TTB_Btm_temp)606 #add_idx_only(OUT_H2ppm1)607 add_idx_only(OUT_H2ppm2)608 add_idx_only(OUT_H2ppm3)609 add_idx_only(OUT_TTB_OLTC1_temp)610 add_idx_only(OUT_HV_HotSpot)611 add_idx_only(OUT_LV_HotSpot)612 add_idx_only(OUT_Ageing)613 add_idx_only(OUT_Ageing1)614 add_idx_only(OUT_Ageing2)...
mds_strings.py
Source:mds_strings.py
1# -*- coding: utf-8 -*-2"""3Created on Tue Dec 1 23:22:39 202045@author: lina_6"""7import copy89def ordered_insertion(initial, additional, **kwargs):10 """ 11 Inserts additional characters (alpha), in order,12 around the initial (num) ones to generate all possible ordered13 insertions. 14 Parameters15 ----------16 initial : int17 Number of initial characters (a list).18 additional : int19 Number of characters to insert (b list).20 kwargs : 21 a_start : boolean22 If True, all sequences will start with either 'a' or '(ab)'23 idx : boolean24 If True, all symbols will have subindices (i.e. 'a_m', 'b_n') 25 assigned in order26 Returns27 -------28 List of all the possible ordered insertions of additional letters29 to initial integers.30 """31 kwargs.setdefault('a_start',False)32 if 'a_start' in kwargs:33 a_start = kwargs['a_start']34 kwargs.setdefault('add_idx', False)35 if 'add_idx' in kwargs:36 add_idx = kwargs['add_idx']37 38 a_list = list()39 40 if not a_start:41 a_list.append([]) # ignore if always starting with a42 43 # Initializes the big list44 for i in range(1,initial+1):45 if add_idx:46 extra = '_' + str(i)47 else:48 extra = ''49 a_list.append(['a' + extra])50 a_list.append([])51 52 b_list = []53 for i in range(1,additional+1):54 if add_idx:55 extra = '_' + str(i)56 else:57 extra = ''58 b_list.append('b' + extra)59 60 depth = 061 position = 062 63 prelim = recursive_insertion(a_list, additional, position, depth, b_list, a_start)64 65 ret = list()66 for p in prelim:67 st = []68 for i in range(len(p)):69 st +=p[i]70 ret.append(''.join(st))71 return ret 72 73def recursive_insertion(a_list, additional, position, depth, b_list, a_start):74 """75 Inserts letters into the big list in allowed positions7677 Parameters78 ----------79 a_list : list80 List of lists. Lists with integers correspond to points, the 81 others to intervals.82 additional : int83 How many characters need to be inserted.84 position : int85 What position to place characters in.86 depth : int87 When it matches 'additional-1' the sequence is complete.88 letters : list89 List of letters to be added.90 a_start : boolean91 True if the word should start with a9293 Returns94 -------95 cleanup(ret) : list96 Cleaned up list of all the lists of possible order preserving 97 insertions.9899 """100 ret = list()101 for i in range(position, len(a_list)):102 tmp = copy.deepcopy(a_list)103 104 if len(tmp[i]) == 0 or 'b' in tmp[i][0]:105 tmp[i].append(b_list[depth])106 elif len(tmp[i]) == 1 and 'a' in tmp[i][0]:107 tmp[i] = '(' + tmp[i].pop() + b_list[depth] + ')'108 else:109 continue110 if depth == additional - 1:111 ret.append(tmp)112 else:113 ret = ret+recursive_insertion(tmp, additional, i, depth+1, b_list, a_start)
...
502_ipo.py
Source:502_ipo.py
1class Solution:2 def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:3 pro_cap = sorted(zip(profits, capital), key=lambda x:x[1])4 heap = []5 add_idx = 06 7 for _ in range(k):8 while add_idx<len(profits) and w>=pro_cap[add_idx][1]:9 heapq.heappush(heap, -pro_cap[add_idx][0]). # max heap10 add_idx += 111 12 if not heap: return w13 w -= heapq.heappop(heap)...
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!!