Spaces:
Running on Zero
Running on Zero
File size: 2,963 Bytes
db06ffa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | """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 <argv> --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()
|