How to use find_substring method in autotest

Best Python code snippet using autotest_python

Voice_Recognition.py

Source:Voice_Recognition.py Github

copy

Full Screen

...12 def processing(self): 13 while (True):14 trigger = self.convert_audio_to_txt()15 self.command2 = None16 if(self.find_substring('night light', trigger)):17 while (self.command2 != 'close'):18 self.start_action()19 self.action()20 def start_action(self):21 print('How can I help you? \n***Say: "play second song" OR Say: "play first song"***')22 print('If you want to end the program, please say "close the Nightlight": ')23 self.command = self.convert_audio_to_txt()24 25 def action(self):26 cmnd = self.command27 if (self.find_substring('first', cmnd) or self.find_substring('one', cmnd)):28 self.do_action(1)29 elif (self.find_substring('second', cmnd) or self.find_substring('two', cmnd)):30 self.do_action(2)31 elif (self.find_substring('third', cmnd) or self.find_substring('three', cmnd)):32 self.do_action(3)33 elif (self.find_substring('fourth', cmnd) or self.find_substring('four', cmnd)):34 self.do_action(4)35 elif (self.find_substring('pause', cmnd) or self.find_substring('stop', cmnd)):36 self.do_action(5)37 elif (self.find_substring('resume', cmnd) or self.find_substring('continue', cmnd)):38 self.do_action(6) 39 elif (self.find_substring('close', cmnd)):40 self.do_action(7)41 else:42 print('There is no such command here.')43 def do_action(self, type_num):44 if(type_num == 1):45 pub_cmd.publish(client, "lullaby1.mp3")46 elif(type_num == 2):47 pub_cmd.publish(client, "lullaby2.mp3")48 elif(type_num == 3):49 pub_cmd.publish(client, "lullaby3.mp3")50 elif(type_num == 4):51 pub_cmd.publish(client, "lullaby4.mp3") 52 elif(type_num == 5):53 pub_cmd.publish(client, "pause")54 elif(type_num == 6):55 pub_cmd.publish(client, "resume")56 elif (type_num == 7):57 self.command2 = 'close'58 def convert_audio_to_txt(self):59 with sr.Microphone() as source:60 # self.r.adjust_for_ambient_noise(source)61 audio = self.r.listen(source)62 try:63 self.text = self.r.recognize_google(audio, show_all=True)64 return (self.text)65 except:66 print('I did not get that. Please say again.')67 def find_substring(self, substring, possible_cmd):68 69 if(type(possible_cmd) == dict):70 for txt in possible_cmd['alternative']:71 if substring in txt['transcript'].lower():72 return True73 return False74vc = Voice_Commmand()...

Full Screen

Full Screen

test_suffix_tree.py

Source:test_suffix_tree.py Github

copy

Full Screen

...22# def test_empty_string(self):23# st = register_new_suffix_tree()24# assert isinstance(st, SuffixTree)25# st.add_string('')26# self.assertEqual(self.app.find_substring('not there', st.id), -1)27# self.assertEqual(self.app.find_substring('', st.id), -1)28# self.assertFalse(self.app.has_substring('not there', st.id))29# self.assertFalse(self.app.has_substring('', st.id))30#31# def test_repeated_string(self):32# st = register_new_suffix_tree()33# st.add_string("aaa")34# self.assertEqual(self.app.find_substring('a', st.id), 0)35# self.assertEqual(self.app.find_substring('aa', st.id), 0)36# self.assertEqual(self.app.find_substring('aaa', st.id), 0)37# self.assertEqual(self.app.find_substring('b', st.id), -1)38# self.assertTrue(self.app.has_substring('a', st.id))39# self.assertTrue(self.app.has_substring('aa', st.id))40# self.assertTrue(self.app.has_substring('aaa', st.id))41# self.assertFalse(self.app.has_substring('aaaa', st.id))42# self.assertFalse(self.app.has_substring('b', st.id))43# # case sensitive by default44# self.assertFalse(self.app.has_substring('A', st.id))45#46# def test_mississippi(self):47# st = register_new_suffix_tree()48# st.add_string("mississippi")49# self.assertEqual(self.app.find_substring('a', st.id), -1)50# self.assertEqual(self.app.find_substring('m', st.id), 0)51# self.assertEqual(self.app.find_substring('i', st.id), 1)52#53# @notquick54# def test_long_string(self):55# st = register_new_suffix_tree()56# st.add_string(LONG_TEXT)57# self.assertEqual(self.app.find_substring('Ukkonen', st.id), 1498)58# self.assertEqual(self.app.find_substring('Optimal', st.id), 11074)59# self.assertFalse(self.app.has_substring('ukkonen', st.id))60#61# @notquick62# def test_case_insensitivity(self):63# st = register_new_suffix_tree(case_insensitive=True)64# st.add_string(LONG_TEXT)65# self.assertEqual(self.app.find_substring('ukkonen', st.id), 1498)...

Full Screen

Full Screen

30. find_substring.py

Source:30. find_substring.py Github

copy

Full Screen

1def find_substring(s, words):2 indexes = []3 word_len = len(words[0])4 length = word_len * len(words)5 i = 06 word_dict = {}7 for word in words:8 if word_dict.get(word) is None:9 word_dict.update({word: 1})10 else:11 word_dict.update({word: word_dict.get(word) + 1})12 while i + length - 1 < len(s):13 sub = s[i: i + length]14 if check_string(sub, word_dict.copy(), word_len):15 indexes.append(i)16 i += 117 return indexes18def check_string(sub, dict_copy, word_len):19 i = 020 while i < len(sub):21 str = sub[i: i + word_len]22 if dict_copy.get(str) is None or dict_copy.get(str) == 0:23 return False24 else:25 dict_copy.update({str: dict_copy.get(str) - 1})26 i += word_len27 return True28s = "barfoothefoobarman"29words = ["foo","bar"]30print(find_substring(s, words))31s = "wordgoodgoodgoodbestword"32words = ["word","good","best","word"]33print(find_substring(s, words))34s = "barfoofoobarthefoobarman"35words = ["bar","foo","the"]36print(find_substring(s, words))37s = "wordgoodgoodgoodbestword"38words = ["word","good","best","good"]39print(find_substring(s, words))40s = "lingmindraboofooowingdingbarrwingmonkeypoundcake"41words = ["fooo","barr","wing","ding","wing"]...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful