From 804b86d16e964ffa1e1db4964be193cd5c400891 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 29 Jun 2020 14:29:56 +0800 Subject: [PATCH] change: replace io.open with open --- httprunner/ext/har2case/utils.py | 7 +++---- httprunner/loader.py | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/httprunner/ext/har2case/utils.py b/httprunner/ext/har2case/utils.py index ed200995..110f8b40 100644 --- a/httprunner/ext/har2case/utils.py +++ b/httprunner/ext/har2case/utils.py @@ -1,4 +1,3 @@ -import io import json import sys from json.decoder import JSONDecodeError @@ -28,7 +27,7 @@ def load_har_log_entries(file_path): ] """ - with io.open(file_path, "r+", encoding="utf-8-sig") as f: + with open(file_path, encoding="utf-8") as f: try: content_json = json.loads(f.read()) return content_json["log"]["entries"] @@ -108,7 +107,7 @@ def dump_yaml(testcase, yaml_file): """ logger.info("dump testcase to YAML format.") - with io.open(yaml_file, "w", encoding="utf-8") as outfile: + with open(yaml_file, "w", encoding="utf-8") as outfile: yaml.dump( testcase, outfile, allow_unicode=True, default_flow_style=False, indent=4 ) @@ -121,7 +120,7 @@ def dump_json(testcase, json_file): """ logger.info("dump testcase to JSON format.") - with io.open(json_file, "w", encoding="utf-8") as outfile: + with open(json_file, "w", encoding="utf-8") as outfile: my_json_str = json.dumps(testcase, ensure_ascii=False, indent=4) if isinstance(my_json_str, bytes): my_json_str = my_json_str.decode("utf-8") diff --git a/httprunner/loader.py b/httprunner/loader.py index 429b4d07..b389c716 100644 --- a/httprunner/loader.py +++ b/httprunner/loader.py @@ -1,6 +1,5 @@ import csv import importlib -import io import json import os import sys @@ -29,7 +28,7 @@ project_meta: Union[ProjectMeta, None] = None def _load_yaml_file(yaml_file: Text) -> Dict: """ load yaml file and check file content format """ - with io.open(yaml_file, "r", encoding="utf-8") as stream: + with open(yaml_file, encoding="utf-8") as stream: try: yaml_content = yaml.load(stream) except yaml.YAMLError as ex: @@ -43,7 +42,7 @@ def _load_yaml_file(yaml_file: Text) -> Dict: def _load_json_file(json_file: Text) -> Dict: """ load json file and check file content format """ - with io.open(json_file, encoding="utf-8") as data_file: + with open(json_file, encoding="utf-8") as data_file: try: json_content = json.load(data_file) except json.JSONDecodeError as ex: @@ -128,7 +127,7 @@ def load_dot_env_file(dot_env_path: Text) -> Dict: logger.info(f"Loading environment variables from {dot_env_path}") env_variables_mapping = {} - with io.open(dot_env_path, "r", encoding="utf-8") as fp: + with open(dot_env_path, encoding="utf-8") as fp: for line in fp: # maxsplit=1 if "=" in line: @@ -182,7 +181,7 @@ def load_csv_file(csv_file: Text) -> List[Dict]: csv_content_list = [] - with io.open(csv_file, encoding="utf-8") as csvfile: + with open(csv_file, encoding="utf-8") as csvfile: reader = csv.DictReader(csvfile) for row in reader: csv_content_list.append(row)