Skip to content

Commit 03dac31

Browse files
committed
tests(_internal/colors): Add tests for build_description heading format
Add tests to verify build_description produces correct heading format: - Named headings include "examples:" suffix for formatter detection - None heading produces bare "examples:" title - Multiple named headings all have suffix - Empty intro doesn't add blank sections
1 parent bb2ab46 commit 03dac31

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/_internal/test_colors.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ColorMode,
2222
Colors,
2323
UnknownStyleColor,
24+
build_description,
2425
get_color_mode,
2526
style,
2627
)
@@ -312,3 +313,50 @@ def test_heading_applies_bright_cyan_bold(monkeypatch: pytest.MonkeyPatch) -> No
312313
assert ANSI_BOLD in result
313314
assert "Local workspaces:" in result
314315
assert ANSI_RESET in result
316+
317+
318+
# build_description tests
319+
320+
321+
def test_build_description_named_heading_includes_examples_suffix() -> None:
322+
"""Named heading should include 'examples:' suffix for formatter detection."""
323+
result = build_description("My tool.", [("sync", ["mytool sync repo"])])
324+
325+
# Should be "sync examples:" not just "sync:"
326+
assert "sync examples:" in result
327+
# Verify the old format is not present (unless contained in "sync examples:")
328+
lines = result.split("\n")
329+
heading_line = next(line for line in lines if "sync" in line.lower())
330+
assert heading_line == "sync examples:"
331+
332+
333+
def test_build_description_no_heading_uses_examples() -> None:
334+
"""Heading=None should produce bare 'examples:' title."""
335+
result = build_description("My tool.", [(None, ["mytool run"])])
336+
337+
assert "examples:" in result
338+
assert result.count("examples:") == 1 # Just one
339+
340+
341+
def test_build_description_multiple_named_headings() -> None:
342+
"""Multiple named headings should all have 'examples:' suffix."""
343+
result = build_description(
344+
"My tool.",
345+
[
346+
("load", ["mytool load"]),
347+
("freeze", ["mytool freeze"]),
348+
("ls", ["mytool ls"]),
349+
],
350+
)
351+
352+
assert "load examples:" in result
353+
assert "freeze examples:" in result
354+
assert "ls examples:" in result
355+
356+
357+
def test_build_description_empty_intro() -> None:
358+
"""Empty intro should not add blank sections."""
359+
result = build_description("", [(None, ["cmd"])])
360+
361+
assert result.startswith("examples:")
362+
assert "cmd" in result

0 commit comments

Comments
 (0)