Skip to content

Commit e7bb7a2

Browse files
authored
Merge pull request #530 from propcgamer20-png/fix/report-reference-more-groups-notice
fix: show "N more groups" notice on the reference-baseline sub-table
2 parents 4a42779 + f5e1391 commit e7bb7a2

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

faircode/report.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ def to_terminal(result: dict) -> str:
8787
if meta:
8888
add(f" ({' '.join(meta)})")
8989
if d.get("reference"):
90+
ref_groups = d["reference"]["groups"]
9091
add(f" reference (deviation {d['reference']['deviation'] * 100:.1f}%):")
91-
for g in d["reference"]["groups"][:DISPLAY_GROUPS]:
92+
for g in ref_groups[:DISPLAY_GROUPS]:
9293
add(f" {g['label'][:16]:<16} exp {g['expected'] * 100:5.1f}% "
9394
f"act {g['actual'] * 100:5.1f}% ({g['delta'] * 100:+5.1f} pp)")
95+
if len(ref_groups) > DISPLAY_GROUPS:
96+
add(f" … and {len(ref_groups) - DISPLAY_GROUPS} more groups")
9497
add("")
9598

9699
if result["flags"]:
@@ -231,13 +234,19 @@ def esc(s) -> str:
231234
f'<td class="num">{g["delta"] * 100:+.1f} pp</td></tr>'
232235
for g in ref["groups"][:DISPLAY_GROUPS]
233236
)
237+
ref_more = ""
238+
if len(ref["groups"]) > DISPLAY_GROUPS:
239+
ref_more = (
240+
f'<div class="dim-more">… and '
241+
f'{len(ref["groups"]) - DISPLAY_GROUPS} more groups</div>'
242+
)
234243
reference_html = (
235244
f'<div class="reference"><h3>Reference '
236245
f'<span class="kind">deviation {ref["deviation"] * 100:.1f}%</span></h3>'
237246
f'<table><caption>Expected vs. actual share - {esc(d["name"])}</caption>'
238247
f'<tr><th scope="col"></th><th scope="col" class="num">Expected</th>'
239248
f'<th scope="col" class="num">Actual</th><th scope="col" class="num">Delta</th></tr>'
240-
f'{ref_rows}</table></div>'
249+
f'{ref_rows}</table>{ref_more}</div>'
241250
)
242251

243252
meta_parts = []

tests/test_report.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,25 @@ def test_to_html_renders_reference_baseline_section(mock_profile_result):
145145
assert "-5.0 pp" in html_out
146146

147147

148+
def test_to_html_reports_reference_groups_omitted_by_display_cap(mock_profile_result):
149+
"""Mirrors test_to_html_reports_groups_omitted_by_display_cap for the
150+
reference-baseline sub-table, which was silently truncated with no
151+
dim-more notice."""
152+
mock_profile_result["dimensions"][0]["reference"] = {
153+
"deviation": 0.1,
154+
"groups": [
155+
{"label": f"Group {i}", "expected": 1 / 15, "actual": 1 / 15, "delta": 0.0}
156+
for i in range(15)
157+
],
158+
}
159+
160+
html_out = to_html(mock_profile_result)
161+
162+
assert "Group 11" in html_out
163+
assert "Group 12" not in html_out
164+
assert '<div class="dim-more">… and 3 more groups</div>' in html_out
165+
166+
148167
def test_to_html_omits_reference_section_when_absent(mock_profile_result):
149168
html_out = to_html(mock_profile_result)
150169

@@ -268,6 +287,25 @@ def test_to_terminal_truncates_a_long_reference_group_label(mock_profile_result)
268287
assert ref_label not in out
269288

270289

290+
def test_to_terminal_reports_reference_groups_omitted_by_display_cap(mock_profile_result):
291+
"""SPEC section 7: every report surface that truncates a group list must
292+
state how many groups were omitted. The reference sub-table used to be
293+
silently capped at DISPLAY_GROUPS with no notice."""
294+
mock_profile_result["dimensions"][0]["reference"] = {
295+
"deviation": 0.1,
296+
"groups": [
297+
{"label": f"Group {i}", "expected": 1 / 15, "actual": 1 / 15, "delta": 0.0}
298+
for i in range(15)
299+
],
300+
}
301+
302+
out = to_terminal(mock_profile_result)
303+
304+
assert "Group 11" in out
305+
assert "Group 12" not in out
306+
assert "… and 3 more groups" in out
307+
308+
271309
def test_to_terminal_renders_flags_section(mock_profile_result):
272310
out = to_terminal(mock_profile_result)
273311

0 commit comments

Comments
 (0)