otko/tests/unit/test_zerolength_section.py
smill f361fee969 feat: named case-result load combinations with full GUI support
Snapshots the current development tree, headlined by proper load
combinations (user request): a reusable LoadCombination entity of
weighted completed static-case results (e.g. 1.2xDead + 1.6xLive).

- core: LoadCombination/LoadCombinationItem entities, Project
  integration (lookup, unique ids, reference validation)
- services: combinations.py (linear superposition + envelope),
  exported via services __init__
- commands: undoable Add/Delete/Update for combinations
- GUI: Load Combinations manager dialog, Run-dialog evaluation,
  envelope display in Results panel, Combinations tab in Table dock
- tests: unit coverage (validation, math, error paths) + integration
  superposition check vs a single factored run
2026-09-11 13:19:59 -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