Best Python code snippet using tempest_python
water.py
Source:water.py
1# water.py2import math3import pickle4import gazebo_getpos5import hierarchical6import utils7from envs import hsr8# Think about what model for each skill.9DEBUG = False10PRETRAINED = True11V = 0.0712OMEGA = math.pi / 5.13STATION_POSITION = [0.75, -2]14FAKE_WATER_LEVEL = 215ARM_STAND_BY = [0, -0.6, -1.57, -1.57, 0.6]16""" Upper Level Skills"""17@hierarchical.Skill18def ServeTables(consta):19 """20 arg: [consta]21 ret_val:22 """23 MoveGripper(1.57)24 MoveArm(0, -0, -1.57, -1.57, 1.02)25 ServeTable()26@hierarchy.Skill27def ServeTable():28 """29 arg: None30 ret_val: region_list31 """32 region_list = [0] * 1633 region_list = InspectTable()34 region_list = GoStandBy(region_list)35 region_list = FillCups(region_list)36 FillCups(region_list)37@hierarchy.Skill38def GoStandBy(region_list)39 """40 arg: region_list41 ret_val: region_list42 """43 region_list[0:8] = [1] + [0] * 744 hsr.MoveBaseAbs(0, -1.2, 1.57, V, OMEGA)45 hsr.MoveBaseAbs(0.375, -1.2, 1.57, V, OMEGA)46 return region_list47#not really sure48@hierarchy.Skill49def InspectTable():50 """51 arg:52 ret_val: region_list from LookAtTable, Move_succeed from GoToTable53 """54 region_list = [0] * 1655 motion_cnt = 156 motion_cnt, region_list = GoToTable(motion_cnt, region_list)57 motion_cnt, region_list = LookAtTable(motion_cnt, region_list)58 motion_cnt += 159 motino_cnt, region_list = GoToTable(motion_cnt, region_list)60 return region_list61#not really sure62@hierarchy.Skill63def FillCups(region_list):64 """65 arg:region list66 ret_val:67 """68 region_list = ReturnRegionList(region_list)69 while(sum(region_listp[8:16])!=0):70 region_list = FillCupsWrapper(region_list)71 region_list = FillCup(region_list) ###not sure the return value72 region_list = ScanTable(region_list)73@hierarchy.Skill74def FillCupsWrapper(region_list):75 """76 arg: region_list77 ret_val:78 """79 #region_list = arg[0:16]80 water_level, is_refilled = EnsureWaterAmount(region_list[0:8])81 destin_region, water_level, is_refilled = SelectNextRegionWrapper(region_list, water_level, is_refilled)82 curr_region = region_list[0:8]83 #changes: in original file, return value has to arguments and comment shows only one of them84 water_level, destin_region = MoveNextRegion(curr_region, destin_region, water_level, is_refilled)85 region_list[0:8] = destin_region86 return region_list, water_level87@hierarchy.Skill88def SelectNextRegionWrapper(region_list, water_level, is_refilled)89 """90 arg: region_list = arg (current region: arg[0:8], region cup number: arg[8:16], [water_level, is_refilled])91 ret_val: destination region in one hot representation92 """93 curr_region = region_list[0:8]94 region_cup_num = region_list[8:16]95 #for here, the function passed in 4 arguments, water_level and is_refilled is missing96 destin_region = SelectNextRegion(curr_region, region_cup_num)97 return destin_region, water_level, is_refilled98@hierarchy.Skill99def SelectNextRegion(curr_region, region_cup_num):100 """101 arg: region_list = arg (current region: arg[0:8], region cup number: arg[8:16], [water_level, is_refilled])102 ret_val: destination region in one hot representation103 """104 update_region = CheckRegion(curr_region, region_cup_num)105 check, update_region = CheckRegion(update_region, region_cup_num)106 while(not check):107 update_region = ShiftRegion(update_region)108 check, update_region = CheckRegion(update_region, region_cup_num)109 return update_region110@hierarchy.Skill111def ShiftRegion(prev_region):112 """113 arg: previous region: arg[0:8]114 ret_val: selected region in one hot representation115 """116 index = sum([i*prev_region[i] for i in range(8)])117 prev_region[index] = 0118 prev_region[(index+1)%8] = 1119 return prev_region120@hierarchy.Skill121def CheckRegion(sele_region, region_cup_num)122 """123 arg: region_list = arg, current region: arg[0:8], region cup number: arg[8:16]124 ret_val: destination region in one hot representation125 """126 index = sum([i*sele_region[i] for i in range(8)])127 return region_cup_num[index], sele_region128@hierarchy.Skill129def MoveNextRegion(curr_region, destin_region, water_level, is_refilled):130 """131 arg: [curr_region, destin_region, water_level, is_refilled]132 ret_val: [water_level]133 """...
Spectra.py
Source:Spectra.py
...19 liveTraceROI = self.addPlot(title="ROI", row=0, col=1, colspan=2)20 liveTraceROI.plot(x2,data2)21 def update_plot():22 liveTraceROI.setXRange(*lr.getRegion(), padding=0)23 def update_region():24 lr.setRegion(liveTraceROI.getViewBox().viewRange()[0])25 lr.sigRegionChanged.connect(update_plot)26 liveTraceROI.sigXRangeChanged.connect(update_region)27 update_plot()28 self.nextRow()29 # HISTORY30 historyTrace = self.addPlot(title="History (ROI)")31 for i in range(1,5,1):32 historyTrace.plot(x2,data2+0.1*i)33 def update_plot():34 historyTrace.setXRange(*lr.getRegion(), padding=0)35 def update_region():36 lr.setRegion(liveTraceROI.getViewBox().viewRange()[0])37 lr.sigRegionChanged.connect(update_plot)38 historyTrace.sigXRangeChanged.connect(update_region)39 update_plot()40 # HISTOGRAMS of peak positions and intensities in ROI41 vals = np.hstack([np.random.normal(size=500), np.random.normal(size=260, loc=600)])42 y, x = np.histogram(vals, bins=np.linspace(-3, 8, 40))43 # HISTOGRAM PEAK POSITION44 histogramPosTrace = self.addPlot(title="Peak position")45 histogramPosTrace.plot(x, y, stepMode=True, fillLevel=0, brush=(0,0,255,100))46 def update_plot():47 y, x = np.histogram(vals, bins=np.linspace(lr.getRegion()[0], lr.getRegion()[1], 40))48 histogramPosTrace.plot(x, y, stepMode=True, fillLevel=0, brush=(0,0,255,100))49 def update_region():50 lr.setRegion(liveTraceROI.getViewBox().viewRange()[0])51 lr.sigRegionChanged.connect(update_plot)52 histogramPosTrace.sigXRangeChanged.connect(update_region)53 update_plot()54 # HISTOGRAM PEAK INTENSITY55 histogramIntTrace = self.addPlot(title="Peak intensity")56 histogramIntTrace.plot(x, y, stepMode=True, fillLevel=0, brush=(0,0,255,100))57 def update_plot():58 y, x = np.histogram(vals, bins=np.linspace(lr.getRegion()[0], lr.getRegion()[1], 40))59 histogramIntTrace.plot(x, y, stepMode=True, fillLevel=0, brush=(0,0,255,100))60 def update_region():61 lr.setRegion(liveTraceROI.getViewBox().viewRange()[0])62 lr.sigRegionChanged.connect(update_plot)63 histogramIntTrace.sigXRangeChanged.connect(update_region)...
test_fixture1.py
Source:test_fixture1.py
1import pytest2import pandas as pd3def update_region(row):4 5 if row['State_Code'] == 2:6 row['EZT_Region_Key'] = 607 row['Region_Name'] = 'USDA - West'8 if row['State_Code'] == 33:9 row['EZT_Region_Key'] = 5710 row['Region_Name'] = 'USDA - Northeast'11 if row['State_Code'] == 35:12 row['EZT_Region_Key'] = 6013 row['Region_Name'] = 'USDA - West'14 if row['State_Code'] == 44:15 row['EZT_Region_Key'] = 5716 row['Region_Name'] = 'USDA - Northeast'17 if row['State_Code'] == 50:18 row['EZT_Region_Key'] = 5719 row['Region_Name'] = 'USDA - Northeast'20 if row['State_Code'] == 60:21 row['EZT_Region_Key'] = 9922 row['Region_Name'] = 'Other'23 if row['State_Code'] == 66:24 row['EZT_Region_Key'] = 9925 row['Region_Name'] = 'Other'26 if row['State_Code'] == 69:27 row['EZT_Region_Key'] = 9928 row['Region_Name'] = 'Other'29 if row['State_Code'] == 72:30 row['EZT_Region_Key'] = 9931 row['Region_Name'] = 'Other'32 if row['State_Code'] == 78:33 row['EZT_Region_Key'] = 9934 row['Region_Name'] = 'Other' 35 36 return row37def test_method1(update_region):38 x = 1739 assert update_region(0) == x40def test_method2(update_region):41 y = 'test_string'42 assert update_region('test') == y43test_method2(update_region)44d = {'State_Code': [44, 12], 'EZT_Region_Key': [66, 67], 'Region_Name': ['testa', 'testb']}45df = pd.DataFrame(data=d)46df.apply(update_region, axis=1)47def test_method3(update_region):48 y = 'test_string'49 assert update_region(df) == 12...
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!!