How to use _analyse method in Airtest

Best Python code snippet using Airtest

semantic_analyser_test.py

Source:semantic_analyser_test.py Github

copy

Full Screen

...85 'void y() { x = 4;}}')8687 def test_param_pass(self):88 """Test parameters can be used within the method body."""89 self._analyse('class X { void x(int y) {int x = y;}}')9091 def test_param_fail(self):92 """Test parameters of one method are not accessible elsewhere."""93 self.assertRaises(SymbolNotFoundError, self._analyse,94 'class x { void x(int y) {} void z(){int w = y;}}')9596 def test_super_cons_params_no_cons_fail(self):97 """Test that an error is thrown when a class does not have98 a constructor, when the super class has a constructor that99 takes parameters.100 """101 self.assertRaises(ConstructorError, self.analyse_file,102 'test_super_cons_params_no_cons_fail.jml')103104 def test_super_cons_params_no_params(self):105 """Test that an error is thrown when the super class has a constructor106 which takes parameters, and the sub class has a constructor, but it107 does not call the super classes constructor.108 """109 self.assertRaises(ConstructorError, self.analyse_file,110 'test_super_cons_params_no_params.jml')111112 def test_multi_constructors_fail(self):113 """Test an error is thrown when a class contains multiple constructors.114 """115 self.assertRaises(ConstructorError, self._analyse,116 'class X { X() {} X() {} }')117118 def test_method_call_pass(self):119 """Test that there is no error when a call is made to another method120 within the same class.121 """122 self._analyse('class X {void x() {y();} void y(){} }')123124 def test_method_call_fail(self):125 """Test an error is thrown when a method is called which doesn't exist.126 """127 self.assertRaises(SymbolNotFoundError, self._analyse,128 'class X {void x() {z();} void y(){} }')129130 def test_method_call_args_pass(self):131 """Test that there is no error when the arguments match the method132 signature.133 """134 self._analyse('class X {void x() {long w = 5; y(w + 5);} ' +135 'void y(long z){} }')136137 def test_method_call_args_length_fail(self):138 """Test an error is thrown when a method is called where no arguments139 are provided when there should be one.140 """141 self.assertRaises(MethodSignatureError, self._analyse,142 'class X {void x() {y();} void y(long z){} }')143144 def test_method_call_args_wrong_type_fail(self):145 """Test an error is thrown when a method is called where the arguments146 are of the incorrect type.147 """148 self.assertRaises(TypeError, self._analyse,149 'class X {void x() {boolean w = true; ' +150 'y(w);} void y(long z){} }')151152 def test_method_return_pass(self):153 """Test that no error is raised when the correct type is returned."""154 self._analyse('class X {short x(){return 6;}}')155156 def test_method_no_return_fail(self):157 """Test that an error is raised when a method does not return anything158 when it's signature states it should.159 """160 self.assertRaises(NoReturnError, self._analyse,161 'class X {short x(){}}')162163 def test_method_wrong_return_fail(self):164 """Test that an error is raised when a method returns an incorrect165 type.166 """167 self.assertRaises(TypeError, self._analyse,168 'class X {short x(){return true;}}')169170 def test_method_return_array_pass(self):171 """Test no error raised when a method returns an array"""172 self._analyse('class X {byte[][] x(){return new byte[5][5];}}')173174 def test_method_return_array_fail(self):175 """Test error raised when array is not returned"""176 self.assertRaises(TypeError, self._analyse,177 'class X {int[] x(){return 1;}}')178179 def test_method_call_external_pass(self):180 """Test no error thrown when a method is called from an object of181 another class."""182 self.analyse_file('test_method_call_external_pass.jml')183184 def test_method_call_external_not_exists_fail(self):185 """Test that an error is raised when a method is called in another186 class which doesn't exist."""187 self.assertRaises(SymbolNotFoundError, self.analyse_file,188 'test_method_call_external_not_exists_fail.jml')189190 def test_method_call_external_wrong_type_fail(self):191 """Test that an error is raised when a method is called in another192 class which returns an incompatible type with what the result is being193 assigned to."""194 self.assertRaises(TypeError, self.analyse_file,195 'test_method_call_external_wrong_type_fail.jml')196197 def test_method_call_super_pass(self):198 """Test no error thrown when a method is invoked that is defined in a199 super class.200 """201 self.analyse_file('test_method_call_super_pass.jml')202203 def test_method_override_final_fail(self):204 """Test that an error is thrown when a subclass attempts to override a205 final method in a super class.206 """207 self.assertRaises(MethodSignatureError, self.analyse_file,208 'test_method_override_final_fail.jml')209210 def test_method_call_static_pass(self):211 """Test no error thrown when a static method is called from another212 class.213 """214 self.analyse_file('test_method_call_static_pass.jml')215216 def test_method_call_static_not_static_fail(self):217 """Test an error thrown when a method is referenced in a static way218 when it is not static.219 """220 self.assertRaises(StaticError, self.analyse_file,221 'test_method_call_static_not_static_fail.jml')222223 def test_lib_method_call(self):224 """Test a call to a library class."""225 self._analyse('class X {void x(){Random rand = new Random();' +226 'float x = rand.nextFloat();}}')227228 def test_lib_method_call_params(self):229 """Test a call to a library class with parameters."""230 self._analyse('class X {void x(){Random rand = new Random();' +231 'int x = rand.nextInt(10);}}')232233 def test_lib_method_in_super_call(self):234 """Test a method call to a library object where the method is defined235 in its super class.236 """237 self._analyse('class X {void x(){String s = new String();' +238 'int h = s.hashCode();}}')239240 def test_lib_method_call_fail(self):241 """Test a call to a library class fails when the method does not exist242 in that class."""243 self.assertRaises(SymbolNotFoundError, self._analyse,244 'class X {void x(){InputStream x = ' +245 'new InputStream(); x.nextInt();}}')246247 def test_lib_method_interface_call_fail(self):248 """Test a method invokation on an interface, where the object has the249 method, but the interface does not.250 """251 self.assertRaises(SymbolNotFoundError, self._analyse,252 'class X {void x(){ Readable x = ' +253 'new BufferedReader();x.close();}}')254255 def test_ref_non_static_field_fail(self):256 """Test that an error is thrown when a non static field is referenced257 from a static method.258 """259 self.assertRaises(StaticError, self._analyse,260 'class X {int x; X(){x=5;} static void x()' +261 '{ int y = x;}}')262263 def test_pivate_method_pass(self):264 """Test no error thrown when a private method is called from within265 the same class.266 """267 self._analyse('class X { void x() {} void y() { x();} }')268269 def test_private_method_fail(self):270 """Test an error thrown when a private method is attempted to be271 accessed in another class.272 """273 self.assertRaises(SymbolNotFoundError, self.analyse_file,274 'test_private_method_fail.jml')275276 def test_object_creator_fail(self):277 """Test that an error is raised when an object is assigned to a278 variable of an incorrect type."""279 self.assertRaises(TypeError, self.analyse_file,280 'test_object_creator_fail.jml')281282 def test_object_creator_abstact_fail(self):283 """Test an error is thrown when an abstract class is attempted to be284 instantiated.285 """286 self.assertRaises(ObjectCreationError, self.analyse_file,287 'test_object_creator_abstact_fail.jml')288289 def test_field(self):290 """Test that a field can be accessed from within a method."""291 self._analyse('class X { int x; void x() {x = 5;}}')292293 def test_final_field_assign_fail(self):294 """Test error thrown when assignment is attempted with a final field.295 """296 self.assertRaises(AssignmentError, self._analyse,297 'class X { static final short y = 5;' +298 'void x(){y=5;}}')299300 def test_field_ref_external_pass(self):301 """Test no error thrown when a field is referenced in another class.302 """303 self.analyse_file('test_field_ref_external_pass.jml')304305 def test_field_ref_external_fail(self):306 """Test an error thrown when a field is referenced in another class307 that doesn't exist.308 """309 self.assertRaises(SymbolNotFoundError, self.analyse_file,310 'test_field_ref_external_fail.jml')311312 def test_field_ref_static_pass(self):313 """Test no error thrown when a static field is referenced from314 another class.315 """316 self.analyse_file('test_field_ref_static_pass.jml')317318 def test_field_ref_static_not_static_fail(self):319 """Test an error thrown when a field is referenced in a static way320 when it is not static.321 """322 self.assertRaises(StaticError, self.analyse_file,323 'test_field_ref_static_not_static_fail.jml')324325 def test_field_ref_super_pass(self):326 """Test no error thrown when a field is referenced that is defined in327 a super class.328 """329 self.analyse_file('test_field_ref_super_pass.jml')330331 def test_pivate_field_pass(self):332 """Test no error thrown when a private field is used in the same class.333 """334 self._analyse('class X { private byte x; X(){x=1;}' +335 'void y() { byte y = x;} }')336337 def test_private_field_fail(self):338 """Test an error thrown when a private method is attempted to be339 accessed in another class.340 """341 self.assertRaises(SymbolNotFoundError, self.analyse_file,342 'test_private_field_fail.jml')343344 def test_lib_field_ref(self):345 """Test that a public field can be accessed that is in a library class.346 """347 self._analyse('class X { void x() { int x = Thread.MAX_PRIORITY;}}')348349 def test_lib_field_ref_fail(self):350 """Test that an error is thrown when a field doesn't exist in a351 library class.352 """353 self.assertRaises(SymbolNotFoundError, self._analyse,354 'class X {void x(){InputStream x = ' +355 'new InputStream(); int y = x.y;}}')356357 # There are a number of possibilities of possible name clashes -358 # these attempt to check for a few of the, but they are not359 # exhaustive tests360 def test_name_clash_field_type(self):361 """Test an error thrown when there is a name clash between a type362 (class) name and a field name.363 """364 self.assertRaises(VariableNameError, self._analyse,365 'class X { short X; }')366367 def test_name_clash_param_field(self):368 """Test an error thrown when there is a name clash between a parameter369 name and a field name.370 """371 self.assertRaises(VariableNameError, self._analyse,372 'class X { short x; void y(byte x){} }')373374 def test_name_clash_local_param(self):375 """Test an error thrown when there is a name clash between a parameter376 name and a local variable name.377 """378 self.assertRaises(VariableNameError, self._analyse,379 'class X { void y(byte x){int x = 5;} }')380381 def test_name_clash_local_field(self):382 """Test an error thrown when there is a name clash between a field383 name and a local variable name."""384 self.assertRaises(VariableNameError, self._analyse,385 'class X { double x; void y(){int x = 5;} }')386387 def test_if_pass(self):388 """Test no exception thrown when there is a boolean expression in the389 if statement.390 """391 self.analyse_stmt('if(3 > 1){}')392393 def test_if_fail(self):394 """Test exception thrown when there is no boolean expression in the if395 statement.396 """397 self.assertRaises(TypeError, self.analyse_stmt, 'if(3 - 1){}')398399 def test_while_pass(self):400 """Test no exception thrown when there is a boolean expression in the401 while statement.402 """403 self.analyse_stmt('while(3 > 1){}')404405 def test_while_fail(self):406 """Test exception thrown when there is no boolean expression in the407 while statement.408 """409 self.assertRaises(TypeError, self.analyse_stmt, 'while(3 - 1){}')410411 def test_for_pass(self):412 """Test no exception thrown when there is a boolean expression in the413 for statement.414 """415 self.analyse_stmt('for(int x = 1; x < 2; x=x+1){}')416417 def test_for_fail(self):418 """Test exception thrown when there is no boolean expression in the419 for statement.420 """421 self.assertRaises(TypeError, self.analyse_stmt,422 'for(int x = 1; x + 2; x=x+1){}')423424 def test_assign_pass(self):425 """Test no exception thrown when the types of both child nodes are426 equal.427 """428 self.analyse_stmt('int x = 1;')429430 def test_assign_undeclared_fail(self):431 """Test exception thrown when an assignment is made, but the variable432 has not been initialised.433 """434 self.assertRaises(NotInitWarning, self.analyse_stmt,435 'int x; int y = x;')436437 def test_lib_assign(self):438 """Test assigning a library class to a variable."""439 self.analyse_stmt('Date x = new Date();')440441 def test_array_init_pass(self):442 """Test no exception thrown when the type and dimension of the array443 is the same.444 """445 self.analyse_stmt('int arr[] = new int[10];')446447 def test_array_init_type_fail(self):448 """Test exception thrown when the type of an array initialisation is449 incorrect.450 """451 self.assertRaises(TypeError, self.analyse_stmt,452 'int arr[] = new boolean[10];')453454 def test_array_init_dimension_fail(self):455 """Test exception thrown when the number of dimensions of an array456 initialisation is incorrect.457 """458 self.assertRaises(DimensionsError, self.analyse_stmt,459 'int arr[] = new int[10][5];')460461 def test_array_element_assign_pass(self):462 """Test no exception thrown when the type and dimension of the array463 is the same.464 """465 self.analyse_stmt('int arr[] = new int[10]; arr[1] = 5;')466467 def test_array_element_assign_type_fail(self):468 """Test exception thrown when the type of an array element assignment469 is incorrent."""470 self.assertRaises(TypeError, self.analyse_stmt,471 'int arr[] = new int[10]; arr[1] = "hello";')472473 def test_array_element_assign_dimension_fail(self):474 """Test exception thrown when the number of dimensions of an array475 element assignment is incorrent.476 """477 self.assertRaises(TypeError, self.analyse_stmt,478 'int arr[] = new int[10]; arr[1][2] = 5;')479480 def test_array_assign_undeclared_fail(self):481 """Test exception thrown when an array element assignment is made, but482 the array is not initialised.483 """484 self.assertRaises(NotInitWarning, self.analyse_stmt,485 'int arr[][]; arr[1][2] = 5;')486487 def test_matrix_init_pass(self):488 """Test no exception thrown when a matrix is initialised."""489 self.analyse_stmt('matrix m = |5,5|;')490491 def test_matrix_element_assign_pass(self):492 """Test no exception thrown when a matrix element is assigned to."""493 self.analyse_stmt('matrix m = |5,5|; m|1,3| = 1;')494495 def test_matrix_element_assign_type_fail(self):496 """Test exception thrown when the type of an array element assignment497 is incorrect."""498 self.assertRaises(TypeError, self.analyse_stmt,499 'matrix m = |5,5|; m|4,4| = "hello";')500501 def test_matrix_assign_undeclared_fail(self):502 """Test exception thrown when a matrix element assignment is made, but503 the matrix is not initialised.504 """505 self.assertRaises(NotInitWarning, self.analyse_stmt,506 'matrix m; m|0,0| = 5;')507508 def test_cond_pass(self):509 """Test no exception thrown when the types of both child nodes are510 boolean.511 """512 self.analyse_stmt('3 < 4 || 3 > 5;')513514 def test_cond_fail(self):515 """Test exception thrown when the child nodes are not boolean."""516 self.assertRaises(TypeError, self.analyse_stmt, '5&&6;')517518 def test_eq_pass(self):519 """Test no exception thrown when the types of both child nodes are520 equal.521 """522 self.analyse_stmt('"hi" != "hello";')523524 def test_eq_fail(self):525 """Test exception thrown when the child nodes are not equal."""526 self.assertRaises(TypeError, self.analyse_stmt, '3 == true;')527528 def test_relational_pass(self):529 """Test no exception thrown when the types of both child nodes are int.530 """531 self.analyse_stmt('3 <= 4;')532533 def test_relational_fail(self):534 """Test exception thrown when the child nodes are not int."""535 self.assertRaises(TypeError, self.analyse_stmt, 'true > "x";')536537 def test_additive_pass(self):538 """Test no exception thrown when the types of both child nodes are int.539 """540 self.analyse_stmt('2-1;')541542 def test_additive_fail(self):543 """Test exception thrown when the child nodes are not int."""544 self.assertRaises(TypeError, self.analyse_stmt, 'true+"x";')545546 def test_concat_pass(self):547 """Test that two strings can be concatenated."""548 self.analyse_stmt('"Hell" + "o";')549550 def test_concat_fail(self):551 """Test that an error is thrown when a string is concatenated with a552 non string.553 """554 self.assertRaises(TypeError, self.analyse_stmt, '"Hell" + 1;')555556 def test_mult_pass(self):557 """Test no exception thrown when the types of both child nodes are int.558 """559 self.analyse_stmt('2*1;')560561 def test_mult_fail(self):562 """Test exception thrown when the child nodes are not int."""563 self.assertRaises(TypeError, self.analyse_stmt, 'true/"x";')564565 def test_not_pass(self):566 """Test no exception thrown when the type of the child node is boolean.567 """568 self.analyse_stmt('!true;')569570 def test_not_fail(self):571 """Test exception thrown when the child node is not boolean."""572 self.assertRaises(TypeError, self.analyse_stmt, '!3;')573574 def test_neg_pass(self):575 """Test no exception thrown when the type of the child node is int."""576 self.analyse_stmt('-1;')577578 def test_neg_fail(self):579 """Test exception thrown when the child node is not int."""580 self.assertRaises(TypeError, self.analyse_stmt, '-"x";')581582 def test_inc_pass(self):583 """Test no exception thrown when the type of the child node is int."""584 self.analyse_stmt('int x = 1; x++;')585586 def test_dec_fail(self):587 """Test exception thrown when the child node is not int."""588 self.assertRaises(TypeError, self.analyse_stmt, '--"x";')589590 # The next section tests the implicit conversion of numerical primitive591 # data types592 # It would take many tests to test this exaustively, so a representative593 # subset of the possibilities is tested below594595 def test_convert_char_int(self):596 """Test a char can be multiplied by an int and the * node's type597 becomes int.598 """599 node = self.analyse_stmt("'a'*1;")600 self.assertEqual(self.get_type_node(node), "int")601602 def test_convert_int_long(self):603 """Test an int can be divided by a long and the / node's type becomes604 long.605 """606 node = self.analyse_stmt('100/10L;')607 self.assertEqual(self.get_type_node(node), "long")608609 def test_convert_long_float(self):610 """Test a long can be added to a float and the + node's type becomes611 float.612 """613 node = self.analyse_stmt('1L+10F;')614 self.assertEqual(self.get_type_node(node), "float")615616 def test_convert_int_double(self):617 """Test a float can be subtracted by a double and the - node's type618 becomes double.619 """620 node = self.analyse_stmt('10-5.5D;')621 self.assertEqual(self.get_type_node(node), "double")622623 ## HELPER METHODS ##624625 def analyse_stmt(self, stmt):626 """Helper method used so that single line code can be tested without627 having to declare a class and method for it to go in.628 """629 return self._analyse("""630 class X {631 void x() {632 """ +633 stmt +634 """635 }636 }637 """)638639 def analyse_file(self, file_name):640 """Helper method to allow the semantic analyser to be run on a641 particular file in the test_files folder.642 """643 path = os.path.join(self._file_dir, file_name)644 return self._analyse(path)645646 def get_type_node(self, root):647 """Helper method for use by the conversion tests to get the648 type node from the AST.649 Must get the correct child of these nodes:650 class651 class_body652 method_dcl653 block654 <numerical op node>655 <the left child of that>656 """657 block_node = root[0][0].children[3].children[0].children[3]658 return block_node.children[0].type_

Full Screen

Full Screen

Robot.py

Source:Robot.py Github

copy

Full Screen

1#-*- coding: utf-8 -*-2import sys3import threading4from naoqi import ALProxy5import Action as action6from Analyse.Analyse import *7from Node import *8import time910xml = 'C:\\Users\\Youssef\\Downloads\\ball_cascade.xml'1112class Robot(threading.Thread):13 """ 14 class define every robot15 """16 PORT = 95591718 def __init__(self,ip,role,strat,coach):19 threading.Thread.__init__(self)20 self.arretthread = False21 self.coach = coach22 self.pos = None23 self.ip = ip24 self.role = role25 self.ready = False2627 # connection to the differentes modules28 self.tpMotion = self.connectProxy("ALMotion")29 self.tpPosture = self.connectProxy("ALRobotPosture")30 self.tpLed = self.connectProxy("ALLeds")3132 # booleane to confirm if every proxy are available33 self.running = self.tpMotion[0] and self.tpPosture[0] and self.tpLed[0]34 if self.running:35 self.motionProxy = self.tpMotion[1]36 self.postureProxy = self.tpPosture[1]37 self.ledProxy = self.tpLed[1]38 self.analyse = Analyse(self.ip,PORT)3940 def stop(self):41 """42 stop threads43 """44 self.arretthread = True4546 def trace(self, frame, event, arg):47 """48 force stoping49 """50 if event=='line':51 if self.arretthread:52 raise SystemExit()53 return self.trace5455 def run(self):56 """57 run thread58 """59 if self.running:60 try:61 sys.settrace(self.trace)62 self.IA(Phase.Initial)63 self.IA(Phase.Ready)6465 sys.settrace(None)66 except:67 sys.settrace(None)6869 def connectProxy(self,module):70 """71 make a connection proxy to the robot72 """73 try:74 75 return True, ALProxy(module, self.ip, PORT)76 except Exception,e:77 print "Could not create proxy to ",module78 print "Error was: ",e79 return (False,)8081 def get_pos(self):82 return self.pos8384 def set_pos(self,pos):85 self.pos = pos8687 def play(condition,x,y):88 """89 playing routine90 91 # we scan the ground to detect the ball92 if self.scanForBall():93 # if the ball is in the playing area according to the role and in the playing area94 if condition and self.coach.perimeterGround.perimeter(self.coach.posBall):95 # we move until we are near96 if self.moveToBall():97 # if we are in the firing range and in the alignment of the cages98 if self.coach.perimeterShoot.perimeter() and alignement():99 # we shoot100 action.shoot()101 # otherwise if there is an obstacle102 elif obstacle():103 # we try to make a pass104 if self.coach.passBall():105 action.passTo(pos)106 # otherwise we bypass107 else:108 action.contourne()109 # otherwise we place ourselves in the perimeter and we align ourselves110 else:111 action.moveTo(self.coach.posCage)112 action.turn(self.motionProxy,degree)113 else:114 action.moveTo(Point2D(x,y))115 """116 pass117118 def IA(self,gamePhase):119 """120 decision per phase of robot121 """122 if gamePhase == Phase.Initial:123 # BLUE COLOR124 self.ledProxy.fadeListRGB('ChestLeds', [0x000000ff], [0])125 # declare his actual position as his origin/home (function)126 self.IA(Phase.Set)127128 elif gamePhase == Phase.Set:129 # YELLOW COLOR130 self.ledProxy.fadeListRGB('ChestLeds', [0x00f5bb19], [0])131 if self.coach.kickoff:132 if self.role == Role.LATTACKER:133 action.moveTo(Role[2])134 self.scanForBall()135 else:136 action.moveTo(Role[1])137 # turn to be in front of the enemy goal138 action.turn(self.motionProxy,degresOfTurn)139 while not self.ready:140 continue141142 elif gamePhase == Phase.Ready:143 # wait sonor signal (function)144 self.IA(Phase.Playing)145146 elif gamePhase == Phase.Playing:147 # GREEN COLOR148 self.ledProxy.fadeListRGB('ChestLeds', [0x0000ff00], [0])149 # according to the role150 if self.role == Role.LATTACKER:151 # if we have the kickoff152 if self.coach.kickoff:153 action.shoot()154 while self.coach.timer.minute < 10:155 #play((self.coach.posBall.get_y() > -0.75 and coach.posBall.get_x() < 0),-0.75,0)156 break157 158 elif self.role == Role.RATTACKER:159 while self.coach.timer.minute < 10:160 #play((self.coach.posBall.get_y() > -0.75 and coach.posBall.get_x() > 0),0.75,0)161 break162 163 elif self.role == Role.LDEFENSE:164 while self.coach.timer.minute < 10:165 #play((self.coach.posBall.get_y() < -0.75 and coach.posBall.get_x() > 0),-0.75,-3)166 break167 168 elif self.role == Role.RDEFENSE:169 while self.coach.timer.minute < 10:170 #play((self.coach.posBall.get_y() < -0.75 and coach.posBall.get_x() > 0),0.75,-3)171 break172173 elif self.role == Role.GOAL:174 while self.coach.timer.minute < 10:175 """176 # if the ball comes into our camp, the robot moves according to it177 if self.coach.posBall.get_y() > -2:178 if self.coach.posBall.get_x() < 0:179 action.moveTo(Point2D(-1,-4.2))180 elif self.coach.posBall.get_() > 0:181 action.moveTo(Point2D(1,-4.2))182 # if it enters the perimeter of the keeper, he sits down to protect the cages183 if self.coach.perimeterGardian.perimeter(self.coach.posBall):184 action.defense(self.postureProxy,self.motionProxy,10)185 """186 break187188 elif gamePhase == Phase.Penalized:189 # RED COLOR190 self.ledProxy.fadeListRGB('ChestLeds', [0x00FF0000], [0])191 time.sleep(40)192 self.IA(Phase.Playing)193194 elif gamePhase == Phase.Finished:195 self.ledProxy.fadeListRGB('ChestLeds', [0x0000000], [0])196 self.stop()197198 def scanForBall(self):199 """200 The robot scans the field by looking around for201 the ball. Once the ball is found, it moves its202 body to face the ball203 """204 self._analyse._takeTopImage(xml)205 self._analyse._takeBottomImage(xml)206 self._motionProxy.angleInterpolation("HeadPitch", [0.1], [1.0], True)207 self._motionProxy.setStiffnesses("HeadPitch", 1)208 t1 = time.time()209 t2 = time.time() - t1210 #While ball is not found211 while (self._analyse._ballAreaTop == -1 and self._analyse._ballAreaBottom == -1 and t2 <12):212 self._analyse._takeTopImage(xml)213 self._analyse._takeBottomImage(xml)214 Action.lookAround(self._motionProxy)215 t2 = time.time() - t1216217 #The robot and head face the ball218 Action.turnBodyToHeadAngle(self._motionProxy)219220 def moveToBall(self):221 """222 The robot moves towards the ball223 :return: exit state. If ball is lost (0) or if ball is at robots feet(1)224 """225 x = 0.6226 y = 0.0227 z = 0.0228229 #Fix head angle230 self._motionProxy.angleInterpolation("HeadYaw",[0.0], [1.0],True)231 self._motionProxy.angleInterpolation("HeadPitch", [0.1], [1.0], True)232 self._motionProxy.setStiffnesses("HeadPitch", 0)233234 self._analyse._takeTopImage(xml)235 self._analyse._takeBottomImage(xml)236 #While the ball is visible in the camera and it is not near the feet237 while ((self._analyse._ballAreaBottom != -1 or self._analyse._ballAreaTop != -1) and238 (self._analyse._ballGridLocationBottom[0] != [3] and239 self._analyse._ballGridLocationBottom[1] != [1])240241 ):242 self._motionProxy.post.move(x, y, z)243 #An image is taken244 self._analyse._takeBottomImage(xml)245 self._analyse._takeTopImage(xml)246247 #If the ball is perceived towards the right248 if (self._analyse._ballGridLocationBottom[1] == 3 or249 self._analyse._ballGridLocationTop[1] == 3250 ):251 #The robot looks and moves towards the ball252 x = 0253 z = 0.2254255256 #if the ball is perceived towards the left257 elif (self._analyse._ballGridLocationBottom[1] == 0 or258 self._analyse._ballGridLocationTop[1] == 0259 ):260 # The robot looks and moves towards the261 x = 0262 z = -0.2263264265 #If the ball is perceived around the center266 else:267 if (x<1):268 x = x + 0.2269 z = 0.0270271 self._motionProxy.stopMove()272 self._motionProxy.move(0.0,0.0,0.0)273274 #If ball is lost return 0275 if (self._analyse._ballAreaBottom != -1):276 return False277 #If ball is at feet return 1278 elif (self._analyse._ballGridLocationBottom == [3,1] or279 self._analyse._ballGridLocationBottom ==[3,2]280 ):281 return True282283#****************** TEST Robot *********************#284285if __name__ == "__main__":286287288 robot = Robot("faux",'role')289 #robot.moveToBall()290 #ret = robot.moveToBall()291 #print(ret)292 #robot._analyse._vision._unsubscribeAll()293294 #Action.turnBodyToHeadAngle(robot._motionProxy) ...

Full Screen

Full Screen

recipe-496984.py

Source:recipe-496984.py Github

copy

Full Screen

...43 else:44 result[atomtype]= s[offset+12:offset+atomsize]45 offset+= atomsize46 return result47def _analyse(fp, offset0, offset1):48 "Walk the atom tree in a mp4 file"49 offset= offset050 while offset < offset1:51 fp.seek(offset)52 atomsize= struct.unpack("!i", fp.read(4))[0]53 atomtype= fp.read(4)54 if atomtype in flagged[CONTAINER]:55 data= ''56 for reply in _analyse(fp, offset+(atomtype in flagged[SKIPPER] and 12 or 8),57 offset+atomsize):58 yield reply59 else:60 fp.seek(offset+8)61 if atomtype in flagged[TAGITEM]:62 data=fp.read(atomsize-8)[16:]63 if atomtype in flagged[NOVERN]:64 data= struct.unpack("!ii", data)65 elif atomtype in flagged[XTAGITEM]:66 data= _xtra(fp.read(atomsize-8))67 else:68 data= fp.read(min(atomsize-8, 32))69 if not atomtype in flagged[IGNORE]: yield atomtype, atomsize, data70 offset+= atomsize71def mp4_atoms(pathname):72 fp= open(pathname, "rb")73 fp.seek(0,2)74 size=fp.tell()75 for atom in _analyse(fp, 0, size):76 yield atom77 fp.close()78class M4ATags(dict):79 "An example class reading .m4a tags"80 cvt= {81 'trkn': 'Track',82 '\xa9ART': 'Artist',83 '\xa9nam': 'Title',84 '\xa9alb': 'Album',85 '\xa9day': 'Year',86 '\xa9gen': 'Genre',87 '\xa9cmt': 'Comment',88 '\xa9wrt': 'Writer',89 '\xa9too': 'Tool',...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful