Best Python code snippet using hypothesis
helper_functions.py
Source:helper_functions.py
1#!/usr/bin/python2'''3Created on September 27, 20184@author: Ryan5'''6import math7import csv8L1 = 500 #mm9L2 = 383 #mm10boom_motor_pos_max = -5 # Max position of boom motor. To prevent collision between boom motor crank and container11arm_motor_pos_min = 25 # Min position of arm motor. To prevent collision between linkages12arm_motor_pos_max = 115 # Max position of arm motor. To prevent collision between linkages13arm_boom_motors_pos_relative_sum_max = -30 # Max sum between boom/arm motor positions. To prevent collision between arm motor crank and base frame14bucket_motor_pos_min = -1.415bucket_motor_pos_max = 2.116# MAX AND MIN JOINT SPEEDS FOR CREATING INTERMEDIATE TRAJECTORY. 17speedMax = [20.0,20.0,1.0] # RAD/S [boom,arm,bucket] Note: Boom and arm speed are BEFORE 50:1 gearbox. 18speedMin = [2.0,2.0,0.1] # RAD/S [boom,arm,bucket] Note: Boom and arm speed are BEFORE 50:1 gearbox. 19transition_hold_time = 1 # Seconds. Time to hold between intermediate trajectory and trajectory (append this many seconds of first frame to intermediate trajectory)20def jointAngles2xyPos(theta_boom, theta_arm):21 x = L1*math.cos(theta_boom)+L2*math.cos(theta_arm + theta_boom)22 y = -L1*math.sin(theta_boom)-L2*math.sin(theta_arm + theta_boom)23 return [x,y]24def xyPos2jointAngles(x, y):25 theta1 = -math.acos((y*y+x*x+L1*L1-L2*L2)/(2*L1*math.sqrt(x*x+y*y))) + math.atan2(-y,x)26 theta2 = math.acos((x-L1*math.cos(theta1))/L2)27 if y > -L1*math.sin(theta1): theta2 *= -128 return [theta1, theta2-theta1] # [theta_boom, theta_arm]29def checkPositionLimits(theta_boom, theta_arm, theta_bucket):30 if theta_boom > boom_motor_pos_max: theta_boom = boom_motor_pos_max 31 if theta_arm < arm_motor_pos_min: theta_arm = arm_motor_pos_min32 if theta_arm > arm_motor_pos_max: theta_arm = arm_motor_pos_max33 if theta_boom + theta_arm < arm_boom_motors_pos_relative_sum_max:34 if theta_arm + theta_boom >= arm_boom_motors_pos_relative_sum_max:35 theta_arm = arm_boom_motors_pos_relative_sum_max - theta_boom36 else:37 theta_arm = arm_motor_pos_max38 theta_boom = arm_boom_motors_pos_relative_sum_max - theta_arm39 if theta_bucket > bucket_motor_pos_max: theta_bucket = bucket_motor_pos_max40 if theta_bucket < bucket_motor_pos_min: theta_bucket = bucket_motor_pos_min41 return [theta_boom, theta_arm, theta_bucket]42def createIntermediateTrajectory(desiredPos, currentPos, fps, speed_factor=1.0):43 intermediate_trajectory = []44 direction = [1,1,1]45 stepSize = [0,0,0]46 for i in range(0,3): 47 if desiredPos[i] < currentPos[i]: direction[i] = -148 stepSize[i] = direction[i]*(speed_factor*(speedMax[i] - speedMin[i]) + speedMin[i])/fps49 i = 050 while(True):51 joint_i = [0,0,0]52 for j in range(0,3): 53 joint_i[j] = currentPos[j] + i*stepSize[j]54 if joint_i[j]*stepSize[j] > desiredPos[j]*stepSize[j]: joint_i[j] = desiredPos[j]55 intermediate_trajectory.append(joint_i)56 if joint_i == desiredPos: break57 i += 158 for k in range(0,int(transition_hold_time*fps)):59 intermediate_trajectory.append(desiredPos) 60 return intermediate_trajectory61def readTrajectoryFromFile(file_name, isCartesian=False):62 trajectory = []63 with open(file_name) as csv_file:64 csv_reader = csv.reader(csv_file)65 for row in csv_reader:66 positions = []67 for col in row: positions.append(float(col))68 if len(positions) != 3: 69 print 'INVALID FORMAT. EACH ROW OF TRAJECTORY CSV MUST HAVE EXACTLY 3 COLUMNS. DID NOT LOAD TRAJECTORY'70 return []71 trajectory.append(positions)72 if isCartesian: 73 for i in range(0,len(trajectory)):74 theta_boom_theta_arm = xyPos2jointAngles(trajectory[i][0],trajectory[i][1])75 trajectory[i][0] = 50.0*theta_boom_theta_arm[0]76 trajectory[i][1] = 50.0*theta_boom_theta_arm[1] 77 78 for positions in trajectory:79 if positions != checkPositionLimits(positions[0],positions[1],positions[2]):80 print 'POSITION IN TRAJECTORY OUT OF RANGE. DID NOT LOAD TRAJECTORY'81 return []82 return trajectory83 ...
test_format.py
Source:test_format.py
...5from jsonschema import FormatError, ValidationError, FormatChecker6from jsonschema.validators import Draft4Validator7BOOM = ValueError("Boom!")8BANG = ZeroDivisionError("Bang!")9def boom(thing):10 if thing == "bang":11 raise BANG12 raise BOOM13class TestFormatChecker(TestCase):14 def test_it_can_validate_no_formats(self):15 checker = FormatChecker(formats=())16 self.assertFalse(checker.checkers)17 def test_it_raises_a_key_error_for_unknown_formats(self):18 with self.assertRaises(KeyError):19 FormatChecker(formats=["o noes"])20 def test_it_can_register_cls_checkers(self):21 original = dict(FormatChecker.checkers)22 self.addCleanup(FormatChecker.checkers.pop, "boom")23 FormatChecker.cls_checks("boom")(boom)...
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!!