Files
PacketStation/tests/server/test_traveler_fit.py
T

20 lines
808 B
Python
Raw Normal View History

"""Work-order text on the traveler stays inside its own box (issue #42). No database needed."""
from __future__ import annotations
def test_work_order_text_fits_its_box() -> None:
# Issue #42: long work-order text shrinks, then clips, instead of running over the next QR code
from reportlab.pdfbase.pdfmetrics import stringWidth
from packetstation.pdf.doc import font_of
from packetstation.pdf.traveler import fit_line
assert fit_line("L662001", 145, 12, bold=True) == ("L662001", 12)
for s, size, bold in [
("L662001/1-SUB-99999-EXTRA-LONG", 12, True),
("Lot 12 Seq 40 WELD-STALL-HYDROTEST-LONG-NAME", 8.5, False),
]:
text, z = fit_line(s, 145, size, bold=bold)
assert size * 0.7 <= z <= size and stringWidth(text, font_of(bold), z) <= 145