Best Python code snippet using pyresttest_python
piece_test.py
Source:piece_test.py
...7 def tearDown(self):8 pass9 def testNoAuthor(self):10 # æ®éå¥å11 self.assertEqual(piece.parse_content(u"æ¯ä¸ªäººçå¿éï¼æå¤ä¹é¿çä¸ä¸ªæ¸
åï¼è¿äºæ¸
åéåçå¤å°ç¾å¥½çäºï¼å¯æ¯ï¼å®ä»¬æ»æ¯è¢«æ¨è¿ï¼è¢«æç½®ï¼å¨æ¶é´çé楼ä¸è
çã为ä»ä¹åæ°çé®é¢æ»æ¯è¢«è¯¯ä»¥ä¸ºæ¯æ¶é´çé®é¢ï¼èé£äºæ²éçãæéçãä¸å¾å·²çï¼æ»æ¯è¢«å«åçæ´»æ¬èº«ã"),{12 "content":u"æ¯ä¸ªäººçå¿éï¼æå¤ä¹é¿çä¸ä¸ªæ¸
åï¼è¿äºæ¸
åéåçå¤å°ç¾å¥½çäºï¼å¯æ¯ï¼å®ä»¬æ»æ¯è¢«æ¨è¿ï¼è¢«æç½®ï¼å¨æ¶é´çé楼ä¸è
çã为ä»ä¹åæ°çé®é¢æ»æ¯è¢«è¯¯ä»¥ä¸ºæ¯æ¶é´çé®é¢ï¼èé£äºæ²éçãæéçãä¸å¾å·²çï¼æ»æ¯è¢«å«åçæ´»æ¬èº«ã",13 "author":None,14 "work":None15 })16 def testPureEnglishWithOneWord(self):17 self.assertEqual(piece.parse_content(u"Mac-talk."),{18 "content":u"Mac-talk.",19 "author":None,20 "work":None21 })22 def testTooManySpliter(self):23 # è¿å¤é¾æ¥ç¬¦å¿½ç¥24 self.assertEqual(piece.parse_content("https://stacksocial.com/sales/the-mac-freebie-bundle-2-0"),{25 "content":"https://stacksocial.com/sales/the-mac-freebie-bundle-2-0",26 "author":None,27 "work":None28 })29 def testByIssue(self):30 self.assertEqual(piece.parse_content(u"It's better to fail than to pass by pure luck."),{31 "content":u"It's better to fail than to pass by pure luck.",32 "author":None,33 "work":None34 })35 def testAuthorSentance(self):36 self.assertEqual(piece.parse_content(u"æä¼å±ææç¥é\n对äºè¯å®¡ç»æè¿æ ·çè¯å®\næä¹ç»äºè¯å®\n----çè²ï¼éæ²çåäºå±æ佳女æ¼å±äººå¾çæè¨"),{37 "content":u"æä¼å±ææç¥é\n对äºè¯å®¡ç»æè¿æ ·çè¯å®\næä¹ç»äºè¯å®\n----çè²ï¼éæ²çåäºå±æ佳女æ¼å±äººå¾çæè¨",38 "author":None,39 "work":None40 })41 def testParseContent(self):42 """ testParseContent """43 self.assertEqual(piece.parse_content(u"æè ¢ç人饱åå
¶æè ¢æ带æ¥çç²ç´¯ä¹è¦ã by åæ¬å"),{44 "content":u"æè ¢ç人饱åå
¶æè ¢æ带æ¥çç²ç´¯ä¹è¦ã",45 "author":u"åæ¬å",46 "work":None47 })48 # 带è¨è¯´è
49 self.assertEqual(piece.parse_content(u"æ们ç»å°æµç¶ä¸ä½ï¼å°±å水溶äºæ°´ã \nââæ´é"),{50 "content":u"æ们ç»å°æµç¶ä¸ä½ï¼å°±å水溶äºæ°´ã",51 "author":u'æ´é',52 "work":None53 })54 # ä¸è§èç ´æ ------55 self.assertEqual(piece.parse_content(u"é»éçæ¯ä¸ä¸ªå¥å¦çä¸è¥¿ï¼è°æ¥æäºå®ï¼è°å°±æ为ä»æ³è¦çä¸åä¸è¥¿ç主人ï¼æäºé»éï¼çè³å¯ä»¥ä½¿çµéåå
¥å¤©å ã-------å¥ä¼¦å¸"),{56 "content":u"é»éçæ¯ä¸ä¸ªå¥å¦çä¸è¥¿ï¼è°æ¥æäºå®ï¼è°å°±æ为ä»æ³è¦çä¸åä¸è¥¿ç主人ï¼æäºé»éï¼çè³å¯ä»¥ä½¿çµéåå
¥å¤©å ã",57 "author":u"å¥ä¼¦å¸",58 "work":None59 })60 # 人å61 self.assertEqual(piece.parse_content(u"å½ä¸ææµè¡ä¸å¤§ç
çï¼æ延çã强迫çãéæ©å°é¾çï¼ç´ç½ç¹è¯´å°±æ¯æãè´±ãç©·ã----@çé»wario"),{62 "content":u"å½ä¸ææµè¡ä¸å¤§ç
çï¼æ延çã强迫çãéæ©å°é¾çï¼ç´ç½ç¹è¯´å°±æ¯æãè´±ãç©·ã",63 "author":u"@çé»wario",64 "work":None65 })66 # 书å67 self.assertEqual(piece.parse_content(u"æä¸ç´åæçä¸ä¸ªä¿¡å¿µæ¯ï¼æ¹åä¸äºå¤§ç¯å¢ï¼å°±æ¹åå°ç¯å¢ï¼åèªå·±åæè½åçäºæ
ãä½ ä¸è½å³å®å¤ªé³å ç¹åèµ·ï¼ä½å¯ä»¥å³å®èªå·±å ç¹èµ·åºãââãèªç±å¨é«å¤ã"),{68 "content":u"æä¸ç´åæçä¸ä¸ªä¿¡å¿µæ¯ï¼æ¹åä¸äºå¤§ç¯å¢ï¼å°±æ¹åå°ç¯å¢ï¼åèªå·±åæè½åçäºæ
ãä½ ä¸è½å³å®å¤ªé³å ç¹åèµ·ï¼ä½å¯ä»¥å³å®èªå·±å ç¹èµ·åºã",69 "author":None,70 "work":u"èªç±å¨é«å¤"71 })72 # 人åå书å73 self.assertEqual(piece.parse_content(u"ææ¶åï¼ä½ å¾æ³å¿µä¸ä¸ªäººï¼ä½ä½ ä¸ä¼æçµè¯ç»ä»ãæçµè¯ç»ä»ï¼ä¸ç¥é说çä¹å¥½ï¼è¿æ¯ä¸ææ¯è¾å¥½ãæ³å¿µä¸ä¸ªäººï¼ä¸ä¸å®è¦å¬å°ä»ç声é³ãå¬å°äºä»ç声é³ä¹è®¸å°±æ¯å¦ä¸åäºã æ³åä¸çä¸åå¾å¾æ¯ç°å®ç¨å¾®ç¾å¥½ä¸ç¹ãæ³å¿µä¸çé£ä¸ªäººä¹æ¯ç°å®ç¨å¾®æ¸©æä¸ç¹ãââ 约翰·èå°æ¯ã许æ¿æ ã"),{74 "content":u"ææ¶åï¼ä½ å¾æ³å¿µä¸ä¸ªäººï¼ä½ä½ ä¸ä¼æçµè¯ç»ä»ãæçµè¯ç»ä»ï¼ä¸ç¥é说çä¹å¥½ï¼è¿æ¯ä¸ææ¯è¾å¥½ãæ³å¿µä¸ä¸ªäººï¼ä¸ä¸å®è¦å¬å°ä»ç声é³ãå¬å°äºä»ç声é³ä¹è®¸å°±æ¯å¦ä¸åäºã æ³åä¸çä¸åå¾å¾æ¯ç°å®ç¨å¾®ç¾å¥½ä¸ç¹ãæ³å¿µä¸çé£ä¸ªäººä¹æ¯ç°å®ç¨å¾®æ¸©æä¸ç¹ã",75 "author":u"约翰·èå°æ¯",76 "work":u"许æ¿æ "77 })78 self.assertEqual(piece.parse_content(u"æ°¸è¿ä¸è¦å¿è®°ï¼ç´è³ä¸å¸å人æ示åºæªæ¥ä¹æ¥ï¼äººç±»å
¨é¨æºæ
§å°±å
å«å¨ä¸¤ä¸ªè¯ä¸ï¼çå¾
åå¸æã âãåºç£å±±ä¼¯çµã"),{79 "content":u"æ°¸è¿ä¸è¦å¿è®°ï¼ç´è³ä¸å¸å人æ示åºæªæ¥ä¹æ¥ï¼äººç±»å
¨é¨æºæ
§å°±å
å«å¨ä¸¤ä¸ªè¯ä¸ï¼çå¾
åå¸æã",80 "author": None,81 "work": u"åºç£å±±ä¼¯çµ"82 })83 # è±æ人å书å84 self.assertEqual(piece.parse_content(u"To choose doubt as a philosophy of life is akin to choosing immobility as a means of transportation. ââ Yann Martel ãLife of Piã"),{85 "content":u"To choose doubt as a philosophy of life is akin to choosing immobility as a means of transportation.",86 "author":u"Yann Martel",87 "work":u"Life of Pi"88 })89 # è±æ人å90 self.assertEqual(piece.parse_content(u"qweqweq qwe q we qw eqw ew ââ qweqwe"),{91 "content":u"qweqweq qwe q we qw eqw ew",92 "author":u"qweqwe",93 "work":None94 })95 # è¿é¿ä¸æ认为é人å96 self.assertEqual(piece.parse_content(u"æ°ï¼æåæçå°ä¼ä¼´ä»¬é½æåäºï¼\n\nãã\n\nããé®ï¼ä¸ºä»ä¹æåäºï¼\n\nãã--è¿ä¸ªè¯¥æä¹åç"),{97 "content":u"æ°ï¼æåæçå°ä¼ä¼´ä»¬é½æåäºï¼\n\nãã\n\nããé®ï¼ä¸ºä»ä¹æåäºï¼\n\nãã--è¿ä¸ªè¯¥æä¹åç",98 "author":None,99 "work":None...
scrapy_oxford.py
Source:scrapy_oxford.py
...12 elements_set = set(elements)13 seed_list = list(elements_set)14 seed_list.remove('')15 return seed_list16def parse_content(response, str_xpath):17 return ' '.join(response.xpath(str_xpath).extract())18class ScrapyOxfordSpider(scrapy.Spider):19 words = ConvertCSVfileToList()20 for (wrong, correct) in match_words:21 words[words.index(wrong)] = correct22 name = 'scrapy_oxford'23 allowed_domains = ['www.lexico.com/en/definition']24 start_urls = ['https://www.lexico.com/en/definition/' + word for word in words]25 def parse(self, response):26 word = response.request.url.split("/")[-1]27 item = []28 item.append(response.xpath('//span[contains(@class,"hw")]/text()').extract()[0] + "\n")29 for section in response.xpath('//*[@id="content"]/div[1]/div[2]/div/div/div/div/section'):30 for trg in section.xpath('./ul/li'):31 item.append(parse_content(trg,'./div/p/span[contains(@class,"ind")]/text()')+"\n")32 item.append(parse_content(trg,'./div/div[contains(@class,"exg")]/div/em/span/text()').replace("â","").replace("â","") + "\n")33 for list in trg.xpath('./div/div[contains(@class,"examples")]/div[contains(@class,"exg")]/ul/li'):34 item.append(parse_content(list,'./em/text()').replace("â","").replace("â","") + "\n")35 print(list.xpath('./em/text()').extract())36 #ol subSenses37 for subSenses in trg.xpath('./div/ol/li'):38 item.append(parse_content(subSenses,'./span[contains(@class,"ind")]/text()') + "\n")39 sub_discription = parse_content(subSenses,'./div[2]/div/em/span[contains(@class," one-click-content")]/text()')40 item.append(sub_discription.replace("â","").replace("â","").lstrip()+"\n")41 for subSenses_example_sentence in subSenses.xpath('./div[3]/div[2]/ul/li'):42 item.append(parse_content(subSenses_example_sentence,'./em/text()').replace("â","").replace("â","") + '\n')43 with open('./data/' + word +'.txt','w',encoding='UTF-8') as f:44 for element in item:45 f.write(str(element))...
domain.py
Source:domain.py
1# -*- coding: utf-8 -*-2import json3import logging4from pyquery import PyQuery5from backend.template import Template6from backend.util import send_request7logger = logging.getLogger(__name__)8class Domain(object):9 def __init__(self, name, parse_content=False, only_active=True, only_unprocessed=True):10 self.name = name11 self.url = "https://instantview.telegram.org/contest/{}/".format(name)12 self.templates = []13 self.parse_content = parse_content14 self.only_active = only_active15 self.only_unprocessed = only_unprocessed16 if parse_content:17 self.parse_templates()18 def add_template(self, creator=None, url=None, template=None):19 if template is None:20 logger.info("New template: {} - {}".format(creator, url))21 self.templates.append(Template(creator=creator, url=url, parse_content=self.parse_content, domain=self.name, only_unprocessed=self.only_unprocessed))22 else:23 logger.info("New template: {} - {}".format(template.creator, template.url))24 self.templates.append(template)25 def parse_templates(self):26 if len(self.templates) > 0:27 logger.error("There are already templates in here!")28 return29 domain_site = send_request(self.url)30 pq = PyQuery(domain_site)31 # Only get active templates32 if self.only_active:33 site_templates = pq(".list-group-contest").eq(0)34 else:35 # Otherwise parse rejected templates as well36 site_templates = pq(".list-group-contest")37 for template in site_templates.items(".list-group-contest-item"):38 creator = template(".contest-item-author > a").text()39 template_url = template(".contest-item-num > a").attr("href")40 self.add_template(creator, "https://instantview.telegram.org{}".format(template_url))41 def to_dict(self):42 return dict(name=self.name, url=self.url, templates=self.templates)43 @staticmethod44 def from_dict(domain_dict):45 name = domain_dict.get("name")46 url = domain_dict.get("url")47 domain = Domain(name, parse_content=False)48 templates = domain_dict.get("templates")49 for template in templates:50 template_o = Template.from_dict(template)51 domain.add_template(template=template_o)52 return domain53 def to_json(self):54 return json.dumps(self.to_dict())55 def __dict__(self):...
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!!