otko/tests/gui/test_section_forms.py
smillmorel 61b850bf46
Some checks failed
CI / lint (pull_request) Has been cancelled
CI / type (pull_request) Has been cancelled
CI / test-headless (macos-latest, 3.10) (pull_request) Has been cancelled
CI / test-headless (macos-latest, 3.11) (pull_request) Has been cancelled
CI / test-headless (macos-latest, 3.12) (pull_request) Has been cancelled
CI / test-headless (ubuntu-latest, 3.10) (pull_request) Has been cancelled
CI / test-headless (ubuntu-latest, 3.11) (pull_request) Has been cancelled
CI / test-headless (ubuntu-latest, 3.12) (pull_request) Has been cancelled
CI / test-headless (windows-latest, 3.10) (pull_request) Has been cancelled
CI / test-headless (windows-latest, 3.11) (pull_request) Has been cancelled
CI / test-headless (windows-latest, 3.12) (pull_request) Has been cancelled
CI / test-gui (pull_request) Has been cancelled
CI / test-integration (macos-latest) (pull_request) Has been cancelled
CI / test-integration (ubuntu-latest) (pull_request) Has been cancelled
CI / test-integration (windows-latest) (pull_request) Has been cancelled
style: resolve the remaining ruff findings
Auto-fixes (UP037, UP038, F401, I001, SIM105, RUF100) plus hand-fixes:
drop the now-unused `Union` imports, annotate mutable class attributes
with ClassVar, raise ValidationError instead of blind Exception in the
zero-length test, delete two dead locals, and bind the per-iteration
grid-builder closures to their loop variables (B023).
2026-09-16 13:20:36 -04:00

100 lines
2.4 KiB
Python

"""Regression: clicking a FiberSection / SectionAggregator row in the
Section Library must not crash ``form_for`` with KeyError."""
from __future__ import annotations
import pytest
pytest.importorskip("PySide6")
from otko.core import (
AggregatorDOF,
ElasticSection,
FiberSection,
RectangularPatch,
SectionAggregator,
)
from otko.views.dialogs.section_forms import (
FORM_REGISTRY,
form_for,
)
def test_fiber_section_has_registered_form() -> None:
assert "FiberSection" in FORM_REGISTRY
def test_section_aggregator_has_registered_form() -> None:
assert "SectionAggregator" in FORM_REGISTRY
@pytest.mark.gui
def test_form_for_elastic_section_returns_editable_form(qtbot) -> None: # type: ignore[no-untyped-def]
s = ElasticSection(
id=1,
name="Rect",
E=200e9,
A=0.01,
Iz=1e-5,
Iy=1e-5,
G=80e9,
J=1e-6,
)
f = form_for(s)
qtbot.addWidget(f)
assert f.type_label == "Elastic Section"
@pytest.mark.gui
def test_form_for_fiber_section_returns_summary(qtbot) -> None: # type: ignore[no-untyped-def]
s = FiberSection(
id=1,
name="RC",
patches=[
RectangularPatch(
material_id=1,
n_fib_y=4,
n_fib_z=4,
y_i=-0.1,
z_i=-0.15,
y_j=0.1,
z_j=0.15,
)
],
)
f = form_for(s)
qtbot.addWidget(f)
assert f.type_label == "Fiber Section"
# read() round-trips without crashing.
out = f.read(1)
assert isinstance(out, FiberSection)
assert len(out.patches) == 1
@pytest.mark.gui
def test_form_for_section_aggregator_returns_summary(qtbot) -> None: # type: ignore[no-untyped-def]
s = SectionAggregator(
id=2,
name="Agg",
section_id=1,
pairings=[AggregatorDOF(material_id=3, dof="T")],
)
f = form_for(s)
qtbot.addWidget(f)
assert f.type_label == "Section Aggregator"
@pytest.mark.gui
def test_form_for_unknown_type_falls_back(qtbot) -> None: # type: ignore[no-untyped-def]
"""An unknown section type must NOT raise — the dialog gets a
placeholder form so the whole UI doesn't go down."""
class _Mystery:
type = "NotRegistered"
id = 99
name = "???"
f = form_for(_Mystery())
qtbot.addWidget(f)
# Placeholder form exists; no exception raised.
assert f is not None