test_base_commands.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """Focused regression tests for module base commands."""
  2. from __future__ import annotations
  3. from types import SimpleNamespace
  4. from cli.core.module.base_commands import list_templates
  5. class _DisplayCapture:
  6. def __init__(self) -> None:
  7. self.lines: list[str] = []
  8. def text(self, value: str, style: str | None = None) -> None:
  9. del style
  10. self.lines.append(value)
  11. def data_table(self, *args, **kwargs) -> None:
  12. del args, kwargs
  13. raise AssertionError("data_table should not be used for raw output")
  14. def info(self, *args, **kwargs) -> None:
  15. del args, kwargs
  16. raise AssertionError("info should not be used when templates exist")
  17. def test_list_templates_raw_outputs_tab_separated_rows() -> None:
  18. """Raw listing should emit one tab-separated row per template."""
  19. template = SimpleNamespace(
  20. id="whoami",
  21. metadata=SimpleNamespace(
  22. name="Whoami",
  23. tags=["docker", "test"],
  24. version=SimpleNamespace(name="1.0.0"),
  25. library="default",
  26. library_type="git",
  27. ),
  28. )
  29. display = _DisplayCapture()
  30. module_instance = SimpleNamespace(
  31. name="compose",
  32. display=display,
  33. _load_all_templates=lambda: [template],
  34. )
  35. returned_templates = list_templates(module_instance, raw=True)
  36. assert returned_templates == [template]
  37. assert display.lines == ["whoami\tWhoami\tdocker,test\t1.0.0\tdefault"]