Best Python code snippet using avocado_python
测试tts失败原因.py
Source:测试tts失败原因.py
...59def writeFile(file, content):60 with open(file, 'wb') as f:61 f.write(content)62 f.close()63def test_fail_reason(txt_file_path):64 # txt_file_path = r"C:\Dpan\python-script\pdf_convert\æ°æ®\10人以ä¸å°å¢é管çæå-å ä¹å
å
彦_image_ocr_result.txt"65 # å¾
åæææ¬å
容66 with open(txt_file_path, 'r', encoding='utf-8') as f:67 text = f.read().replace('\n', "")68 # print('æ»åæ°ï¼',len(text))69 # text_length = 33370 # text_list = re.findall(r".{%d}" % text_length, text)71 # text_list.append(text[len(text_list) * text_length:])72 text_list = text_byte_num_cut(text, 998)73 # print('å段æ°ï¼',len(text_list))74 try:75 folder_path = os.path.join(r"E:\python\python-post-tencent\讯é£AI\audio", os.path.splitext(os.path.basename(txt_file_path))[0])76 os.makedirs(folder_path)77 except:78 pass79 for i, every_text in enumerate(text_list):80 r = requests.post(URL, headers=getHeader(), data=getBody(every_text))81 contentType = r.headers['Content-Type']82 if contentType == "audio/mpeg":83 sid = r.headers['sid']84 if AUE == "raw":85 # åæé³é¢æ ¼å¼ä¸ºpcmãwav并ä¿åå¨audioç®å½ä¸86 writeFile(os.path.join(folder_path, '{}.wav'.format(i)), r.content)87 # writeFile( + str(i) + ".wav", r.content)88 else:89 # åæé³é¢æ ¼å¼ä¸ºmp3并ä¿åå¨audioç®å½ä¸90 writeFile("audio/" + "xiaoyan" + ".mp3", r.content)91 print(i,"success, sid = " + sid)92 else:93 # é误ç é¾æ¥ï¼https://www.xfyun.cn/document/error-code ï¼codeè¿åé误ç æ¶å¿
çï¼94 for i in json.loads(r.content).items():95 print(' => '.join(i))96if __name__ == "__main__":...
test_jsonresult.py
Source:test_jsonresult.py
...14 data = json.load(json_file)15 test_data = data["tests"].pop()16 expected_logfile = path.join(test_data["logdir"], "debug.log")17 self.assertEqual(expected_logfile, test_data["logfile"])18 def test_fail_reason(self):19 cmd_line = (20 f"{AVOCADO} run examples/tests/failtest.py "21 f"--job-results-dir {self.tmpdir.name} --disable-sysinfo"22 )23 process.run(cmd_line, ignore_status=True)24 json_path = path.join(self.tmpdir.name, "latest", "results.json")25 with open(json_path, "r", encoding="utf-8") as json_file:26 data = json.load(json_file)27 test_data = data["tests"].pop()28 self.assertEqual("This test is supposed to fail", test_data["fail_reason"])29 def test_tags_in_result(self):30 cmd_line = (31 f"{AVOCADO} run examples/tests/failtest.py "32 f"--job-results-dir {self.tmpdir.name} --disable-sysinfo"...
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!!