diff --git a/test/scripts/auto_xts_test/get_resource/get_tool.py b/test/scripts/auto_xts_test/get_resource/get_tool.py index b1af7a061cb56e8c3e0203f773b6af5481c27eec..02c781bde7fdcd3ba549aa0a96130050fb548621 100755 --- a/test/scripts/auto_xts_test/get_resource/get_tool.py +++ b/test/scripts/auto_xts_test/get_resource/get_tool.py @@ -47,7 +47,6 @@ def get_tool(url): if __name__ == "__main__": - yl = open(r".\get_resource\config.yaml", 'r') - data = yaml.safe_load(yl.read()) - get_tool(data['url_tools']) - yl.close() \ No newline at end of file + with open(r".\get_resource\config.yaml", 'r') as config_file: + data = yaml.safe_load(config_file.read()) + get_tool(data['url_tools']) \ No newline at end of file diff --git a/test/scripts/auto_xts_test/get_resource/spider.py b/test/scripts/auto_xts_test/get_resource/spider.py index 24f1882e493037f08f1c7fa6d479fffaf622aa74..2c06247719915f64b2ff8b62600107235333a452 100755 --- a/test/scripts/auto_xts_test/get_resource/spider.py +++ b/test/scripts/auto_xts_test/get_resource/spider.py @@ -70,10 +70,9 @@ def change_port(xml_path, xml_dw="./environment/device/port"): if __name__ == '__main__': - yl = open(r".\get_resource\config.yaml", 'r') - data = yaml.safe_load(yl.read()) + with open(r".\get_resource\config.yaml", 'r') as config_file: + data = yaml.safe_load(config_file.read()) dest_url = get_url(data['url_dailybuilds'], data['headers'], data['data'], data['url_dayu200']) get_images_and_testcases(dest_url, data['path_xts_pack'], data['path_xts_dir']) change_port(data['path_configfile']) - yl.close() \ No newline at end of file diff --git a/test/scripts/auto_xts_test/get_result.py b/test/scripts/auto_xts_test/get_result.py index 992731af24ebb90306cccf1cf304553489f6db08..4f3510ba241f38c706b5e9a60b1b77350f66e493 100755 --- a/test/scripts/auto_xts_test/get_result.py +++ b/test/scripts/auto_xts_test/get_result.py @@ -21,12 +21,12 @@ import shutil import yaml if __name__ == "__main__": - yl = open(r".\get_resource\config.yaml", 'r') - data = yaml.safe_load(yl.read()) + with open(r".\get_resource\config.yaml", 'r') as f: + data = yaml.safe_load(f.read()) + path = data['path_xts_report'] - yl.close() file_list = os.listdir(path) - + summary_report = os.path.join(path, file_list[-1], "summary_report.html") if (os.path.exists(summary_report)): shutil.copy2(summary_report, "result\\") diff --git a/test/scripts/performance_test/performance_build.py b/test/scripts/performance_test/performance_build.py index a4d7572c569e41ebc8b4b7c48932a404d1a95593..94af3edf8275fa712f51eec5c3d486eb53ab2d80 100644 --- a/test/scripts/performance_test/performance_build.py +++ b/test/scripts/performance_test/performance_build.py @@ -215,9 +215,8 @@ class PerformanceBuild(): if self.developing_test_mode: content = self.developing_test_data.split("\t") else: - src = open(self.config.temp_filename, "r", encoding='UTF-8') - content = src.read().split("\t") - src.close() + with open(self.config.temp_filename, "r", encoding='UTF-8') as src: + content = src.read().split("\t") clean_filter = False for task_build_time_str in content: if len(task_build_time_str) == 0: diff --git a/test/scripts/send_email.py b/test/scripts/send_email.py index 27243c19e4d63eda829a0cf6363191890fe03c65..07f7030f065291aca271c3e2356f3264c14c48bd 100755 --- a/test/scripts/send_email.py +++ b/test/scripts/send_email.py @@ -55,8 +55,9 @@ def add_image(msg, img_dic): def send_email(): - yl = open(r".\email_config.yaml", 'r') - data = yaml.safe_load(yl.read()) + with open(r".\email_config.yaml", 'r') as f: + data = yaml.safe_load(f.read()) + user_name = data["user_name"] sender = data["sender_email_address"] auth_code = data["auth_code"] @@ -68,7 +69,6 @@ def send_email(): perf_test = data["perf_report_file"] attachment_files = data["attatchment_files"] image_files = data["image_files"] - yl.close() msg = MIMEMultipart() msg['From'] = sender