Files
phronesis/test/test_formatting.py
nvaldez 196df53a9b phronesis v0.2.0: the CLI app per SPEC.md - list, filter, install, update
- SPEC.md sectionized with stable ids (sectionize-markdown conventions)
- src/phronesis: cli, registry, harnesses (modular, vibe first), state,
  formatting, completions; argcomplete completion; exit codes per SPEC
- phronesis              -> version line + skill table (name, version, category,
  description wrapped below, daedalus-style)
- phronesis <category>   -> filtered table; close-match typos for skills+categories
- phronesis <skill> --install | --project  [--harness <name>] [-f]
  installs whole skill dir; prompt when present; EOF/default = skip; -f no prompt
- phronesis --update     -> refresh every state entry; warns unbundled; reinstalls missing
- state: <config>/phronesis/installed.json, unique by (name, harness, scope)
- skill/python-tdd bumped 1.2.0 with category: development
- test/ (56 tests, 92% cov) + autotest pytest check with 75% floor;
  all 7 autotest checks green

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-11-19 09:50:45 +01:00

76 lines
2.5 KiB
Python

"""Formatting tests: table layout and the description wrapping (SPEC items 3.3.1 to 3.3.5)."""
import phronesis.formatting as fmt
class FakeSkill:
def __init__(self, description):
self.name = "python-tdd"
self.version = "1.2.0"
self.category = "development"
self.description = description
def forces_plain(monkeypatch):
monkeypatch.setenv("NO_COLOR", "1")
def test_format_list_starts_with_version_line(monkeypatch):
forces_plain(monkeypatch)
assert fmt.format_list("Phronesis Version: 0.1.0", []).startswith("Phronesis Version: 0.1.0")
def test_no_skills_is_just_the_version_line(monkeypatch):
forces_plain(monkeypatch)
assert fmt.format_list("Phronesis Version: 0.1.0", []) == "Phronesis Version: 0.1.0"
def test_table_header_and_row(monkeypatch):
forces_plain(monkeypatch)
out = fmt.format_list("Phronesis Version: 0.1.0", [FakeSkill("a description")])
lines = out.splitlines()
assert lines[0] == "Phronesis Version: 0.1.0"
assert lines[1] == ""
assert lines[2].rstrip() == "skill version category"
assert lines[3].rstrip() == "---------- ------- -----------"
assert lines[4].rstrip() == "python-tdd 1.2.0 development"
assert lines[5] == fmt.DESCRIPTION_INDENT + "a description"
def test_long_descriptions_wrap_indented(monkeypatch):
forces_plain(monkeypatch)
long_text = " ".join(["word"] * 60)
out = fmt.format_list("Phronesis Version: 0.1.0", [FakeSkill(long_text)])
description_lines = [line for line in out.splitlines() if line.startswith(" " * 8)]
assert len(description_lines) > 1
for line in description_lines:
assert len(line.rstrip()) <= 80
def test_wrapping_never_splits_a_long_word():
wide = fmt.wrapped_description("x" * 100, 40)
assert wide == [fmt.DESCRIPTION_INDENT + "x" * 100]
def test_colors_respect_no_color_over_force_color(monkeypatch):
class Tty:
def isatty(self):
return True
monkeypatch.setenv("NO_COLOR", "1")
monkeypatch.setenv("FORCE_COLOR", "1")
assert fmt.colors_enabled(Tty()) is False
monkeypatch.setenv("NO_COLOR", "")
assert fmt.colors_enabled(Tty()) is True
monkeypatch.delenv("FORCE_COLOR")
assert fmt.colors_enabled(Tty()) is True
def test_cell_left_aligned(monkeypatch):
forces_plain(monkeypatch)
assert fmt.cell("ab", 5) == "ab "
def test_wrapped_description_indents_subsequent_lines():
lines = fmt.wrapped_description("one two three four five " * 4, 40)
assert all(line.startswith(fmt.DESCRIPTION_INDENT) for line in lines)