76 lines
1.7 KiB
Python
76 lines
1.7 KiB
Python
import os
|
|
import sys
|
|
import types
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
from aare.common.models import SampleShortInfo, DewarAddress
|
|
|
|
# Ensure safe defaults during tests
|
|
os.environ.setdefault("BEAMLINE", "SIMULATED")
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
|
|
|
|
def install_module(name: str):
|
|
mod = types.ModuleType(name)
|
|
sys.modules[name] = mod
|
|
return mod
|
|
|
|
|
|
# -------------------------
|
|
# aarelcinfer_client mocks
|
|
# -------------------------
|
|
install_module("aarelcinfer_client")
|
|
install_module("aarelcinfer_client.api")
|
|
|
|
m = install_module("aarelcinfer_client.models")
|
|
|
|
class LatestPredictionModel:
|
|
@classmethod
|
|
def model_validate(cls, data):
|
|
return cls()
|
|
|
|
def model_dump(self):
|
|
return {}
|
|
|
|
m.LatestPredictionModel = LatestPredictionModel
|
|
|
|
|
|
# -------------------------
|
|
# aarescan_client mocks
|
|
# -------------------------
|
|
install_module("aarescan_client")
|
|
install_module("aarescan_client.models")
|
|
|
|
grid = install_module("aarescan_client.models.grid_request")
|
|
grid.GridRequest = type("GridRequest", (), {})
|
|
|
|
screen = install_module("aarescan_client.models.screen_request")
|
|
screen.ScreenRequest = type("ScreenRequest", (), {})
|
|
|
|
|
|
# -------------------------
|
|
# Qt app fixture
|
|
# -------------------------
|
|
@pytest.fixture(scope="session")
|
|
def qapp():
|
|
app = QApplication.instance()
|
|
if app is None:
|
|
app = QApplication(sys.argv)
|
|
return app
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_info():
|
|
return SampleShortInfo(
|
|
db_id=1,
|
|
puck_name="puck1",
|
|
dewar_name="dew1",
|
|
sample_name="sample1",
|
|
run_number=1,
|
|
user="group1",
|
|
pin=3,
|
|
location=DewarAddress(segment="A", pos=2),
|
|
) |