Best Python code snippet using localstack_python
store_test.py
Source:store_test.py
...28 languages)29 def test_voc(self):30 self._create_vocabulary()31 self._create_user()32 vocs = self.db.list_vocabularies(self.user).values()33 self.assertEqual(1, len(vocs))34 self.assertEqual([self.word1, self.word2],35 next(iter(vocs)).words)36 voc2 = self.db.get_vocabulary(self.user, 1)37 self.assertEqual([self.word1, self.word2],38 voc2.words)39 def test_manage_sessions(self):40 self._create_vocabulary()41 self._create_user()42 self.assertIsNone(self.db.last_session(self.user, self.new_voc))43 session_id = self.db.create_new_session(self.user, self.new_voc)44 self.assertIsNotNone(session_id)45 session = self.db.last_session(self.user, self.new_voc)46 self.assertEqual(session_id.id, session.id)47 first_word = session.current_word48 self.assertTrue((self.word1 == session.current_word) or49 (self.word2 == session.current_word))50 word_attempt = session.guess(session.current_word,51 session.current_word.word_output)52 self.db.add_word_attempt(session, word_attempt)53 db_session = self.db.load_session(session.id)54 self.assertNotEqual(first_word, db_session.current_word)55 self.assertFalse(db_session.is_finished)56 self.assertIsNone(self.db.last_session(self.user, self.new_voc,57 finished=True))58 self.assertIsNotNone(self.db.last_session(self.user, self.new_voc,59 finished=False))60 word_attempt = session.guess(session.current_word,61 session.current_word.word_output)62 self.db.add_word_attempt(session, word_attempt)63 db_session = self.db.load_session(session.id)64 self.assertTrue(db_session.is_finished)65 self.assertEqual(100.0, db_session.accuracy)66 self.assertIsNone(self.db.last_session(self.user, self.new_voc,67 finished=False))68 self.assertIsNotNone(self.db.last_session(self.user, self.new_voc,69 finished=True))70 def test_vocabulary_stats(self):71 self._create_user()72 self._create_vocabulary()73 new_session = self.db.create_new_session(self.user, self.new_voc)74 word = new_session.current_word75 attempt = new_session.guess(word, 'bla')76 self.db.add_word_attempt(new_session, attempt)77 other_word = new_session.current_word78 stats = self.db.vocabulary_stats(self.new_voc)79 self.assertEqual(100.0, stats.errors_prob_for(word))80 self.assertEqual(0.0, stats.errors_prob_for(other_word))81 def test_user(self):82 self._create_user()83 self.assertIsNotNone(self.user)84 with self.assertRaises(DbException):85 self.db.create_user('test@hotmail.com', 'other', set())86 with self.assertRaises(DbException):87 self.db.get_user('test2@gmail.com', 'def')88 with self.assertRaises(DbException):89 self.db.get_user('test@hotmail.com', 'def')90 other_user = self.db.get_user('test@hotmail.com', 'abc')91 self.assertEqual('test@hotmail.com', other_user.email)92 def test_normal_vocabulary(self):93 self._create_vocabulary()94 self._create_user({Language.FRENCH})95 vocs = self.db.list_vocabularies(self.user)96 self.assertEqual(1, len(vocs))97 first_voc = next(iter(vocs.values()))98 self.assertFalse(first_voc.is_flipped)99 first_voc = self.db.get_vocabulary(self.user, first_voc.id)100 self.assertFalse(first_voc.is_flipped)101 self.assertEqual('fr', first_voc.input_language)102 self.assertEqual('de', first_voc.output_language)103 self.assertEqual([self.word1, self.word2],104 first_voc.words)105 new_session = self.db.create_new_session(self.user, first_voc)106 self.assertFalse(new_session.is_flipped)107 self.assertIn(new_session.current_word,108 {self.word1, self.word2})109 session_fetched = self.db.last_session(self.user, first_voc)110 self.assertIn(session_fetched.current_word,111 {self.word1, self.word2})112 session_fetched2 = self.db.load_session(session_fetched.id)113 self.assertIn(session_fetched2.current_word,114 {self.word1, self.word2})115 current_word = session_fetched.current_word116 attempt = session_fetched.guess(current_word, current_word.word_input)117 self.db.add_word_attempt(session_fetched, attempt)118 def test_flipped_vocabulary(self):119 self._create_vocabulary()120 self._create_user({Language.GERMAN})121 vocs = self.db.list_vocabularies(self.user)122 self.assertEqual(1, len(vocs))123 first_voc = next(iter(vocs.values()))124 first_voc = self.db.get_vocabulary(self.user, first_voc.id)125 self.assertTrue(first_voc.is_flipped)126 self.assertEqual('de', first_voc.input_language)127 self.assertEqual('fr', first_voc.output_language)128 self.assertEqual([self.word1.flip(), self.word2.flip()],129 first_voc.words)130 new_session = self.db.create_new_session(self.user, first_voc)131 self.assertIn(new_session.current_word,132 {self.word1.flip(), self.word2.flip()})133 self.assertTrue(new_session.is_flipped)134 self.assertTrue(first_voc.is_flipped)135 session_fetched = self.db.last_session(self.user, first_voc)136 self.assertTrue(session_fetched.is_flipped)137 self.assertIn(session_fetched.current_word,138 {self.word1.flip(), self.word2.flip()})139 session_fetched2 = self.db.load_session(session_fetched.id)140 self.assertIn(session_fetched2.current_word,141 {self.word1.flip(), self.word2.flip()})142 current_word = session_fetched.current_word143 attempt = session_fetched.guess(current_word, current_word.word_input)144 self.db.add_word_attempt(session_fetched, attempt)145 def test_list_vocabulary(self):146 self._create_vocabulary()147 self._create_user()148 vocs = self.db.list_vocabularies_for(None)149 self.assertEqual({1}, vocs.keys())150 voc = next(iter(vocs.values()))151 self.assertEqual(self.new_voc.words, voc.words)152 self.assertIsNone(self.db.get_vocabulary(None, 2))153 self.assertEqual([self.word1, self.word2],154 self.db.get_vocabulary(None, 1).words)155 def test_same_name_several_times(self):156 word1 = Word(word_input='fr_1',157 word_output='de_1',158 directive=None)159 word2 = Word(word_input='fr_1',160 word_output='de_1',161 directive='#name')162 words = [word1, word2]163 new_voc = Vocabulary(word1, words,164 input_language='fr',165 output_language='de')166 self._create_user()167 self.db.create_vocabulary(new_voc)168 self.db.create_new_session(self.user, new_voc)169 session = self.db.last_session(self.user, new_voc)170 word_attempt = session.guess(word2, word2.word_output)171 self.db.add_word_attempt(session, word_attempt)172 self.assertTrue(word_attempt.success)173 self.db.last_session(self.user, new_voc)174 def test_remove_vocabulary(self):175 self._create_vocabulary()176 self._create_user()177 self.db.create_new_session(self.user, self.new_voc)178 session = self.db.last_session(self.user, self.new_voc)179 session.guess(self.word1, self.word1.word_output)180 self.db.remove_vocabulary(self.new_voc)181 self.assertEqual({}, self.db.list_vocabularies(None))182 def test_add_word(self):183 self._create_vocabulary()184 self._create_user()185 self.word3 = Word(word_input='fr_3',186 word_output='de_3',187 directive=None)188 self.db.add_word(self.new_voc, self.word3)189 self.db.update_word(self.new_voc, self.word3,190 word_input='fr_4',191 word_output='de_4',192 directive='#name')193 vocs = self.db.list_vocabularies(None)194 new_word = Word(word_input='fr_4',195 word_output='de_4',196 directive='#name')197 self.assertIn(new_word, vocs[self.new_voc.id].words)198 def test_save_same_words_twice(self):199 self._create_vocabulary()200 self._create_user()201 session_id = self.db.create_new_session(self.user, self.new_voc)202 self.assertIsNotNone(session_id)203 session = self.db.last_session(self.user, self.new_voc)204 self.assertEqual(session_id.id, session.id)205 first_word = session.current_word206 word_attempt = session.guess(session.current_word,207 session.current_word.word_output)...
lx.py
Source:lx.py
1import requests2url = 'https://www.shanbay.com/api/v1/vocabtest/category/'3headers = {'user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}4# 0: ["GMAT", "GMAT"]5# 1: ["NGEE", "èç "]6# 2: ["NCEE", "é«è"]7# 3: ["CET4", "å级"]8# 4: ["CET6", "å
级"]9# 5: ["TEM", "è±ä¸"]10# 6: ["TOEFL", "æç¦"]11# 7: ["GRE", "GRE"]12# 8: ["IELTS", "é
æ"]13# 9: ["NONE", "ä»»æ"]14res = requests.get(url, headers=headers)15res_json = res.json()16datas = res_json['data']17i = 018for data in datas:19 print(str(i) + '--' + str(data))20 i = i + 1 21choice = int(input('请è¾å
¥ä½ çéæ©ï¼'))22url1 = 'https://www.shanbay.com/api/v1/vocabtest/vocabularies/?' + datas[choice][0]23res = requests.get(url1, headers=headers)24#print(res.status_code)25voc_json = res.json()26vocabularies = voc_json['data']27list_vocabularies = []28for v in vocabularies:29 list_vocabularies.append(v['content'])30words_knows = []31not_knows = []32for i in range(50):33 print( str(i) + ' ' + list_vocabularies[i] + '\n')34 x = input('认è¯è¾å
¥1ï¼ä¸è®¤è¯è¾å
¥0ï¼')35 if x == '1':36 words_knows.append(list_vocabularies[i])37 else:38 not_knows.append(list_vocabularies[i])39print('ä½ è®¤è¯' + str(len(words_knows)) + '个åè¯\nåå«æ¯ï¼')40for i in range(len(words_knows)):41 print(words_knows[i])42 43# åèçæ¡ 44"""45import requests46link = requests.get('https://www.shanbay.com/api/v1/vocabtest/category/')47#å
ç¨requestsä¸è½½é¾æ¥ã48js_link = link.json()49#解æä¸è½½å¾å°çå
容ã50bianhao = int(input('''请è¾å
¥ä½ éæ©çè¯åºç¼å·ï¼æEnter确认511ï¼GMAT 2ï¼èç 3ï¼é«è 4ï¼å级 5ï¼å
级526ï¼è±ä¸ 7ï¼æç¦ 8ï¼GRE 9ï¼é
æ 10ï¼ä»»æ53>'''))54#让ç¨æ·éæ©èªå·±æ³æµçè¯åºï¼è¾å
¥æ°åç¼å·ãint()æ¥è½¬æ¢æ°æ®ç±»å55ciku = js_link['data'][bianhao-1][0]56#å©ç¨ç¨æ·è¾å
¥çæ°åç¼å·ï¼è·åé¢åºç代ç ãå¦æ以è¾å
¥âé«èâçç¼å·â3â为ä¾ï¼é£ä¹cikuçå¼å°±æ¯ï¼å¨åå
¸js_linkä¸æ¥æ¾dataçå¼ï¼dataæ¯ä¸ä¸ªlistï¼æ¥æ¾å®ç第bianhao-1ï¼ä¹å°±æ¯ç¬¬2个å
ç´ ï¼å¾å°çä¾ç¶æ¯ä¸ä¸ªlistï¼åæ¥æ¾è¯¥listç第0个å
ç´ ãæåå¾å°çå°±æ¯æ们æ³è¦çNCEEã57test = requests.get('https://www.shanbay.com/api/v1/vocabtest/vocabularies/?category='+ciku)58#ä¸è½½ç¨äºæµè¯ç50个åè¯ã59words = test.json()60#对testè¿è¡è§£æã61danci = []62#æ°å¢ä¸ä¸ªlistï¼ç¨äºç»è®¡ç¨æ·è®¤è¯çåè¯63words_knows = []64#å建ä¸ä¸ªç©ºçå表ï¼ç¨äºè®°å½ç¨æ·è®¤è¯çåè¯ã65not_knows = []66#å建ä¸ä¸ªç©ºçå表ï¼ç¨äºè®°å½ç¨æ·ä¸è®¤è¯çåè¯ã67print ('æµè¯ç°å¨å¼å§ãå¦æä½ è®¤è¯è¿ä¸ªåè¯ï¼è¯·è¾å
¥Yï¼å¦åç´æ¥æ²Enterï¼')68n=069for x in words['data']:70#å¯å¨ä¸ä¸ªå¾ªç¯ï¼å¾ªç¯ç次æ°çäºåè¯çæ°éã71 n=n+172 print ("\n第"+str(n)+'个ï¼'+x['content'])73 #å ä¸ä¸ª\nï¼ç¨äºæ¢è¡ã74 answer = input('认è¯è¯·æ²Yï¼å¦åæ²Enterï¼')75 #让ç¨æ·è¾å
¥èªå·±æ¯å¦è®¤è¯ã76 if answer == 'Y':77 #å¦æç¨æ·è®¤è¯ï¼78 danci.append(x['content'])79 words_knows.append(x)80 #å°±æè¿ä¸ªåè¯ï¼è¿½å è¿å表words_knowsã81 else:82 #å¦å83 not_knows.append(x)84 #å°±æè¿ä¸ªåè¯ï¼è¿½å è¿å表not_knowsã85print ('\nå¨ä¸è¿°'+str(len(words['data']))+'个åè¯å½ä¸ï¼æ'+str(len(danci))+'个æ¯ä½ è§å¾èªå·±è®¤è¯çï¼å®ä»¬æ¯ï¼')86print(danci)87print ('ç°å¨æ们æ¥æ£æµä¸ä¸ï¼ä½ æ没æçæ£ææ¡å®ä»¬ï¼')88wrong_words = []89right_num = 090for y in words_knows:91 print('\n\n'+'A:'+y['definition_choices'][0]['definition'])92 #æ们æ¹ç¨AãBãCãDï¼ä¸åç¨rankå¼ï¼ä¸å93 print('B:'+y['definition_choices'][1]['definition'])94 print('C:'+y['definition_choices'][2]['definition'])95 print('D:'+y['definition_choices'][3]['definition'])96 xuanze = input('请éæ©åè¯\"'+y['content']+'\"çæ£ç¡®ç¿»è¯ï¼å¡«åæ°åå³å¯ï¼ï¼')97 dic = {'A':y['definition_choices'][0]['rank'],'B':y['definition_choices'][1]['rank'],'C':y['definition_choices'][2]['rank'],'D':y['definition_choices'][3]['rank']} 98 #æ们å建ä¸ä¸ªåå
¸ï¼æ建起AãBãCãDåå个rankå¼çæ å°å
³ç³»ã99 if dic[xuanze] == y['rank']:100 #æ¤æ¶dic[xuanze]çå
容ï¼å
¶å®å°±æ¯rankå¼ï¼æ¤æ¶ç代ç å«ä¹å·²ç»åä¹åççæ¬ç¸åäºã101 right_num += 1102 else:103 wrong_words.append(y)104print ('ç°å¨ï¼å°äºå
¬å¸æ绩çæ¶å»:')105print ('å¨'+str(len(words['data']))+'个'+js_link['data'][bianhao-1][1]+'è¯æ±å½ä¸ï¼ä½ 认è¯å
¶ä¸'+str(len(danci))+'个ï¼å®é
ææ¡'+str(right_num)+'个ï¼é误'+str(len(wrong_words))+'个ã')106#è¿æ¯å¥è®å¤æçè¯ï¼å¯¹ç
§åé¢ç代ç åjsonæä»¶ä½ æè½ç解å®ãä¸ä¸ªè¿è¡ç¤ºä¾æ¯ï¼å¨50个é«èè¯æ±å½ä¸ï¼ä½ 认è¯å
¶ä¸30个ï¼å®é
ææ¡25个ï¼é误5个ã107save = input ('æ¯å¦æå°å¹¶ä¿åä½ çéè¯éï¼å¡«å
¥YæNï¼ ')108#询é®ç¨æ·ï¼æ¯å¦è¦æå°å¹¶ä¿åéé¢éã109if save == 'Y':110#å¦æç¨æ·è¯´æ¯ï¼111 f = open('éé¢é.txt', 'a+')112 #å¨å½åç®å½ä¸ï¼å建ä¸ä¸ªéé¢é.txtçææ¡£ã 113 print ('ä½ è®°éçåè¯æï¼')114 f.write('ä½ è®°éçåè¯æï¼\n')115 #åå
¥"ä½ è®°éçåè¯æï¼\n"116 m=0117 for z in wrong_words:118 #å¯å¨ä¸ä¸ªå¾ªç¯ï¼å¾ªç¯ç次æ°çäºï¼ç¨æ·çéè¯æ°ï¼119 m=m+1120 print (z['content'])121 #æå°æ¯ä¸ä¸ªéè¯ã122 f.write(str(m+1) +'. '+ z['content']+'\n')123 #åå
¥åºå·ï¼åå
¥éè¯ã 124 print ('ä½ ä¸è®¤è¯çåè¯æï¼')125 f.write('ä½ æ²¡è®°ä½çåè¯æï¼\n')126 #åå
¥"ä½ æ²¡è®°ä½çåè¯æï¼\n"127 s=0128 for x in not_knows:129 #å¯å¨ä¸ä¸ªå¾ªç¯ï¼å¾ªç¯ç次æ°çäºï¼ç¨æ·ä¸è®¤è¯çåè¯æ°ã130 print (x['content'])131 #æå°æ¯ä¸ä¸ªä¸è®¤è¯çåè¯ã132 f.write(str(s+1) +'. '+ x['content']+'\n')133 #åå
¥åºå·ï¼åå
¥ç¨æ·ä¸è®¤è¯çè¯æ±ã 134 print ('éè¯å没记ä½çè¯å·²ä¿åè³å½åæ件ç®å½ä¸ï¼ä¸æ¬¡è§ï¼')135 #åè¯ç¨æ·ï¼æ件已ç»ä¿å好ã136 #å¨ç½é¡µçç»ç«¯è¿è¡æ¶ï¼æ件ä¼è¢«åå¨è¯¾ç¨çæå¡å¨ä¸ï¼ä½ çä¸å°ï¼ä½å®ç确已ç»åå¨ã137else:138#å¦æç¨æ·ä¸æ³ä¿åï¼139 print('ä¸æ¬¡è§ï¼')140 #è¾åºâä¸æ¬¡è§ï¼â141 ...
list_vocabs.py
Source:list_vocabs.py
1import boto32from .basics import list_vocabularies3def main():4 transcribe_client = boto3.client('transcribe')5 print("Vocabs: ", list_vocabularies(transcribe_client))6if __name__ == '__main__':...
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!!