feat: shared unit-aware formatting helpers
Pure presentation helpers (labels, number parse/format) shared by docks and dialogs; no Qt imports.
This commit is contained in:
parent
1d21006281
commit
f1d58273b7
2 changed files with 148 additions and 0 deletions
51
tests/unit/test_formatting.py
Normal file
51
tests/unit/test_formatting.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"""Unit tests for :mod:`otko.views.formatting` (no Qt required)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from otko.core import UnitSystem
|
||||
from otko.views.formatting import (
|
||||
DOF_LABELS,
|
||||
MASS_LABELS,
|
||||
RESTRAINT_LABELS,
|
||||
format_number,
|
||||
parse_float,
|
||||
parse_int,
|
||||
unit_label,
|
||||
)
|
||||
|
||||
|
||||
def test_label_tuples() -> None:
|
||||
assert DOF_LABELS == ("Ux", "Uy", "Uz", "Rx", "Ry", "Rz")
|
||||
assert MASS_LABELS == ("Mx", "My", "Mz", "Ixx", "Iyy", "Izz")
|
||||
assert RESTRAINT_LABELS == ("Ux", "Uy", "Uz", "Rx", "Ry", "Rz")
|
||||
|
||||
|
||||
def test_format_number() -> None:
|
||||
assert format_number(50.0) == "50"
|
||||
assert format_number(1.5) == "1.5"
|
||||
|
||||
|
||||
def test_parse_float_required() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
parse_float("", "x")
|
||||
|
||||
|
||||
def test_parse_float_allow_empty() -> None:
|
||||
assert parse_float("", "x", allow_empty=True) == 0.0
|
||||
|
||||
|
||||
def test_parse_int_rejects_fractional() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
parse_int("1.5", "x")
|
||||
|
||||
|
||||
def test_unit_label() -> None:
|
||||
assert unit_label("force", UnitSystem.SI_M_N) == "N"
|
||||
assert unit_label("moment", UnitSystem.US_FT_KIP) == "kip·ft"
|
||||
|
||||
|
||||
def test_unit_label_unknown_quantity() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
unit_label("temperature", UnitSystem.SI_M_N)
|
||||
Loading…
Reference in a new issue