|
1 | 1 | """Test nimare.reports.""" |
2 | 2 |
|
3 | 3 | import os.path as op |
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | import pytest |
6 | 7 |
|
7 | 8 | from nimare.correct import FWECorrector |
8 | 9 | from nimare.diagnostics import FocusCounter, Jackknife |
9 | 10 | from nimare.meta.cbma import ALESubtraction |
10 | 11 | from nimare.meta.ibma import FixedEffectsHedges, Stouffers |
11 | | -from nimare.reports.base import run_reports |
| 12 | +from nimare.reports.base import Reportlet, run_reports |
12 | 13 | from nimare.workflows import CBMAWorkflow, IBMAWorkflow, PairwiseCBMAWorkflow |
13 | 14 |
|
14 | 15 |
|
@@ -158,6 +159,26 @@ def test_reports_alesubtraction_montecarlo_uses_pairwise_mass_map( |
158 | 159 |
|
159 | 160 | summary_file = op.join(tmpdir, "figures", "corrector_figure-summary.html") |
160 | 161 | assert op.isfile(summary_file) |
161 | | - with open(summary_file) as fo: |
| 162 | + with open(summary_file, encoding="utf-8") as fo: |
162 | 163 | summary_text = fo.read() |
163 | 164 | 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