Skip to content

Commit 9457535

Browse files
committed
fix reports
1 parent 0888f35 commit 9457535

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

nimare/reports/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,11 @@ def __init__(self, out_dir, config=None):
434434
contents = None
435435
html_anchor = src.relative_to(out_dir)
436436
if ext == ".html":
437-
contents = IFRAME_SNIPPET.format(html_anchor) if iframe else src.read_text()
437+
contents = (
438+
IFRAME_SNIPPET.format(html_anchor)
439+
if iframe
440+
else src.read_text(encoding="utf-8")
441+
)
438442
if dropdown:
439443
contents = (
440444
f"<details><summary>Advanced ({self.title})</summary>{contents}</details>"
@@ -630,7 +634,7 @@ def __init__(
630634
def _load_config(self, config):
631635
from yaml import safe_load as load
632636

633-
settings = load(config.read_text())
637+
settings = load(config.read_text(encoding="utf-8"))
634638
self.packagename = settings.get("package", None)
635639

636640
self.index(settings["sections"])

nimare/tests/test_reports.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""Test nimare.reports."""
22

33
import os.path as op
4+
from pathlib import Path
45

56
import pytest
67

78
from nimare.correct import FWECorrector
89
from nimare.diagnostics import FocusCounter, Jackknife
910
from nimare.meta.cbma import ALESubtraction
1011
from nimare.meta.ibma import FixedEffectsHedges, Stouffers
11-
from nimare.reports.base import run_reports
12+
from nimare.reports.base import Reportlet, run_reports
1213
from nimare.workflows import CBMAWorkflow, IBMAWorkflow, PairwiseCBMAWorkflow
1314

1415

@@ -158,6 +159,26 @@ def test_reports_alesubtraction_montecarlo_uses_pairwise_mass_map(
158159

159160
summary_file = op.join(tmpdir, "figures", "corrector_figure-summary.html")
160161
assert op.isfile(summary_file)
161-
with open(summary_file) as fo:
162+
with open(summary_file, encoding="utf-8") as fo:
162163
summary_text = fo.read()
163164
assert "z_desc-group1MinusGroup2Mass_level-cluster_corr-FWE_method-montecarlo" in summary_text
165+
166+
167+
def test_reportlet_reads_utf8_html(tmp_path):
168+
"""Reportlets should read generated HTML fragments as UTF-8 on all platforms."""
169+
expected_text = "caf\u00e9 \u2014 \u4f60\u597d"
170+
figures_dir = tmp_path / "figures"
171+
figures_dir.mkdir()
172+
html_file = figures_dir / "utf8_fragment.html"
173+
html_file.write_text(f"<div>{expected_text}</div>", encoding="utf-8")
174+
175+
reportlet = Reportlet(
176+
Path(tmp_path),
177+
config={
178+
"name": "utf8_fragment",
179+
"bids": {"value": "utf8_fragment", "suffix": "html"},
180+
},
181+
)
182+
183+
assert len(reportlet.components) == 1
184+
assert expected_text in reportlet.components[0][0]

0 commit comments

Comments
 (0)