mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
change: replace io.open with open
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import io
|
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from json.decoder import JSONDecodeError
|
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:
|
try:
|
||||||
content_json = json.loads(f.read())
|
content_json = json.loads(f.read())
|
||||||
return content_json["log"]["entries"]
|
return content_json["log"]["entries"]
|
||||||
@@ -108,7 +107,7 @@ def dump_yaml(testcase, yaml_file):
|
|||||||
"""
|
"""
|
||||||
logger.info("dump testcase to YAML format.")
|
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(
|
yaml.dump(
|
||||||
testcase, outfile, allow_unicode=True, default_flow_style=False, indent=4
|
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.")
|
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)
|
my_json_str = json.dumps(testcase, ensure_ascii=False, indent=4)
|
||||||
if isinstance(my_json_str, bytes):
|
if isinstance(my_json_str, bytes):
|
||||||
my_json_str = my_json_str.decode("utf-8")
|
my_json_str = my_json_str.decode("utf-8")
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import csv
|
import csv
|
||||||
import importlib
|
import importlib
|
||||||
import io
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -29,7 +28,7 @@ project_meta: Union[ProjectMeta, None] = None
|
|||||||
def _load_yaml_file(yaml_file: Text) -> Dict:
|
def _load_yaml_file(yaml_file: Text) -> Dict:
|
||||||
""" load yaml file and check file content format
|
""" 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:
|
try:
|
||||||
yaml_content = yaml.load(stream)
|
yaml_content = yaml.load(stream)
|
||||||
except yaml.YAMLError as ex:
|
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:
|
def _load_json_file(json_file: Text) -> Dict:
|
||||||
""" load json file and check file content format
|
""" 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:
|
try:
|
||||||
json_content = json.load(data_file)
|
json_content = json.load(data_file)
|
||||||
except json.JSONDecodeError as ex:
|
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}")
|
logger.info(f"Loading environment variables from {dot_env_path}")
|
||||||
env_variables_mapping = {}
|
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:
|
for line in fp:
|
||||||
# maxsplit=1
|
# maxsplit=1
|
||||||
if "=" in line:
|
if "=" in line:
|
||||||
@@ -182,7 +181,7 @@ def load_csv_file(csv_file: Text) -> List[Dict]:
|
|||||||
|
|
||||||
csv_content_list = []
|
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)
|
reader = csv.DictReader(csvfile)
|
||||||
for row in reader:
|
for row in reader:
|
||||||
csv_content_list.append(row)
|
csv_content_list.append(row)
|
||||||
|
|||||||
Reference in New Issue
Block a user