otko/tests/gui/test_section_extrusion.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

86 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Smoke tests for the Show Extruded Sections overlay."""
from __future__ import annotations
import pytest
pytest.importorskip("PySide6")
from otko.core import (
ElasticBeamColumn,
ElasticSection,
Node,
Project,
)
def _frame_project() -> Project:
# Rectangular section 0.3×0.5 m.
b, h = 0.30, 0.50
A = b * h
Iz = b * h**3 / 12.0
Iy = h * b**3 / 12.0
return Project(
nodes=[
Node(id=1, coords=(0.0, 0.0, 0.0), restraint=(True, True, True, True, True, True)),
Node(id=2, coords=(6.0, 0.0, 0.0)),
],
sections=[
ElasticSection(
id=1,
name="Rect",
E=200e9,
A=A,
Iz=Iz,
Iy=Iy,
G=80e9,
J=1e-6,
)
],
elements=[
ElasticBeamColumn(id=1, nodes=(1, 2), section_id=1),
],
)
@pytest.mark.gui
def test_toggle_creates_and_removes_extrusion_actor(qtbot) -> None: # type: ignore[no-untyped-def]
from otko.views.canvas3d.model_canvas import ModelCanvas
canvas = ModelCanvas()
qtbot.addWidget(canvas)
canvas.show_project(_frame_project())
before = len(canvas._renderer._aux_actors)
canvas.set_show_section_extrusions(True)
after_on = len(canvas._renderer._aux_actors)
assert after_on > before, "Extrusion actor should appear after toggling on"
canvas.set_show_section_extrusions(False)
after_off = len(canvas._renderer._aux_actors)
assert after_off == before, "Extrusion actor must disappear when toggled off"
@pytest.mark.gui
def test_extrusion_skips_elements_without_section(qtbot) -> None: # type: ignore[no-untyped-def]
"""A truss element has no section — it must be skipped silently."""
from otko.core import ElasticUniaxial, TrussElement
from otko.views.canvas3d.model_canvas import ModelCanvas
canvas = ModelCanvas()
qtbot.addWidget(canvas)
p = Project(
nodes=[
Node(id=1, coords=(0, 0, 0), restraint=(True, True, True, True, True, True)),
Node(id=2, coords=(3, 0, 0)),
],
materials=[ElasticUniaxial(id=1, E=200e9)],
elements=[
TrussElement(id=1, nodes=(1, 2), area=1e-3, material_id=1),
],
)
canvas.show_project(p)
canvas.set_show_section_extrusions(True)
# No crash, no extra actor (truss has no section_id).
# (Other aux actors like the grid might exist; only verify nothing blew up.)
assert canvas._renderer._aux_actors is not None