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
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).
63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
"""Unit tests for element types."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pydantic import TypeAdapter, ValidationError
|
|
|
|
from otko.core import (
|
|
ElasticBeamColumn,
|
|
Element,
|
|
ForceBeamColumn,
|
|
TrussElement,
|
|
ZeroLengthElement,
|
|
)
|
|
|
|
element_adapter: TypeAdapter[Element] = TypeAdapter(Element)
|
|
|
|
|
|
def test_truss_construct() -> None:
|
|
t = TrussElement(id=1, nodes=(1, 2), area=0.01, material_id=1)
|
|
assert t.type == "Truss"
|
|
assert t.nodes == (1, 2)
|
|
|
|
|
|
def test_truss_requires_two_nodes() -> None:
|
|
with pytest.raises(ValidationError):
|
|
TrussElement(id=1, nodes=(1,), area=0.01, material_id=1) # type: ignore[arg-type]
|
|
with pytest.raises(ValidationError):
|
|
TrussElement(id=1, nodes=(1, 2, 3), area=0.01, material_id=1) # type: ignore[arg-type]
|
|
|
|
|
|
def test_truss_area_must_be_positive() -> None:
|
|
with pytest.raises(ValidationError):
|
|
TrussElement(id=1, nodes=(1, 2), area=-0.01, material_id=1)
|
|
|
|
|
|
def test_elastic_beam_default_geom_transf() -> None:
|
|
e = ElasticBeamColumn(id=1, nodes=(1, 2), section_id=1)
|
|
assert e.geom_transf == "Linear"
|
|
|
|
|
|
def test_force_beam_integration_points_bounds() -> None:
|
|
ForceBeamColumn(id=1, nodes=(1, 2), section_id=1, integration_points=5)
|
|
with pytest.raises(ValidationError):
|
|
ForceBeamColumn(id=1, nodes=(1, 2), section_id=1, integration_points=1)
|
|
with pytest.raises(ValidationError):
|
|
ForceBeamColumn(id=1, nodes=(1, 2), section_id=1, integration_points=11)
|
|
|
|
|
|
def test_zero_length_dofs_match_materials() -> None:
|
|
z = ZeroLengthElement(id=1, nodes=(1, 2), material_ids=(1, 2), dofs=(1, 2))
|
|
assert z.dofs == (1, 2)
|
|
|
|
|
|
def test_element_union_round_trip() -> None:
|
|
for original in [
|
|
TrussElement(id=1, nodes=(1, 2), area=0.01, material_id=1),
|
|
ElasticBeamColumn(id=2, nodes=(1, 2), section_id=1, geom_transf="PDelta"),
|
|
]:
|
|
payload = element_adapter.dump_python(original, mode="json")
|
|
restored = element_adapter.validate_python(payload)
|
|
assert type(restored) is type(original)
|
|
assert restored.id == original.id
|