"""Tests for the HtmlFormatter.""" from textwrap import dedent from cyclopts._markup import escape_html, extract_text from cyclopts.help import HelpEntry, HelpPanel from cyclopts.help.formatters.html import HtmlFormatter def test_html_formatter_empty_panel(): """Test that empty panels produce no output.""" formatter = HtmlFormatter() panel = HelpPanel(format="command", title="Commands") formatter(None, None, panel) output = formatter.get_output() assert output == "" def test_html_formatter_command_panel(): """Test command panel formatting as HTML table.""" formatter = HtmlFormatter() panel = HelpPanel( format="command", title="Commands", entries=[ HelpEntry(positive_names=("serve",), description="Start the server"), HelpEntry(positive_names=("build",), positive_shorts=("-b",), description="Build the project"), ], ) formatter(None, None, panel) output = formatter.get_output() # Check structure assert '
' in output assert "Commands" in output # Check structure contains list assert "serve" in output assert "build" in output assert "(-b)" in output # Aliases are shown in parentheses without code tags assert "Start the server" in output assert "Build the project" in output def test_html_formatter_parameter_panel(): """Test parameter panel formatting as HTML table.""" formatter = HtmlFormatter() panel = HelpPanel( format="parameter", title="Parameters", entries=[ HelpEntry( positive_names=("--port",), positive_shorts=("-p",), description="Port number", required=True, type="int", default="8080", ), HelpEntry( positive_names=("--verbose",), positive_shorts=("-v",), description="Enable verbose mode", required=False, choices=("true", "false"), ), ], ) formatter(None, None, panel) output = formatter.get_output() # Check structure assert '
' in output assert "Parameters" in output # Check structure contains list assert "