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).
99 lines
2.6 KiB
Python
99 lines
2.6 KiB
Python
"""Tests for UpdateElementFieldsCommand — inline scalar edits."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
pytest.importorskip("PySide6")
|
|
|
|
from otko.commands import (
|
|
AddElementsCommand,
|
|
AddMaterialsCommand,
|
|
AddNodesCommand,
|
|
UpdateElementFieldsCommand,
|
|
)
|
|
from otko.core import (
|
|
ElasticUniaxial,
|
|
Node,
|
|
TrussElement,
|
|
)
|
|
from otko.viewmodels import ProjectViewModel
|
|
|
|
|
|
def _vm_with_truss() -> ProjectViewModel:
|
|
vm = ProjectViewModel()
|
|
vm.new_project()
|
|
vm.apply_command(
|
|
AddNodesCommand(
|
|
vm,
|
|
[
|
|
Node(id=1, coords=(0, 0, 0)),
|
|
Node(id=2, coords=(3, 0, 0)),
|
|
],
|
|
)
|
|
)
|
|
vm.apply_command(
|
|
AddMaterialsCommand(
|
|
vm,
|
|
[
|
|
ElasticUniaxial(id=1, name="Steel", E=200e9),
|
|
],
|
|
)
|
|
)
|
|
vm.apply_command(
|
|
AddElementsCommand(
|
|
vm,
|
|
[
|
|
TrussElement(id=1, nodes=(1, 2), area=0.001, material_id=1),
|
|
],
|
|
)
|
|
)
|
|
return vm
|
|
|
|
|
|
@pytest.mark.gui
|
|
def test_update_area_on_truss_element(qtbot) -> None: # type: ignore[no-untyped-def]
|
|
vm = _vm_with_truss()
|
|
vm.apply_command(UpdateElementFieldsCommand(vm, 1, {"area": 0.00645}))
|
|
assert vm.project.element(1).area == pytest.approx(0.00645)
|
|
|
|
|
|
@pytest.mark.gui
|
|
def test_update_area_is_undoable(qtbot) -> None: # type: ignore[no-untyped-def]
|
|
vm = _vm_with_truss()
|
|
vm.apply_command(UpdateElementFieldsCommand(vm, 1, {"area": 0.005}))
|
|
vm.undo_stack.undo()
|
|
assert vm.project.element(1).area == pytest.approx(0.001)
|
|
vm.undo_stack.redo()
|
|
assert vm.project.element(1).area == pytest.approx(0.005)
|
|
|
|
|
|
@pytest.mark.gui
|
|
def test_unknown_field_is_silently_ignored(qtbot) -> None: # type: ignore[no-untyped-def]
|
|
"""Fields not in the element's model are filtered out — no exception."""
|
|
vm = _vm_with_truss()
|
|
vm.apply_command(
|
|
UpdateElementFieldsCommand(
|
|
vm,
|
|
1,
|
|
{"section_id": 42}, # TrussElement has no section_id
|
|
)
|
|
)
|
|
# The element is unchanged.
|
|
assert vm.project.element(1).area == pytest.approx(0.001)
|
|
assert vm.project.element(1).material_id == 1
|
|
|
|
|
|
@pytest.mark.gui
|
|
def test_update_multiple_fields_at_once(qtbot) -> None: # type: ignore[no-untyped-def]
|
|
vm = _vm_with_truss()
|
|
vm.apply_command(
|
|
UpdateElementFieldsCommand(
|
|
vm,
|
|
1,
|
|
{"area": 0.003, "rho": 7850.0},
|
|
)
|
|
)
|
|
el = vm.project.element(1)
|
|
assert el.area == pytest.approx(0.003)
|
|
assert el.rho == pytest.approx(7850.0)
|