Best Python code snippet using grail_python
test_bdi_step_translator.py
Source:test_bdi_step_translator.py
...114 plan = self.generate_plan(drc.footstep_opts_t.BEHAVIOR_BDI_STEPPING)115 lc = lcm.LCM()116 lc.publish('CANDIDATE_FOOTSTEP_PLAN', plan.encode())117 translator = BDIStepTranslator()118 def handle_steps(channel, msg_data):119 msg = atlas.behavior_step_params_t.decode(msg_data)120 self.assertAlmostEqual(msg.desired_step_spec.foot.position[0], 0.04)121 self.assertAlmostEqual(msg.desired_step_spec.foot.position[1], 0)122 self.assertAlmostEqual(msg.desired_step_spec.foot.position[2], 0)123 self.assertAlmostEqual(msg.desired_step_spec.foot.normal[0], 0)124 self.assertAlmostEqual(msg.desired_step_spec.foot.normal[1], 0)125 self.assertAlmostEqual(msg.desired_step_spec.foot.normal[2], 1)126 self.assertEqual(msg.use_spec, True)127 lc.subscribe('ATLAS_STEP_PARAMS', handle_steps)128 translator.handle_footstep_plan('COMMITTED_FOOTSTEP_PLAN', plan.encode())129 lc.handle()130 # import pdb; pdb.set_trace()131 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[0], 0.04)132 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[1], 0)133 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[2], 0)134 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.normal[0], 0)135 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.normal[1], 0)136 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.normal[2], 1)137 self.assertEqual(translator.use_spec, True)138 plotter = BDIStepTranslator(mode=Mode.plotting)139 plotter.handle_footstep_plan('CANDIDATE_FOOTSTEP_PLAN', plan.encode())140 def test_walking(self):141 plan = self.generate_plan(drc.footstep_opts_t.BEHAVIOR_BDI_WALKING)142 lc = lcm.LCM()143 lc.publish('CANDIDATE_FOOTSTEP_PLAN', plan.encode())144 translator = BDIStepTranslator()145 def handle_steps(channel, msg_data):146 msg = atlas.behavior_walk_params_t.decode(msg_data)147 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.position[0], 0.04)148 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.position[1], 0)149 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.position[2], 0)150 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.normal[0], 0)151 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.normal[1], 0)152 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.normal[2], 1)153 self.assertEqual(msg.use_spec, True)154 lc.subscribe('ATLAS_WALK_PARAMS', handle_steps)155 translator.handle_footstep_plan('COMMITTED_FOOTSTEP_PLAN', plan.encode())156 lc.handle()157 plotter = BDIStepTranslator(mode=Mode.plotting)158 plotter.handle_footstep_plan('CANDIDATE_FOOTSTEP_PLAN', plan.encode())159 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[0], 0.04)160 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[1], 0)161 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[2], 0)162 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.normal[0], 0)163 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.normal[1], 0)164 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.normal[2], 1)165 self.assertEqual(translator.use_spec, True)166 def test_stop_walking(self):167 plan = self.generate_plan(drc.footstep_opts_t.BEHAVIOR_BDI_STEPPING)168 translator = BDIStepTranslator()169 translator.handle_footstep_plan('COMMITTED_FOOTSTEP_PLAN', plan.encode())170 def handle_steps(channel, msg_data):171 msg = atlas.behavior_step_params_t.decode(msg_data)172 self.assertEqual(msg.desired_step_spec.step_index, -1)173 lc = lcm.LCM()174 lc.subscribe('ATLAS_STEP_PARAMS', handle_steps)175 translator.handle_stop_walking('STOP_WALKING', None)176 lc.handle()177 def test_stop_walking_no_queue(self):178 translator = BDIStepTranslator()179 def handle_steps(channel, msg_data):180 msg = atlas.behavior_step_params_t.decode(msg_data)181 self.assertEqual(msg.desired_step_spec.step_index, -1)182 lc = lcm.LCM()183 lc.subscribe('ATLAS_STEP_PARAMS', handle_steps)184 translator.handle_stop_walking('STOP_WALKING', None)185 lc.handle()186 def test_atlas_status(self):187 plan = self.generate_plan(drc.footstep_opts_t.BEHAVIOR_BDI_STEPPING)188 lc = lcm.LCM()189 lc.publish('CANDIDATE_FOOTSTEP_PLAN', plan.encode())190 translator = BDIStepTranslator()191 translator.handle_footstep_plan('COMMITTED_FOOTSTEP_PLAN', plan.encode())192 self.assertEqual(translator.delivered_index, 1)193 status = atlas.status_t()194 status.step_feedback = atlas.step_feedback_t()195 status.step_feedback.next_step_index_needed = 2196 translator.executing = True197 translator.handle_atlas_status('ATLAS_STATUS', status)198 translator.executing = False199 self.assertEqual(translator.delivered_index, 2)200 def test_terrain_clearance(self):201 plan = self.generate_plan(drc.footstep_opts_t.BEHAVIOR_BDI_STEPPING)202 translator = BDIStepTranslator()203 def handle_steps(channel, msg_data):204 msg = atlas.behavior_step_params_t.decode(msg_data)205 self.assertAlmostEqual(msg.desired_step_spec.action.lift_height, plan.footsteps[2].params.bdi_lift_height + plan.footsteps[2].terrain_height[1])206 lc = lcm.LCM()207 lc.subscribe('ATLAS_STEP_PARAMS', handle_steps)208 translator.handle_footstep_plan('COMMITTED_FOOTSTEP_PLAN', plan.encode())209 lc.handle()210 def test_deprecated_stepping(self):211 plan = self.generate_deprecated_plan(drc.footstep_opts_t.BEHAVIOR_BDI_STEPPING)212 lc = lcm.LCM()213 lc.publish('CANDIDATE_FOOTSTEP_PLAN', plan.encode())214 translator = BDIStepTranslator()215 def handle_steps(channel, msg_data):216 msg = atlas.behavior_step_params_t.decode(msg_data)217 self.assertAlmostEqual(msg.desired_step_spec.foot.position[0], 0.04)218 self.assertAlmostEqual(msg.desired_step_spec.foot.position[1], 0)219 self.assertAlmostEqual(msg.desired_step_spec.foot.position[2], 0)220 self.assertAlmostEqual(msg.desired_step_spec.foot.normal[0], 0)221 self.assertAlmostEqual(msg.desired_step_spec.foot.normal[1], 0)222 self.assertAlmostEqual(msg.desired_step_spec.foot.normal[2], 1)223 self.assertEqual(msg.use_spec, True)224 lc.subscribe('ATLAS_STEP_PARAMS', handle_steps)225 translator.handle_footstep_plan('COMMITTED_FOOTSTEP_PLAN', plan.encode())226 lc.handle()227 # import pdb; pdb.set_trace()228 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[0], 0.04)229 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[1], 0)230 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[2], 0)231 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.normal[0], 0)232 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.normal[1], 0)233 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.normal[2], 1)234 self.assertEqual(translator.use_spec, True)235 plotter = BDIStepTranslator(mode=Mode.plotting)236 plotter.handle_footstep_plan('CANDIDATE_FOOTSTEP_PLAN', plan.encode())237 def test_deprecated_walking(self):238 plan = self.generate_deprecated_plan(drc.footstep_opts_t.BEHAVIOR_BDI_WALKING)239 lc = lcm.LCM()240 lc.publish('CANDIDATE_FOOTSTEP_PLAN', plan.encode())241 translator = BDIStepTranslator()242 def handle_steps(channel, msg_data):243 msg = atlas.behavior_walk_params_t.decode(msg_data)244 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.position[0], 0.04)245 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.position[1], 0)246 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.position[2], 0)247 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.normal[0], 0)248 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.normal[1], 0)249 self.assertAlmostEqual(msg.walk_spec_queue[0].foot.normal[2], 1)250 self.assertEqual(msg.use_spec, True)251 lc.subscribe('ATLAS_WALK_PARAMS', handle_steps)252 translator.handle_footstep_plan('COMMITTED_FOOTSTEP_PLAN', plan.encode())253 lc.handle()254 plotter = BDIStepTranslator(mode=Mode.plotting)255 plotter.handle_footstep_plan('CANDIDATE_FOOTSTEP_PLAN', plan.encode())256 self.assertAlmostEqual(translator.bdi_step_queue_out[0].foot.position[0], 0.04)...
binance_test.py
Source:binance_test.py
...41 print("an exception occured - {}".format(e))42 print('error : ',quantity)43 return False44 return True45def handle_steps(side='BUY',bidask_price=1,min_trade_qty=0.000001,step=0,46 target_asset='BTC',base_asset='USDT',pair='BTCUSDT'):47 base_qty = float(client.get_asset_balance(base_asset)['free'])48 print('Step {}:Converting {} to {}'.format(step,base_asset,target_asset))49 print("Available {}: ".format(base_asset), base_qty)50 if side == "BUY":51 # bidask_price = lowest ask price52 if min_trade_qty == 1:53 tgt_qty = int(math.floor(float(base_qty/bidask_price)*0.95))54 print('Symbol Ask = ', bidask_price)55 else:56 x = float(base_qty/bidask_price)*0.9557 y = min_trade_qty58 tgt_qty = utils.floor_rounding(x,y,max_rounding=8)59 print('Symbol Ask = ', bidask_price)60 else:61 # Sell testcase62 # bidask_price = bid_price63 if min_trade_qty == 1:64 tgt_qty = base_qty - base_qty%165 print('Symbol Ask = ', bidask_price)66 else:67 x = base_qty68 y = min_trade_qty69 tgt_qty = utils.floor_rounding(x,y,max_rounding=8)70 print('Symbol Ask = ', bidask_price)71 f = order(side, tgt_qty, pair)72 print('Conversion Successful' if f==True else 'Conversion Failed')73 print()74try:75 while True:76 snap = client.get_orderbook_tickers()77 # print(snap)78 tmp = {}79 for i in snap:80 tmp[i['symbol']] = i81 # print(tmp)82 # print('Data processed')83 for i in range(len(usdt_symbols)):84 for j in range(len(symbols)):85 if 'USDT' in symbols[j]:86 continue87 try:88 first_usdt_ask = float(tmp[usdt_symbols[i]]['askPrice'])89 s = usdt_symbols[i][:-len('USDT')]90 if is_suffix(s,symbols[j]):91 symbol_ask = float(tmp[symbols[j]]['askPrice'])92 # print('1 ------> ',first_usdt_ask)93 # print('2 ------> ',symbol_bid)94 p = symbols[j][:-len(s)]95 second_usdt_bid = float(tmp[p+'USDT']['bidPrice'])96 # print('3 ------> ',second_usdt_bid)97 profit = ((((1/first_usdt_ask)/symbol_ask)*second_usdt_bid)-1)*10098 profit = profit99 # print(profit)100 # print(usdt_symbols[i], '->', symbols[j], '->', p + 'USDT')101 # print('q1 = ',q1,'q2 = ',q2,'q3 = ',q3)102 if profit>0.1:103 # Step 1104 handle_steps(side='BUY', bidask_price=first_usdt_ask,min_trade_qty=0.000001,step=1,105 target_asset=usdt_symbols[i].split('USDT')[0],106 base_asset='USDT',pair=usdt_symbols[i])107 # Step 2108 handle_steps(side='BUY',bidask_price=symbol_ask,min_trade_qty=min_trade_qty[symbols[j]],step=2,109 target_asset=symbols[j].split(s)[0],110 base_asset=s,pair=symbols[j])111 # Step 3112 handle_steps(side='SELL',min_trade_qty=min_trade_qty[p+'USDT'],113 step=3,target_asset='USDT',114 base_asset=p,pair=p+'USDT')115 print(usdt_symbols[i],'->',symbols[j],'->',p+'USDT','profit =',profit)116 tmp1 = float(client.get_asset_balance('USDT')['free'])117 print('Available USDT: ', tmp1, usdt_symbols[i])118 print()119 print()120 print()121 else:122 # print('pofit problem')123 continue124 # symbol_bid = tmp[j]['bidPrice']125 # p = j[:-len(s)]126 # second_usdt_bid = tmp[p+'USDT']['askPrice']...
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!!