Best Python code snippet using localstack_python
metamorphic_relations.py
Source:metamorphic_relations.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3import datetime 4#local5import util6from analyzes import metrics7from scripts.ACM_search import ACM8from scripts.IEEE_search import IEEE9from scripts.Springer_search import Springer10from scripts.SCOPUS_search import Scopus11from scripts.Scidirect_search import Scidirect12"""13 Will handle MR exections14"""15def MPublished(engine, keywords, driver):16 #get the time using a specific format17 starting_time = datetime.datetime.now().strftime('%H:%M:%S')18 results = []19 #source search20 source_string = util.create_search_string(keywords, engine)21 #create the bots22 acm_bot = ACM(source_string,driver)23 ieee_bot = IEEE(source_string,driver)24 scidirect_bot = Scidirect(source_string,driver)25 scopus_bot = Scopus(source_string,driver)26 springer_bot = Springer(source_string,driver)27 #number of results, papers list, conferences list28 source_results = []29 #get the source query results30 if engine == "ACM":31 source_results = acm_bot.test_ACM()32 if engine == "IEEE":33 source_results = ieee_bot.test_IEEE()34 if engine == "Scidirect":35 source_results = scidirect_bot.test_scidirect()36 if engine == "Springer":37 source_results = springer_bot.test_springer()38 if engine == "Scopus":39 source_results = scopus_bot.test_Scopus()40 41 #get the list of papers and conferences from source query42 source_papers = source_results[1]43 conferences_list = source_results[2]44 45 46 #surround by try to avoid exceptions47 try:48 #get the first paper name 49 first_paper = source_papers[0]50 except:51 first_paper = ''52 try:53 #conference of the first paper54 first_conference = conferences_list[0]55 except:56 first_conference = ''57 #generate the followup string58 follow_string = util.create_search_string(keywords, engine, conference= first_conference)59 #create a new instance of the bots60 acm_bot = ACM(follow_string, driver)61 ieee_bot = IEEE(follow_string, driver)62 scidirect_bot = Scidirect(follow_string, driver)63 scopus_bot = Scopus(follow_string, driver)64 springer_bot = Springer(follow_string, driver)65 follow_up_results = []66 #get the followup query results67 if engine == "ACM":68 follow_up_results = acm_bot.test_ACM()69 if engine == "IEEE":70 follow_up_results = ieee_bot.test_IEEE()71 if engine == "Scidirect":72 #Scidirect limitation.. Strings bigger than 255 chars are not suported. End the execution and sent a False value to not registre the entry73 if(len(follow_string) > 255):74 print("W: Follow-up string exceeds the allowed size limit for the base! This execution will be aborted and will not be logged.")75 return [], False76 77 follow_up_results = scidirect_bot.test_scidirect()78 if engine == "Springer":79 follow_up_results = springer_bot.test_springer()80 if engine == "Scopus":81 follow_up_results = scopus_bot.test_Scopus()82 83 #papers from follow up query84 try:85 followup_papers = follow_up_results[1]86 except:87 followup_papers = []88 if first_paper in followup_papers:89 #working good90 fault = False91 else:92 #there is a bug93 fault = True94 results = [source_string] + source_results + [follow_string] + follow_up_results + [fault] + [starting_time]95 #add an extra return value to ensure that the execution runned as expected96 return results, True97def MPTitle(engine, keywords, driver):98 #get the time using a specific format99 starting_time = datetime.datetime.now().strftime('%H:%M:%S')100 results = []101 #source search102 source_string = util.create_search_string(keywords, engine)103 #create the bots104 acm_bot = ACM(source_string,driver)105 ieee_bot = IEEE(source_string,driver)106 scidirect_bot = Scidirect(source_string,driver)107 scopus_bot = Scopus(source_string,driver)108 springer_bot = Springer(source_string,driver)109 source_results = []110 #get the source query results111 if engine == "ACM":112 source_results = acm_bot.test_ACM()113 if engine == "IEEE":114 source_results = ieee_bot.test_IEEE()115 if engine == "Scidirect":116 source_results = scidirect_bot.test_scidirect()117 if engine == "Springer":118 source_results = springer_bot.test_springer()119 if engine == "Scopus":120 source_results = scopus_bot.test_Scopus()121 #get the list of papers and conferences from source query122 source_papers = source_results[1]123 conferences_list = source_results[2]124 125 126 #surround by try to avoid exceptions127 try:128 #get the first paper name 129 first_paper = source_papers[0]130 except:131 first_paper = ''132 try:133 #conference of the first paper134 first_conference = conferences_list[0]135 except:136 first_conference = ''137 #generate the followup string138 follow_string = util.create_search_string(keywords, engine, title= first_paper)139 #create a new instance of the bots140 acm_bot = ACM(follow_string, driver)141 ieee_bot = IEEE(follow_string, driver)142 scidirect_bot = Scidirect(follow_string, driver)143 scopus_bot = Scopus(follow_string, driver)144 springer_bot = Springer(follow_string, driver)145 follow_up_results = []146 #get the followup query results147 if engine == "ACM":148 follow_up_results = acm_bot.test_ACM()149 if engine == "IEEE":150 follow_up_results = ieee_bot.test_IEEE()151 if engine == "Scidirect":152 #Scidirect limitation.. Strings bigger than 255 chars are not suported. End the execution and sent a False value to not registre the entry153 if(len(follow_string) > 255):154 print("W: Follow-up string exceeds the allowed size limit for the base! This execution will be aborted and will not be logged.")155 return [], False 156 157 follow_up_results = scidirect_bot.test_scidirect()158 if engine == "Springer":159 follow_up_results = springer_bot.test_springer()160 if engine == "Scopus":161 follow_up_results = scopus_bot.test_Scopus()162 163 #papers from follow up query164 try:165 followup_papers = follow_up_results[1]166 except:167 followup_papers = []168 if first_paper in followup_papers:169 #working good170 fault = False171 else:172 #there is a bug173 fault = True174 results = [source_string] + source_results + [follow_string] + follow_up_results + [fault] + [starting_time]175 #add an extra return value to ensure that the execution runned as expected176 return results, True177def MPShuffleJD(engine, keywords, driver):178 179 #get the time using a specific format180 starting_time = datetime.datetime.now().strftime('%H:%M:%S')181 results = []182 #source search183 source_string = util.create_search_string(keywords, engine)184 #create the bots185 acm_bot = ACM(source_string,driver)186 ieee_bot = IEEE(source_string,driver)187 scidirect_bot = Scidirect(source_string,driver)188 scopus_bot = Scopus(source_string,driver)189 springer_bot = Springer(source_string,driver)190 source_results = []191 #get the source query results192 if engine == "ACM":193 source_results = acm_bot.test_ACM()194 if engine == "IEEE":195 source_results = ieee_bot.test_IEEE()196 if engine == "Scidirect":197 source_results = scidirect_bot.test_scidirect()198 if engine == "Springer":199 source_results = springer_bot.test_springer()200 if engine == "Scopus":201 source_results = scopus_bot.test_Scopus()202 203 #shufle the keywords204 from random import shuffle205 shuffle(keywords)206 #generate the followup string207 follow_string = util.create_search_string(keywords, engine)208 #create a new instance of the bots209 acm_bot = ACM(follow_string, driver)210 ieee_bot = IEEE(follow_string, driver)211 scidirect_bot = Scidirect(follow_string, driver)212 scopus_bot = Scopus(follow_string, driver)213 springer_bot = Springer(follow_string, driver)214 follow_up_results = []215 #get the followup query results216 if engine == "ACM":217 follow_up_results = acm_bot.test_ACM()218 if engine == "IEEE":219 follow_up_results = ieee_bot.test_IEEE()220 if engine == "Scidirect":221 #Scidirect limitation.. Strings bigger than 255 chars are not suported. End the execution and sent a False value to not registre the entry222 if(len(follow_string) > 255):223 print("W: Follow-up string exceeds the allowed size limit for the base! This execution will be aborted and will not be logged.")224 return [], False225 follow_up_results = scidirect_bot.test_scidirect()226 if engine == "Springer":227 follow_up_results = springer_bot.test_springer()228 if engine == "Scopus":229 follow_up_results = scopus_bot.test_Scopus()230 #get the first paper from source query231 try:232 num_source = source_results[0]233 except:234 num_source = 0235 try:236 source_papers = source_results[1]237 except:238 source_papers = []239 240 #get followup results241 try:242 num_followup = follow_up_results[0]243 except:244 num_followup = 0245 try:246 followup_papers = follow_up_results[1]247 except:248 followup_papers = []249 250 #If the number of results is diferent then found a anomaly251 if num_source == num_followup:252 anon = False253 else:254 anon = True255 #check similarity from both results256 jaccard = metrics.check_similarity(source_papers, followup_papers)257 results = [source_string] + source_results + [follow_string] + follow_up_results + [anon] + [jaccard] + [starting_time]258 #add an extra return value to ensure that the execution runned as expected259 return results, True260def Top1Absent(engine, keywords, driver):261 #get the time using a specific format262 starting_time = datetime.datetime.now().strftime('%H:%M:%S')263 results = []264 #source search265 source_string = util.create_search_string(keywords, engine)266 #create the bots267 acm_bot = ACM(source_string,driver)268 ieee_bot = IEEE(source_string,driver)269 scidirect_bot = Scidirect(source_string,driver)270 scopus_bot = Scopus(source_string,driver)271 springer_bot = Springer(source_string,driver)272 source_results = []273 #get the source query results274 if engine == "ACM":275 source_results = acm_bot.test_ACM()276 if engine == "IEEE":277 source_results = ieee_bot.test_IEEE()278 if engine == "Scidirect":279 source_results = scidirect_bot.test_scidirect()280 if engine == "Springer":281 source_results = springer_bot.test_springer()282 if engine == "Scopus":283 source_results = scopus_bot.test_Scopus()284 #get the list of papers and conferences from source query285 source_papers = source_results[1]286 conferences_list = source_results[2]287 288 289 #surround by try to avoid exceptions290 try:291 #get the first paper name 292 first_paper = source_papers[0]293 except:294 first_paper = ''295 try:296 #conference of the first paper297 first_conference = conferences_list[0]298 except:299 first_conference = ''300 #generate the followup string301 follow_string = util.create_search_string(keywords, engine, title= first_paper)302 #create a new instance of the bots303 acm_bot = ACM(follow_string, driver)304 ieee_bot = IEEE(follow_string, driver)305 scidirect_bot = Scidirect(follow_string, driver)306 scopus_bot = Scopus(follow_string, driver)307 springer_bot = Springer(follow_string, driver)308 follow_up_results = []309 #get the followup query results310 if engine == "ACM":311 follow_up_results = acm_bot.test_ACM()312 if engine == "IEEE":313 follow_up_results = ieee_bot.test_IEEE()314 if engine == "Scidirect":315 #Scidirect limitation.. Strings bigger than 255 chars are not suported. End the execution and sent a False value to not registre the entry316 if(len(follow_string) > 255):317 print("W: Follow-up string exceeds the allowed size limit for the base! This execution will be aborted and will not be logged.")318 return [], False319 320 follow_up_results = scidirect_bot.test_scidirect()321 if engine == "Springer":322 follow_up_results = springer_bot.test_springer()323 if engine == "Scopus":324 follow_up_results = scopus_bot.test_Scopus()325 326 #papers from follow up query327 try:328 followup_papers = follow_up_results[1]329 except:330 followup_papers = []331 try:332 first_followup_paper = follow_up_results[1]333 except:334 first_followup_paper = ''335 #check if the first paper of both query is equal336 if (first_paper == first_followup_paper) and (first_paper != ''):337 #working good338 fault = False339 else:340 #there is a bug341 fault = True342 results = [source_string] + source_results + [follow_string] + follow_up_results + [fault] + [starting_time]343 #add an extra return value to ensure that the execution runned as expected...
test.py
Source:test.py
...10headers = {11 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36',12}1314def test_acm():15 url = 'https://dl.acm.org/citation.cfm?doid=3092627.3092632'16 response = tools.requestsGet(url, headers=headers)17 # print(response.content)18 # print(response.text)19 # with open('test.html', 'w', encoding='utf-8') as f:20 # f.write(response.text)21 # f.close()22 html = etree.HTML(response.text)23 # aTags = html.xpath('//a')24 # for aTag in aTags:25 # print(aTag.text)2627 aTag = html.xpath('//a[contains(@title, "FullText PDF")]')[0]28 print(aTag.xpath('./text()'))29 imgTag = html.xpath('//a[contains(@title, "FullText PDF")]/img')[0]30 print(imgTag.tail)31 # aTag = html.xpath('//a[contains(@title, "Author Profile Page")]')[0]32 # print(aTag.text)33 # aTag.text = 'lance'34 # print(aTag.text)3536def test_ieee():37 url = 'https://ieeexplore.ieee.org/document/915037'38 response = tools.requestsGet(url, headers=headers)39 print(response.text)40 html = etree.HTML(response.text)41 pdfTag = html.xpath('//*[@id="LayoutWrapper"]/div/div/div/div[5]/div[2]/xpl-root/xpl-document-details/div/div[1]/section[2]/div/xpl-document-header/section/div[2]/div/div/div[3]/div[2]/div[2]/xpl-document-toolbar/div/div/ul/li[1]/a')42 print(pdfTag)434445if __name__ == '__main__':46 # test_acm()
...
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!!