Skip to content

Commit 48f7553

Browse files
committed
fix: enforce utf-8 for report template and html file io
1 parent d617e44 commit 48f7553

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

investing_algorithm_framework/app/reporting/backtest_report.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636
def _read_template(filename):
37-
with open(os.path.join(_TEMPLATE_DIR, filename), 'r') as f:
37+
with open(os.path.join(_TEMPLATE_DIR, filename), 'r', encoding='utf-8') as f:
3838
return f.read()
3939

4040

@@ -186,7 +186,7 @@ def show(self, backtest_date_range=None, browser=False):
186186
self.html_report = self._build_html()
187187

188188
path = "/tmp/backtest_report.html"
189-
with open(path, "w") as f:
189+
with open(path, "w", encoding="utf-8") as f:
190190
f.write(self.html_report)
191191

192192
if browser:
@@ -208,7 +208,7 @@ def show(self, backtest_date_range=None, browser=False):
208208
def save(self, path):
209209
if not self.html_report:
210210
self.html_report = self._build_html()
211-
with open(path, "w") as f:
211+
with open(path, "w", encoding="utf-8") as f:
212212
f.write(self.html_report)
213213

214214
@staticmethod

tests/app/reporting/test_backtest_report_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def test_save_creates_file(self):
211211
report.save(path)
212212
self.assertTrue(os.path.isfile(path))
213213

214-
with open(path) as f:
214+
with open(path, encoding="utf-8") as f:
215215
content = f.read()
216216
self.assertIn("<!DOCTYPE html>", content)
217217
self.assertIn("const STRATEGIES", content)

0 commit comments

Comments
 (0)