Coverage for tests / unit / utils / test_ascii_normalize.py: 100%
22 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Unit tests for ASCII art normalization helpers."""
3from __future__ import annotations
5from pathlib import Path
7from assertpy import assert_that
9from lintro.utils.formatting import normalize_ascii_block, normalize_ascii_file_sections
12def test_normalize_ascii_block_center_and_alignments() -> None:
13 """Normalize ASCII blocks across horizontal/vertical alignments."""
14 src = ["XX", "XXXX", "X"]
15 out = normalize_ascii_block(
16 src,
17 width=10,
18 height=5,
19 align="center",
20 valign="middle",
21 )
22 assert_that(len(out)).is_equal_to(5)
23 assert_that(all(len(line) == 10 for line in out)).is_true()
24 assert_that({"XX", "XXXX", "X"}).contains(out[2].strip())
25 left = normalize_ascii_block(["X"], width=5, height=1, align="left")
26 right = normalize_ascii_block(["X"], width=5, height=1, align="right")
27 assert_that(left[0].startswith("X") and left[0].endswith(" ")).is_true()
28 assert_that(right[0].startswith(" ") and right[0].endswith("X")).is_true()
31def test_normalize_ascii_file_sections(tmp_path: Path) -> None:
32 """Normalize sections from a file and enforce width/height constraints.
34 Args:
35 tmp_path: Temporary directory path provided by pytest.
36 """
37 p = tmp_path / "art.txt"
38 p.write_text("A\nAA\n\nBBB\nB\n", encoding="utf-8")
39 sections = normalize_ascii_file_sections(p, width=6, height=3)
40 assert_that(len(sections)).is_equal_to(2)
41 for sec in sections:
42 assert_that(len(sec)).is_equal_to(3)
43 assert_that(all(len(line) == 6 for line in sec)).is_true()