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

76 lines
2.4 KiB
Python

"""GUI tests for the Run Analysis dialog."""
from __future__ import annotations
from pathlib import Path
import pytest
pytest.importorskip("PySide6")
from PySide6.QtCore import QObject, Signal
from otko.core import LinearTimeSeries, PlainLoadPattern, TransientCase
from otko.viewmodels import ProjectViewModel
from otko.views.dialogs.run_analysis import RunAnalysisDialog
class _FakeRunner(QObject):
started = Signal()
log = Signal(str)
finished = Signal(object)
failed = Signal(str)
runningChanged = Signal(bool)
def __init__(self) -> None:
super().__init__()
self.is_running = False
self.last_project = None
self.last_case = None
self.last_results_dir = None
def run(self, project, case, results_dir=None) -> None: # type: ignore[no-untyped-def]
self.last_project = project
self.last_case = case
self.last_results_dir = results_dir
@pytest.mark.gui
def test_run_dialog_applies_transient_damping_overrides(qtbot, tmp_path) -> None: # type: ignore[no-untyped-def]
vm = ProjectViewModel()
vm.new_project()
vm.project.time_series.append(LinearTimeSeries(id=1, name="Ramp")) # type: ignore[union-attr]
vm.project.load_patterns.append(PlainLoadPattern(id=1, name="P1", time_series_id=1)) # type: ignore[union-attr]
vm.project.analyses.append(
TransientCase( # type: ignore[union-attr]
id=1,
name="EQ",
pattern_ids=[1],
dt=0.01,
n_steps=10,
rayleigh_alpha_m=0.1,
rayleigh_beta_k=0.002,
rayleigh_mode1_damping=0.02,
)
)
vm._path = Path(tmp_path) / "demo.osmodel" # type: ignore[attr-defined]
runner = _FakeRunner()
dlg = RunAnalysisDialog(vm, runner)
qtbot.addWidget(dlg)
dlg._case_combo.setCurrentIndex(0)
assert dlg._alpha_m.value() == pytest.approx(0.1)
assert dlg._beta_k.value() == pytest.approx(0.002)
assert dlg._mode1_damping.value() == pytest.approx(0.02)
dlg._alpha_m.setValue(0.3)
dlg._beta_k.setValue(0.005)
dlg._mode1_damping.setValue(0.05)
dlg._on_run()
assert runner.last_project is vm.project
assert runner.last_case.rayleigh_alpha_m == pytest.approx(0.3)
assert runner.last_case.rayleigh_beta_k == pytest.approx(0.005)
assert runner.last_case.rayleigh_mode1_damping == pytest.approx(0.05)
assert runner.last_results_dir == tmp_path / "demo_results"