Best Python code snippet using Airtest
test_locationmanager_model.py
Source:test_locationmanager_model.py
...37 def test_edit(self):38 assert_catch_exc(ConfigNotFoundError, self.model.edit)39 def test_copy(self):40 assert_catch_exc(ConfigNotFoundError, self.model.copy)41 def test_set_current(self):42 location = 'loation name'43 assert_catch_exc(ConfigNotFoundError, self.model.set_current, location)44 def test_set_current(self):45 loc = 046 assert_catch_exc(ConfigNotFoundError, self.model.set_current, loc)47 def test_set_default(self):48 location = 'location name'49 assert_catch_exc(ConfigNotFoundError,50 self.model.set_default, location)51 def test_get_config(self):52 config_dict = self.model.get_config_dict()53 assert_equal(config_dict, {})54 def test_set_config(self):55 config = 'aaa'56 assert_catch_exc(ConfigNotFoundError, self.model.set_config, config)57 def test_get_location_list(self):58 assert_equal( self.model.get_location_list(), [] )59 #def test_destroy(self):60 #assert True61class TestOneLocation:62 def setup(self):63 class LocationShower:64 def __init__(self): pass65 self.model = LocationManagerModel()66 shower = LocationShower()67 self.model.install(shower)68 self.model.create('test location')69 self.key_list = [70 'name', 'address', 'workdir',71 'ssh', 'environment', 'init_file', 'mpi_command', 'jms', 'commands'72 ]73 def with_selected(self):74 self.model.set_current( 'test location' )75 def test_init(self):76 assert_false( self.model.get_current() )77 assert_equal( len(self.model.get_location_list()), 1 )78 config = self.model.get_config_dict()79 self.with_selected()80 assert_true( self.model.get_current(), 'test location')81 #assert_equal( config.get('test location'), True)82 def test_create(self):83 name = 'second location'84 self.model.create(name)85 assert_equal( len(self.model.get_location_list()), 2 )86 expected = set(['test location', name])87 assert_equal( set( self.model.get_location_list() ), expected)88 assert_false( self.model.get_current() )89 def test_delete(self):90 assert_catch_exc(ConfigNotSelectedError, self.model.delete)91 self.with_selected()92 self.model.delete()93 assert_equal( len(self.model.get_location_list()), 0 )94 def test_edit(self):95 assert_catch_exc(ConfigNotSelectedError, self.model.edit)96 self.with_selected()97 ecatcher = EventCatcher(self.model.edit_event)98 self.model.edit()99 assert_catch_event(ecatcher)100 def test_copy(self):101 assert_catch_exc(ConfigNotSelectedError, self.model.delete)102 self.with_selected()103 self.model.copy()104 assert_equal( len(self.model.get_location_list()), 2 )105 assert_false( self.model.get_current() )106 def test_set_name(self):107 locname = 'changed location'108 assert_catch_exc(ConfigNotSelectedError, self.model.set_name, locname)109 self.with_selected()110 old_locname = self.model.get_current()111 self.model.set_name( locname )112 assert_equal( self.model.get_current(), locname )113 assert old_locname not in self.model.get_location_list()114 def test_set_default(self):115 # invalid116 loc = 'invalid locaiton'117 assert_catch_exc(ConfigNotFoundError, self.model.set_default, loc)118 # valid119 loc = 'test location'120 self.model.set_default(loc)121 assert_equal( self.model.get_default(), loc )122 def test_set_current(self):123 # invalid124 loc = 'invalid locaiton'125 assert_catch_exc(ConfigNotFoundError, self.model.set_current, loc)126 # valid127 loc = 'test location'128 self.model.set_current( loc )129 assert_equal( self.model.get_current() , loc)130 131 def test_get_config_dict(self):132 config = self.model.get_config_dict()['test location']133 ret_keyset = set( config.keys() )134 assert_equal( ret_keyset, set(self.key_list) )135 136 def test_set_config(self):137 assert_catch_exc(ConfigNotSelectedError, self.model.set_config, 'cog')138 self.with_selected()139 config = dict(140 name = 'new loc' , 141 address = '133.66.117.139' , 142 workdir = '/home/ishikura/Nagara' , 143 ssh = {} , 144 environment = '' , 145 init_file = '/etc/profile.local' , 146 mpi_command = 'mpijob mpirun' , 147 jms = '' , 148 commands = '' , 149 )150 config['ssh']['address'] = 'hpcs.med.nagaoya-u.ac.jp'151 config['ssh']['username'] = 'ishikura'152 config['ssh']['password'] = '********'153 config['ssh']['port'] = 22154 self.model.set_config(config)155 new_config = self.model.get_config_dict()['new loc']156 assert_equal(self.model.get_location_list(), ['new loc'] )157 assert_equal( new_config, config )158 def test_get_location_list(self):159 assert_equal( self.model.get_location_list(), ['test location'] )160 #def test_destroy(self):161 #pass162class TestMoreThanTwoLocation:163 def setup(self):164 class LocationShower:165 def __init__(self): pass166 self.model = LocationManagerModel()167 shower = LocationShower()168 self.model.install(shower)169 self.model.create('first location')170 self.model.create('second location')171 self.key_list = [172 'name', 'address', 'workdir',173 'ssh', 'environment', 'init_file', 'mpi_command', 'jms', 'commands'174 ]175 def with_selected(self):176 self.model.set_current( 'first location' )177 def test_init(self):178 assert_false( self.model.get_current() )179 assert_equal( len(self.model.get_location_list()), 2 )180 config = self.model.get_config_dict()181 self.with_selected()182 assert_true( self.model.get_current(), 'first location')183 #assert_equal( config.get('test location'), True)184 def test_create(self):185 name = 'third location'186 self.model.create(name)187 assert_equal( len(self.model.get_location_list()), 3 )188 expected = set(['first location', 'second location', name])189 assert_equal( set( self.model.get_location_list() ), expected)190 assert_false( self.model.get_current() )191 def test_delete(self):192 assert_catch_exc(ConfigNotSelectedError, self.model.delete)193 self.with_selected()194 self.model.delete()195 assert_equal( len(self.model.get_location_list()), 1 )196 def test_edit(self):197 assert_catch_exc(ConfigNotSelectedError, self.model.edit)198 self.with_selected()199 ecatcher = EventCatcher(self.model.edit_event)200 self.model.edit()201 assert_catch_event(ecatcher)202 def test_copy(self):203 assert_catch_exc(ConfigNotSelectedError, self.model.delete)204 self.with_selected()205 self.model.copy()206 assert_equal( len(self.model.get_location_list()), 3 )207 assert_false( self.model.get_current() )208 def test_set_name(self):209 locname = 'changed location'210 assert_catch_exc(ConfigNotSelectedError, self.model.set_name, locname)211 self.with_selected()212 old_locname = self.model.get_current()213 self.model.set_name( locname )214 assert_equal( self.model.get_current(), locname )215 assert old_locname not in self.model.get_location_list()216 def test_set_default(self):217 # invalid218 loc = 'invalid locaiton'219 assert_catch_exc(ConfigNotFoundError, self.model.set_default, loc)220 # valid221 loc = 'second location'222 self.model.set_default(loc)223 assert_equal( self.model.get_default(), loc )224 def test_set_current(self):225 # invalid226 loc = 'invalid locaiton'227 assert_catch_exc(ConfigNotFoundError, self.model.set_current, loc)228 # valid229 loc = 'first location'230 self.model.set_current( loc )231 assert_equal( self.model.get_current() , loc)232 loc = 'second location'233 self.model.set_current( loc )234 assert_equal( self.model.get_current() , loc)235 236 def test_get_config_dict(self):237 config = self.model.get_config_dict()['first location']238 ret_keyset = set( config.keys() )...
test_multiple_contexts.py
Source:test_multiple_contexts.py
...36 print(context.current)37 print(old)38 print(c1)39 self.assertTrue(context.current is old);40 def test_set_current(self):41 c1 = context.SimulationContext()42 c1.set_current();43 self.assertTrue(context.current is c1);44 c1.on_gpu();45if __name__ == '__main__':...
test_time.py
Source:test_time.py
...3 """4 :param rpcclient.client.Client client:5 """6 assert client.time.now() > datetime.fromtimestamp(0)7def test_set_current(client):8 """9 :param rpcclient.client.Client client:10 """11 old_now = client.time.now()12 try:13 client.time.set_current(datetime(year=2020, month=1, day=1))14 assert client.time.now() < datetime(year=2020, month=1, day=1, minute=1)15 finally:16 client.time.set_current(old_now)17 client.time.set_auto()18def test_is_set_automatically(client):19 """20 :param rpcclient.client.Client client:21 """...
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!!