"""Tests guarding CLI help text — examples must render and stay clean.""" from __future__ import annotations import io import unittest from contextlib import redirect_stdout from zsgdp.cli import _epilog, main def _capture_help(argv: list[str]) -> str: """Run `zsgdp --help` and return captured stdout. SystemExit is normal.""" buffer = io.StringIO() with redirect_stdout(buffer): try: main(argv + ["--help"]) except SystemExit: pass return buffer.getvalue() class EpilogFormatterTests(unittest.TestCase): def test_epilog_dedents_indented_source_string(self): rendered = _epilog( """ zsgdp parse --input ./a --output ./b zsgdp parse --input ./c --output ./d """ ) # No double-indentation; first non-blank line begins with two spaces only. lines = rendered.splitlines() self.assertEqual(lines[0], "Examples:") self.assertTrue(lines[1].startswith(" zsgdp parse")) # No source-indent leak. self.assertNotIn(" zsgdp", rendered) def test_epilog_preserves_blank_lines_as_separators(self): rendered = _epilog( """ line one line two """ ) self.assertIn("\n\n", rendered) class SubcommandHelpTests(unittest.TestCase): def test_top_level_help_lists_examples_section(self): text = _capture_help([]) self.assertIn("Examples:", text) self.assertIn("zsgdp parse", text) self.assertIn("docs/space_smoke.md", text) def test_parse_help_has_examples(self): text = _capture_help(["parse"]) self.assertIn("Examples:", text) self.assertIn("zsgdp parse --input", text) self.assertIn("--config configs/docling.yaml", text) def test_benchmark_help_covers_three_dataset_modes(self): text = _capture_help(["benchmark"]) self.assertIn("Examples:", text) self.assertIn("--dataset omnidocbench", text) self.assertIn("--dataset doclaynet", text) def test_benchmark_ablate_shows_merged_arm_pattern(self): text = _capture_help(["benchmark-ablate"]) self.assertIn("--parser docling --parser pymupdf", text) self.assertIn("--no-merged", text) def test_run_gpu_tasks_documents_dry_run_vs_execute(self): text = _capture_help(["run-gpu-tasks"]) self.assertIn("Dry-run", text) self.assertIn("--execute", text) def test_combine_benchmarks_shows_label_pairing(self): text = _capture_help(["combine-benchmarks"]) self.assertIn("--label omnidocbench", text) self.assertIn("--label doclaynet", text) def test_preflight_help_documents_skip_flags(self): text = _capture_help(["preflight"]) self.assertIn("--benchmark", text) self.assertIn("--skip-unit", text) if __name__ == "__main__": unittest.main()