otko/tests/unit/test_zerolength_section.py
smillmorel ba783718d4 chore: adopt remaining local development state
Catch-all for the intermixed residue of the unpushed otko-development
work ported into this tree: combinations/console-dock/quick-guide wiring
across commands, core, services, views and tests; repo-wide ruff-format
normalization; README/CONTRIBUTING updates; and the toolbar default
(both toolbars now open in the top area, quick guide text updated).

Splitting this further would require hunk-level surgery with low
confidence; the preceding commits in this branch isolate the
self-contained features.
2026-09-16 12:03:22 -04:00

64 lines
1.8 KiB
Python

"""Unit tests for ZeroLengthSectionElement model + serialization."""
from __future__ import annotations
import pytest
from otko.core import (
ElasticSection,
Node,
Project,
ZeroLengthSectionElement,
)
from otko.services import load_project, save_project
def test_zero_length_section_schema_defaults() -> None:
el = ZeroLengthSectionElement(id=1, nodes=(1, 2), section_id=5)
assert el.type == "ZeroLengthSection"
assert el.nodes == (1, 2)
assert el.section_id == 5
def test_zero_length_section_rejects_extra_fields() -> None:
with pytest.raises(Exception):
ZeroLengthSectionElement(
id=1,
nodes=(1, 2),
section_id=1,
bogus="not allowed", # type: ignore[call-arg]
)
def test_zero_length_section_round_trips(tmp_path) -> None: # type: ignore[no-untyped-def]
"""A project containing a zeroLengthSection must save+load unchanged."""
p = Project(
ndm=2,
ndf=3,
nodes=[
Node(id=1, coords=(0, 0, 0), restraint=(True, True, False, False, False, True)),
Node(id=2, coords=(0, 0, 0), restraint=(False, True, False, False, False, False)),
],
sections=[
ElasticSection(
id=1,
name="Box",
E=200e9,
A=0.01,
Iz=1e-5,
Iy=1e-5,
G=80e9,
J=1e-6,
)
],
elements=[
ZeroLengthSectionElement(id=10, nodes=(1, 2), section_id=1),
],
)
path = tmp_path / "mk.osmodel"
save_project(p, path)
r = load_project(path)
assert len(r.elements) == 1
assert isinstance(r.elements[0], ZeroLengthSectionElement)
assert r.elements[0].nodes == (1, 2)
assert r.elements[0].section_id == 1