Skip to content

Commit

Permalink
open file with utf-8 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
idle-man committed Oct 24, 2019
1 parent d2dc3ec commit ef8c350
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions iparrot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def har_to_case(self, source, target="ParrotProject",
@staticmethod
def __read_file(name):
try:
with open(file=name, mode="r") as f:
with open(file=name, mode="r", encoding='utf-8') as f:
return f.read()
except IOError:
logger.error("Failed to open file: {}".format(name))
Expand All @@ -358,7 +358,7 @@ def __generate_case(self, suite, target="ParrotProject"):
_d_yaml = "{}/{}_env.yml".format(_d_path, suite['config']['name'])
r_d_yaml = "../environments/{}_env.yml".format(suite['config']['name'])
make_dir(_d_path)
with open(file=_d_yaml, mode='w') as f:
with open(file=_d_yaml, mode='w', encoding='utf-8') as f:
yaml.dump(data=self.env_tpl, stream=f, encoding='utf-8', allow_unicode=True)
logger.debug(" - environments: {}".format(_d_yaml))

Expand All @@ -379,7 +379,7 @@ def __generate_case(self, suite, target="ParrotProject"):
_step['config']['name'].split('/')[-1])
_step['config']['import'] = r_d_yaml
make_dir(_s_path)
with open(file=_s_yaml, mode='w') as f:
with open(file=_s_yaml, mode='w', encoding='utf-8') as f:
# use allow_unicode=True to solve Chinese display problem
yaml.dump(data=_step, stream=f, encoding='utf-8', allow_unicode=True)
_case['test_steps'][_sid] = r_s_yaml
Expand All @@ -391,13 +391,13 @@ def __generate_case(self, suite, target="ParrotProject"):
r_c_yaml = "../test_cases/{}.yml".format(suite['config']['name'])
_case['config']['import'] = r_d_yaml
make_dir(_c_path)
with open(file=_c_yaml, mode='w') as f:
with open(file=_c_yaml, mode='w', encoding='utf-8') as f:
yaml.dump(data=_case, stream=f, encoding='utf-8', allow_unicode=True)
logger.debug(" - test case: {}".format(_c_yaml))
suite['test_cases'][_cid] = r_c_yaml

# generate test suite
with open(file=_e_yaml, mode='w') as f:
with open(file=_e_yaml, mode='w', encoding='utf-8') as f:
yaml.dump(data=suite, stream=f, encoding='utf-8', allow_unicode=True)
logger.debug(" - test suite: {}".format(_e_yaml))
logger.info("Done. You could get them in {}".format(target))
Expand Down
2 changes: 1 addition & 1 deletion iparrot/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def do_hook_actions(self, actions):

def generate_report(self, output):
report_file = "{}/parrot_{}.html".format(output, now_timestamp())
Report(stream=open(report_file, 'w')).generate_report(result=self.report)
Report(stream=open(report_file, 'w', encoding='utf-8')).generate_report(result=self.report)
logger.info("You could check the report: {}".format(report_file))


Expand Down

0 comments on commit ef8c350

Please sign in to comment.