"""End-to-end behaviour of the `wapdown` command.""" from __future__ import annotations import pytest from conftest import EXAMPLES from wapdown.cli import main TWO_SECTIONS = "Intro.\n\n{.card One}\nFirst.\n\n{.card Two}\nSecond.\n" @pytest.fixture def source(tmp_path): def _write(text: str = TWO_SECTIONS, name: str = "doc.md"): path = tmp_path / name path.write_text(text, encoding="utf-8") return path return _write class TestOutput: def test_writes_to_stdout_by_default(self, source, capsys): assert main([str(source())]) == 0 assert capsys.readouterr().out.startswith('') def test_writes_to_a_file(self, source, tmp_path): out = tmp_path / "deck.wml" assert main([str(source()), "-o", str(out)]) == 0 assert out.read_text(encoding="utf-8").endswith("\n") def test_creates_missing_parent_directories(self, source, tmp_path): out = tmp_path / "nested" / "deep" / "deck.wml" assert main([str(source()), "-o", str(out)]) == 0 assert out.exists() def test_uses_lf_line_endings(self, source, tmp_path): out = tmp_path / "deck.wml" main([str(source()), "-o", str(out)]) assert b"\r" not in out.read_bytes() def test_deck_per_card_writes_a_directory(self, source, tmp_path): out = tmp_path / "decks" assert main([str(source()), "--deck-per-card", "-o", str(out)]) == 0 assert sorted(p.name for p in out.iterdir()) == [ "index.wml", "one.wml", "two.wml", ] def test_deck_per_card_without_output_is_refused(self, source): # Several files cannot be written to stdout, so say so rather than # silently emitting only one of them. with pytest.raises(SystemExit, match="pass -o DIRECTORY"): main([str(source()), "--deck-per-card"]) class TestOptions: def test_flags_reach_the_renderer(self, source, capsys): main([str(source()), "--menu-style", "select", "--title", "Deck"]) out = capsys.readouterr().out assert "