Best Python code snippet using tempest_python
bodyfeature.py
Source:bodyfeature.py
...47 def __init__(self, points, confi):48 self.points = np.array(points)49 self.c = confi50 self.standard = length(self.points[1]-self.points[8])51 def create_trunk(self, i, center):52 return trunk(self.points[i] - self.points[center], self.c[i], self.c[center],53 self.c[i] > 0.0 and self.c[center] > 0.0 and length(self.points[i] - self.points[center]) > self.standard * 0.1)54 @property55 def lleg_in(self):56 return self.create_trunk(12, 13)57 @property58 def lleg_out(self):59 return self.create_trunk(14, 13)60 @property61 def rleg_in(self):62 return self.create_trunk(9, 10)63 @property64 def body(self):65 return self.create_trunk(1, 8)66 @property67 def rleg_out(self):68 return self.create_trunk(11, 10)69 @property70 def larm_in(self):71 return self.create_trunk(5, 6)72 @property73 def larm_out(self):74 return self.create_trunk(7, 6)75 @property76 def rarm_in(self):77 return self.create_trunk(2, 3)78 @property79 def rarm_out(self):80 return self.create_trunk(4, 3)81 @property82 def head(self):83 return self.create_trunk(0, 1)84 @property85 def lshoulder(self):86 return self.create_trunk(5, 1)87 @property88 def rshoulder(self):89 return self.create_trunk(2, 1)90 def is_stand(self):91 """92 å¤ææ¯å¦ç«ç«93 å½åå¤æé»è¾ï¼åå«å¤æå·¦å³è
¿ï¼æä¸æ¡æ»¡è¶³å为ç«ç«94 æ¯æ¡è
¿å¤æé»è¾ï¼95 两æ¡è
¿é¿åº¦æ¯ä¾ç¸å·®ä¸è¶
è¿20%ï¼96 大è
¿åå°è
¿å¤¹è§è¶
è¿150°ï¼97 æ¯æ¡è
¿å水平线çè·ç¦»å¤§äº75°ï¼è¿ä¹åç´ï¼98 :return:99 """100 if self.is_lie():101 return False102 if self.lleg_in.useable and self.lleg_out.useable:103 x, y = self.lleg_in.vector, self.lleg_out.vector104 if abs(length(x) - length(y)) / length(x) < 0.2 and degree(x, y) > 150 and degree(x) > 75 and degree(105 y) > 75:106 return True107 if self.rleg_in.useable and self.rleg_out.useable:108 x, y = self.rleg_in.vector, self.rleg_out.vector109 if abs(length(x) - length(y)) / length(x) < 0.2 and degree(x, y) > 150 and degree(x) > 75 and degree(110 y) > 75:111 return True112 return False113 def _is_raise(self, x, y):114 if degree(y, np.array([0, -1])) < 45 and y[1] < 0:115 return True116 # if degree(x, y) < 45 and degree(y) > 60:117 # return True118 return False119 def is_raise(self):120 """121 å¤ææ¯å¦ä¸¾æ122 å½åå¤æé»è¾ï¼123 åå·¦å³æåå«å¤æï¼æä¸åªæ为举起ï¼åè¿å举æç¶æ124 æ¯åªæå¤æé»è¾ï¼å¤æå°è对åºåéï¼6->7å3->4ï¼ä¸ç«ç´æ¹å夹è§æ¯å¦å°äº45°ï¼ä¸yè½´æ¹åæ¯å¦åä¸125 ï¼ç±äºæå¿æ²¡æåæ³å¤æçå¾ç»ï¼æ以第ä¸å¼ çææºä¹è¢«è®¤ä¸ºæ¯ä¸¾æï¼126 :return:127 """128 if self.larm_in.useable and self.larm_out.useable:129 if self._is_raise(self.larm_in.vector, self.larm_out.vector):130 return True131 if self.rarm_in.useable and self.rarm_out.useable:132 if self._is_raise(self.rarm_in.vector, self.rarm_out.vector):133 return True134 return False135 def is_sit(self):136 """137 å¤ææ¯å¦åä¸138 å½åå¤æé»è¾ï¼139 é¦å
å¤ææ¯å¦èººä¸ï¼å¦æ躺ä¸åè¿åFalse140 å¦æ没æ躺ä¸ï¼åä¾æ¬¡å¤æå·¦å³è
¿çç¶æã141 æ ¹æ®ä¸è§å½¢ä¸¤è¾¹ä¹å大äºç¬¬ä¸è¾¹çåçï¼å¤æ两è
¿çåéé¿åº¦ï¼ä»¥åèè¸å°è¯é¨çåéé¿åº¦ï¼11->9å14->12ï¼142 ï¼ä¸¤æ¡å¤§è
¿åé为13->12å10->9ï¼å°è
¿åé为13->14å10->11)143 å¦æ大è
¿åå°è
¿é¿å¤§äºç¬¬ä¸è¾¹åéé¿åº¦çæ个åæ°ï¼å为åä¸144 ï¼ç±äºç«ç´æ¶åä¹æ¯ä¸è§å½¢ï¼å æ¤éè¦è¶
è¿ä¸å®éå¼ï¼æ¥ç¡®ä¿å¼¯æ²ç¨åº¦ï¼145 ï¼ç¨å¤§è
¿åå°è
¿å¤¹è§å¤æä¹å¯ä»¥ï¼åªæ¯å¤æçæ¶åç¨äºä¸è§å½¢ä¸è¾¹ï¼146 两æ¡è
¿æä¸æ¡æ»¡è¶³å为åä¸çç¶æ147 :return:148 """149 if self.is_lie():150 return False151 if self.lleg_in.useable and self.lleg_out.useable:152 x, y = self.lleg_in.vector, self.lleg_out.vector153 third = self.create_trunk(9, 11)154 if third.useable:155 if length(x) + length(y) > length(third.vector) * 1.20:156 return True157 if self.rleg_in.useable and self.rleg_out.useable:158 x, y = self.rleg_in.vector, self.rleg_out.vector159 third = self.create_trunk(9, 11)160 if third.useable:161 if length(x) + length(y) > length(third.vector) * 1.20:162 return True163 return False164 def is_lie(self):165 """166 å¤ææ¯å¦èººä¸167 å½åå¤ææ åï¼å¤æ身ä½èº¯å¹²åéï¼8->1)ä¸æ°´å¹³æ¹åç夹è§ï¼å°äº90°çï¼ï¼å¦æ夹è§å°äº45°å为躺ä¸168 :return:169 """170 if self.body.useable:171 x = self.body.vector172 dg = degree(x)173 if dg > 90:...
test_trunks_rbac.py
Source:test_trunks_rbac.py
...28 def resource_setup(cls):29 super(TrunksExtRbacTest, cls).resource_setup()30 cls.network = cls.create_network()31 cls.port_id = cls.create_port(cls.network)["id"]32 def create_trunk(self, port_id):33 trunk = self.ntp_client.create_trunk(port_id, [])34 self.addCleanup(35 test_utils.call_and_ignore_notfound_exc,36 self.ntp_client.delete_trunk, trunk["trunk"]['id'])37 return trunk38 @decorators.idempotent_id('c02618e7-bb20-1a3a-83c8-6eec2af08130')39 @rbac_rule_validation.action(service="neutron",40 rules=["create_trunk"])41 def test_create_trunk(self):42 """Create trunk.43 RBAC test for the neutron "create_trunk" policy44 """45 with self.override_role():46 self.create_trunk(self.port_id)47 @decorators.idempotent_id('c02618e7-bb20-1a3a-83c8-6eec2af08131')48 @rbac_rule_validation.action(service="neutron",49 rules=["get_trunk"],50 expected_error_codes=[404])51 def test_show_trunk(self):52 """Show trunk.53 RBAC test for the neutron "get_trunk" policy54 """55 trunk = self.create_trunk(self.port_id)56 with self.override_role():57 self.ntp_client.show_trunk(trunk['trunk']['id'])58 @decorators.idempotent_id('c02618e7-bb20-1a3a-83c8-6eec2af08132')59 @rbac_rule_validation.action(service="neutron",60 rules=["get_trunk",61 "delete_trunk"],62 expected_error_codes=[404, 403])63 def test_delete_trunk(self):64 """Delete trunk.65 RBAC test for the neutron "delete_trunk" policy66 """67 trunk = self.create_trunk(self.port_id)68 with self.override_role():69 self.ntp_client.delete_trunk(trunk['trunk']['id'])70 @decorators.idempotent_id('047badd1-e4ff-40c5-9929-99ffcb8750a7')71 @rbac_rule_validation.action(service="neutron", rules=["get_trunk"])72 def test_list_trunks(self):73 """Show trunk.74 RBAC test for the neutron ``list_trunks``` function and75 the ``get_trunk`` policy76 """77 admin_resource_id = self.create_trunk(self.port_id)["trunk"]['id']78 with (self.override_role_and_validate_list(79 admin_resource_id=admin_resource_id)) as ctx:80 ctx.resources = self.ntp_client.list_trunks(81 id=admin_resource_id)["trunks"]82class TrunksSubportsExtRbacTest(base.BaseNetworkExtRbacTest):83 @classmethod84 def skip_checks(cls):85 super(TrunksSubportsExtRbacTest, cls).skip_checks()86 if not utils.is_extension_enabled('trunk', 'network'):87 msg = "trunk extension not enabled."88 raise cls.skipException(msg)89 @classmethod90 def resource_setup(cls):91 super(TrunksSubportsExtRbacTest, cls).resource_setup()92 cls.network = cls.create_network()93 cls.port_id = cls.create_port(cls.network)["id"]94 cls.trunk_id = cls.ntp_client.create_trunk(95 cls.port_id, [])['trunk']['id']96 cls.addClassResourceCleanup(97 test_utils.call_and_ignore_notfound_exc,98 cls.ntp_client.delete_trunk, cls.trunk_id)99 def create_subports(self, trunk_id, port_id):100 subports = [{'port_id': port_id,101 'segmentation_type': 'vlan',102 'segmentation_id': 4000}]103 sub = self.ntp_client.add_subports(trunk_id, subports)104 self.addCleanup(105 test_utils.call_and_ignore_notfound_exc,106 self.ntp_client.remove_subports,107 trunk_id, subports)108 return sub["sub_ports"]...
trunk.py
Source:trunk.py
...134 return self.get(config.NEUTRON_TRUNKS + '/' + trunkid)135 def get_trunks(self):136 logging.info('get all trunks')137 return self.get(config.NEUTRON_TRUNKS)138 def create_trunk(self, payload):139 if 'trunk' in payload:140 logging.info('create trunk: ' + payload['trunk']['id'])141 else:142 logging.info('bulk create trunks: ' + ', '.join([trunk['id'] for trunk in payload['trunks']]))143 return self.post(config.NEUTRON_TRUNKS, payload)144 def update_trunk(self, trunkid, payload):145 logging.info('update trunk: ' + trunkid)146 return self.put(config.NEUTRON_TRUNKS + '/' + trunkid, payload)147 def delete_trunk(self, trunkid):148 logging.info('delete trunk: ' + trunkid)149 return self.delete(config.NEUTRON_TRUNKS + '/' + trunkid)150 @staticmethod151 def perform_tests(servername, username, count=0):152 logging.info('perform trunk tests, server: %s, user: %s' % (servername, username))153 tester = Trunk(servername, username)154 utils.assert_status(tester.get_trunks(), 200)155 trunk_one = tester.create_trunk(change_id(TRUNK_ONE, count))156 utils.assert_status(trunk_one, 201)157 if trunk_one.status_code == 201:158 trunk_one_id = json.loads(trunk_one.text)['trunk']['id']159 utils.assert_status(tester.get_trunk(trunk_one_id), 200)160 utils.assert_status(tester.create_trunk(change_id(TRUNK_DEFAULT, count)), 201)161 utils.assert_status(tester.update_trunk(change_id(TRUNK_UPDATE['trunk'], count)['trunk']['id'],162 change_id(TRUNK_UPDATE['trunk'], count)), 201)163 if count == 0:164 utils.assert_status(tester.create_trunk(TRUNKS_BULK), 201)165 utils.assert_status(tester.delete_trunk(TRUNKS_BULK['trunks'][0]['id']), 204)166 utils.assert_status(tester.get_trunk(TRUNKS_BULK['trunks'][0]['id']), 404)167 trunks = tester.get_trunks()168 for trunk in json.loads(trunks.text)['trunks']:169 utils.assert_status(tester.delete_trunk(trunk['id']), 204)170if __name__ == '__main__':...
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!!