How to use has_exception method in SeleniumBase

Best Python code snippet using SeleniumBase

tests_Functions.py

Source:tests_Functions.py Github

copy

Full Screen

...6def test_insert_contestant():7 history = []8 contestants = [create_contestant([1,0,0]),create_contestant([2,1,4])]9 10 assert(has_exception(insert_contestant,(history,contestants,create_contestant([0,0,0]),-1)) == True)11 12 assert(has_exception(insert_contestant,(history,contestants,create_contestant([0,0,0]),3)) == True)13 insert_contestant(history,contestants,create_contestant([0,0,0]))14 assert(contestants == [create_contestant([1,0,0]),create_contestant([2,1,4]),create_contestant([0,0,0])])15 insert_contestant(history,contestants,create_contestant([1,1,1]),2)16 assert(contestants == [create_contestant([1,0,0]),create_contestant([2,1,4]),create_contestant([1,1,1]),create_contestant([0,0,0])])17 undo(history,contestants)18 assert(contestants == [create_contestant([1,0,0]),create_contestant([2,1,4]),create_contestant([0,0,0])])19def test_remove_contestants():20 history = []21 contestants = [create_contestant([1,0,0]),22 create_contestant([2,1,4]),23 create_contestant([3,1,4]),24 create_contestant([4,10,4]),25 ]26 27 assert(has_exception(remove_range_contestants,(history,contestants,-1,2)) == True)28 assert(has_exception(remove_range_contestants,(history,contestants,0,10)) == True)29 assert(has_exception(remove_range_contestants,(history,contestants,3,2)) == True)30 remove_range_contestants(history,contestants,1,2)31 assert(contestants == [create_contestant([1,0,0]),create_contestant([4,10,4])])32 remove_filter_contestants(history,contestants,(lambda x: get_score(x,0) == 1))33 assert(contestants == [create_contestant([4,10,4])])34 undo(history,contestants)35 assert(contestants == [create_contestant([1,0,0]),create_contestant([4,10,4])])36def test_replace_contestant():37 history = []38 contestants = [create_contestant([10,0,0]),39 create_contestant([2,10,4]),40 create_contestant([3,10,4]),41 create_contestant([4,10,4]),42 ]43 44 assert(has_exception(replace_contestant, (history,contestants,-1,0,0)) == True)45 assert(has_exception(replace_contestant, (history,contestants,100,10,10)) == True)46 replace_contestant(history,contestants,0,1,10)47 assert (contestants == [create_contestant([10,10,0]),48 create_contestant([2,10,4]),49 create_contestant([3,10,4]),50 create_contestant([4,10,4])])51 undo(history,contestants)52 assert (contestants == [create_contestant([10,0,0]),53 create_contestant([2,10,4]),54 create_contestant([3,10,4]),55 create_contestant([4,10,4])])56def test_list_contestants():57 contestants = [create_contestant([1,0,0]),58 create_contestant([2,10,4]),59 create_contestant([3,10,4]),60 create_contestant([4,10,4]),61 ]62 assert(list_contestants(contestants,None,None) == \63 [create_contestant([1,0,0]),64 create_contestant([2,10,4]),65 create_contestant([3,10,4]),66 create_contestant([4,10,4]),67 ])68 69 assert(list_contestants(contestants,lambda x: -get_score(x,None),None) == \70 [71 create_contestant([4,10,4]),72 create_contestant([3,10,4]),73 create_contestant([2,10,4]),74 create_contestant([1,0,0]),75 ])76 77 assert(list_contestants(contestants,None,lambda x: get_score(x,None) > 15) == \78 [79 create_contestant([2,10,4]),80 create_contestant([3,10,4]),81 create_contestant([4,10,4]),82 ])83 assert(list_contestants(contestants,lambda x: -get_score(x,None),lambda x: get_score(x,None) > 15) == \84 [85 create_contestant([4,10,4]),86 create_contestant([3,10,4]),87 create_contestant([2,10,4]),88 ])89def test_calculate_function():90 contestants = [create_contestant([1,0,0]),91 create_contestant([2,10,4]),92 create_contestant([3,10,4]),93 create_contestant([4,10,4])]94 extractor = (lambda x: get_score(x,None) / 3)95 avg = (lambda x:sum(x) / len(x))96 97 assert(has_exception(calculate_function,(contestants,extractor,avg,-1,2)))98 assert(has_exception(calculate_function,(contestants,extractor,avg,2,100)))99 assert(abs(calculate_function(contestants,extractor,avg,2,3) - 35 / 6) < 1e-5)100 assert(abs(calculate_function(contestants,extractor,min,0,2) - 1 / 3) < 1e-5)101def test_top_contestants():102 contestants = [create_contestant([1,0,0]),103 create_contestant([2,10,4]),104 create_contestant([3,10,4]),105 create_contestant([4,10,4])]106 assert(has_exception(top_contestants,(10,lambda x:0)))107 assert(has_exception(top_contestants,(-1,lambda x:0)))108 assert(top_contestants(contestants,2,lambda x:-get_score(x,None)) == [create_contestant([4,10,4]),create_contestant([3,10,4])])109 assert(top_contestants(contestants,2,lambda x:get_score(x,0)) == [create_contestant([1,0,0]),110 create_contestant([2,10,4])])111def run_tests():112 test_insert_contestant()113 test_remove_contestants()114 test_replace_contestant()115 test_list_contestants()116 test_calculate_function()...

Full Screen

Full Screen

validation_resources.py

Source:validation_resources.py Github

copy

Full Screen

1# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.2# Licensed under the Apache License, Version 2.0 (the "License");3# you may not use this file except in compliance with the License.4# You may obtain a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS,10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11# See the License for the specific language governing permissions and12# limitations under the License.13from oslo_log import log as logging14from automation.common import exceptions15from automation.common.utils import data_utils16from automation import config17CONF = config.CONF18LOG = logging.getLogger(__name__)19def create_ssh_security_group(os, add_rule=False):20 security_groups_client = os.security_groups_client21 security_group_rules_client = os.security_group_rules_client22 sg_name = data_utils.rand_name('securitygroup-')23 sg_description = data_utils.rand_name('description-')24 security_group = security_groups_client.create_security_group(25 name=sg_name, description=sg_description)26 if add_rule:27 security_group_rules_client.create_security_group_rule(28 parent_group_id=security_group['id'], ip_protocol='tcp',29 from_port=22, to_port=22)30 security_group_rules_client.create_security_group_rule(31 parent_group_id=security_group['id'], ip_protocol='icmp',32 from_port=-1, to_port=-1)33 LOG.debug("SSH Validation resource security group with tcp and icmp "34 "rules %s created"35 % sg_name)36 return security_group37def create_validation_resources(os, validation_resources=None):38 # Create and Return the validation resources required to validate a VM39 validation_data = {}40 if validation_resources:41 if validation_resources['keypair']:42 keypair_name = data_utils.rand_name('keypair')43 validation_data['keypair'] = \44 os.keypairs_client.create_keypair(name=keypair_name)45 LOG.debug("Validation resource key %s created" % keypair_name)46 add_rule = False47 if validation_resources['security_group']:48 if validation_resources['security_group_rules']:49 add_rule = True50 validation_data['security_group'] = \51 create_ssh_security_group(os, add_rule)52 if validation_resources['floating_ip']:53 floating_client = os.floating_ips_client54 validation_data['floating_ip'] = \55 floating_client.create_floating_ip()56 return validation_data57def clear_validation_resources(os, validation_data=None):58 # Cleanup the vm validation resources59 has_exception = None60 if validation_data:61 if 'keypair' in validation_data:62 keypair_client = os.keypairs_client63 keypair_name = validation_data['keypair']['name']64 try:65 keypair_client.delete_keypair(keypair_name)66 except exceptions.NotFound:67 LOG.warn("Keypair %s is not found when attempting to delete"68 % keypair_name)69 except Exception as exc:70 LOG.exception('Exception raised while deleting key %s'71 % keypair_name)72 if not has_exception:73 has_exception = exc74 if 'security_group' in validation_data:75 security_group_client = os.security_groups_client76 sec_id = validation_data['security_group']['id']77 try:78 security_group_client.delete_security_group(sec_id)79 security_group_client.wait_for_resource_deletion(sec_id)80 except exceptions.NotFound:81 LOG.warn("Security group %s is not found when attempting to "82 " delete" % sec_id)83 except exceptions.Conflict as exc:84 LOG.exception('Conflict while deleting security '85 'group %s VM might not be deleted ' % sec_id)86 if not has_exception:87 has_exception = exc88 except Exception as exc:89 LOG.exception('Exception raised while deleting security '90 'group %s ' % sec_id)91 if not has_exception:92 has_exception = exc93 if 'floating_ip' in validation_data:94 floating_client = os.floating_ips_client95 fip_id = validation_data['floating_ip']['id']96 try:97 floating_client.delete_floating_ip(fip_id)98 except exceptions.NotFound:99 LOG.warn('Floating ip %s not found while attempting to delete'100 % fip_id)101 except Exception as exc:102 LOG.exception('Exception raised while deleting ip %s '103 % fip_id)104 if not has_exception:105 has_exception = exc106 if has_exception:...

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 SeleniumBase 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