Best Python code snippet using autotest_python
CommonData.py
Source: CommonData.py
...29 def get_datatable_config(self):30 return self.config.get_datatable_config()31 def get_initdata(self,name):32 return self.config.get_initdata(name)33 def get_test_database(self):34 return self.config.get_test_database()35 def get_test_database_case_mapping(self):36 return self.config.get_test_database_case_mapping()37 ## è®°å½å½åç¨ä¾è¿è¡æ¨¡ååç¨ä¾ã sessionï¼moudelï¼function 3个级å«ã38 def setup_runObject(self,name):39 self.runCaseObject.append(name)40 def teardown_runObject(self):41 # æåä¸ä¸ªæ¯defaultï¼ä¿çå¨å¯¹è±¡ä¸é¿å
被éæ¾42 if len(self.runCaseObject)>1:43 self.runCaseObject.pop()44 else:45 pass46 def get_database_parms(self,source_name):47 # if len(self.runCaseObject)==1 and source_name is None:48 # # ç´æ¥è¿åé»è®¤æ°æ®åºé
ç½®49 # return self.get_test_database()[self.runCaseObject[0]]50 # data_mapping=self.get_test_database_case_mapping()51 # reCaseObject=self.runCaseObject.reverse()52 # for name in reCaseObject:53 # if name in data_mapping:54 # return self.get_test_database()[self.runCaseObject[name]]55 if source_name:56 return self.get_test_database()[source_name]57 else:58 return self.get_test_database()['default']59 raise DataBaseError("è·åæ°æ®å¯¹åºé
ç½®åæ°åºéï¼è¯·æ£æ¥Settingæ件ä¸æ¯å¦é
ç½®æ£ç¡®ã")60 def _check_isin_datamapping(self,name):61 pass62 def _getConfigObject(self,rags):63 # jsonfile_path 为èçæ¬éçå称 èçæ¬åªæ¯æ skisetting.json ä¸ç§æ ¼å¼ã1.5.0çæ¬ä¹åæ©å±æ¯æå¤ç§çæ¬çé
ç½®æ件ãåéåæªå64 (configfile_path, configfile_name) = os.path.split(rags.jsonfile_path)65 extname = configfile_name.split(".")[-1:] # è·åæ©å±åç¨äºå¤æ66 if extname[0] == "json":67 return JsonConfigObject(rags)68 elif extname[0] =="py":69 return PyfileConfigObject(rags)70class ConfigObject():71 def __init__(self,rags):72 self.config={}73 def get_setting_data(self):74 try:75 return self.config.KW_ROUTER76 except:77 raise SettingFileError("没ææ¾å°{0}é
ç½®ï¼è¯·æ£æ¥é
ç½®æ件ï¼æ¯å¦å
å«{0} é
ç½®".format('KW_ROUTER'))78 def get_global_all_data(self):79 try:80 return self.config.GLOBAL_VARIABLE81 except:82 raise SettingFileError("没ææ¾å°{0}é
ç½®ï¼è¯·æ£æ¥é
ç½®æ件ï¼æ¯å¦å
å«{0} é
ç½®".format('GLOBAL_VARIABLE'))83 def get_global_data(self, value):84 try:85 return self.config.GLOBAL_VARIABLE[value]86 except:87 raise SettingFileError("没ææ¾å°{0}.{1}é
ç½®ï¼è¯·æ£æ¥é
ç½®æ件ï¼æ¯å¦å
å«{0}.{1} é
ç½®".format('GLOBAL_VARIABLE',value))88 def add_global_data(self, data):89 try:90 for s in data:91 self.config.GLOBAL_VARIABLE[s] = data[s]92 except:93 raise SettingFileError("æ·»å å
¨å±åéå¼å¸¸")94 def get_datatable_config(self):95 try:96 return self.config.DATATABLE97 except:98 raise SettingFileError("没ææ¾å°{0}é
ç½®ï¼è¯·æ£æ¥é
ç½®æ件ï¼æ¯å¦å
å«{0} åé".format('DATATABLE'))99 def get_initdata(self, name):100 try:101 return self.config.initdata['name']102 except:103 raise SettingFileError("没ææ¾å°{0}é
ç½®ï¼è¯·æ£æ¥é
ç½®æ件ï¼æ¯å¦å
å«{0} é
ç½®".format('TEST_DATABASES'))104 def get_test_database(self):105 try:106 return self.config.TEST_DATABASES107 except Exception as e:108 raise SettingFileError(e,"没ææ¾å°{0}é
ç½®ï¼è¯·æ£æ¥é
ç½®æ件ï¼æ¯å¦å
å«{0} é
ç½® config ï¼{1}".format('TEST_DATABASES',self.config))109 def get_test_database_case_mapping(self):110 try:111 return self.config.TEST_DATABASE_CASE_MAPPING112 except:113 raise SettingFileError("没ææ¾å°{0}é
ç½®ï¼è¯·æ£æ¥é
ç½®æ件ï¼æ¯å¦å
å«{0} é
ç½®".format('TEST_DATABASE_APPS_MAPPING'))114class JsonConfigObject(ConfigObject):115 def __init__(self,rags):116 # jsonfile_path 为èçæ¬éçå称 èçæ¬åªæ¯æ skisetting.json ä¸ç§æ ¼å¼ã1.5.0çæ¬ä¹åæ©å±æ¯æå¤ç§çæ¬çé
ç½®æ件ãåéåæªå117 # (configfile_path, configfile_name) = os.path.split(rags.jsonfile_path)118 # extname = configfile_name.split(".")[-1:] # è·åæ©å±åç¨äºå¤æ...
test_test_database.py
Source: test_test_database.py
...9engine_test = sqlalchemy.create_engine(f"mysql://root:root@127.0.0.1/stock_data_storage")10database_test = Database(f"mysql+aiomysql://root:root@127.0.0.1/stock_data_storage")11stock_data_table = create_sa_stock_data_table("stock_data_201503")12@asynccontextmanager13async def get_test_database() -> Database:14 db = database_test15 await db.connect()16 try:17 yield db18 finally:19 await db.disconnect()20@pytest.fixture(scope="session")21def event_loop():22 loop = asyncio.get_event_loop()23 yield loop24 loop.close()25@pytest.mark.asyncio26async def test_connection():27 metadata.create_all(engine_test)28 async with get_test_database() as database_test:29 result = await database_test.fetch_all(query="show tables;")30 print(result)31@pytest.mark.asyncio32async def test_query():33 async with get_test_database() as database_test:34 print(await database_test.fetch_all(query="desc stock_data_201503;"))35 result = await database_test.fetch_one(query=select(stock_data_table))36 print(result)37@pytest.mark.asyncio38async def test_pandas():39 async with get_test_database() as database_test:40 result = await database_test.fetch_all(query=select(stock_data_table))41 print(pd.DataFrame((dict(row) for row in result)))42@pytest.mark.asyncio43async def test_get_task_table_names():44 async with get_test_database() as database_test:45 result = await get_task_table_names(database_test)...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!