tests: added more tests, pytest ini options in pyporject toml

This commit is contained in:
2026-04-22 16:59:30 +02:00
parent 2fc25cc7f5
commit 6e2023cefa
7 changed files with 59 additions and 11 deletions
+8
View File
@@ -35,6 +35,14 @@ aaredb = { index = "psi"}
name = "psi"
url = "https://gitea.psi.ch/api/packages/mx/pypi/simple"
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
norecursedirs = ["scripts", ".venv", "logs", "docs"]
markers = [
"integration: tests that require external systems or secrets",
]
[build-system]
requires = ["setuptools>=75.6.0"]
build-backend = "setuptools.build_meta"
@@ -0,0 +1,5 @@
import pytest
@pytest.mark.integration
def test_real_db_connection():
pass
@@ -6,7 +6,8 @@ from aare.common.models import DataCollectionParameters
def test_directory_defaults_when_missing():
params = DataCollectionParameters()
assert params.directory == "{date}/{prefix}"
assert params.directory == None
#TODO What should the defaults be? Do we want it to be "{date}/{prefix}"?
def test_directory_spaces_are_replaced():
@@ -27,3 +28,17 @@ def test_exposure_must_be_between_0_and_1():
def test_cloud_blank_defaults_to_true():
params = DataCollectionParameters(cloud="")
assert params.cloud is True
def test_directory_accepts_valid_macros():
params = DataCollectionParameters(directory="{date}/{prefix}/run")
assert params.directory == "{date}/{prefix}/run"
def test_aperture_accepts_float_string():
params = DataCollectionParameters(aperture="2.0")
assert params.aperture == 2
def test_processingpipeline_rejects_unknown_value():
with pytest.raises(ValidationError):
DataCollectionParameters(processingpipeline="xia2")
+4
View File
@@ -19,3 +19,7 @@ def test_get_best_for_class_returns_highest_confidence():
assert best is not None
assert best.conf == 0.7
def test_get_best_for_class_returns_none_when_missing():
model = MLOutputModel()
assert model.get_best_for_class(MLBoxType.Crystal) is None
@@ -33,3 +33,15 @@ def test_get_camera_settings_raises_when_empty():
model = ZoomModel(z={})
with pytest.raises(ValueError):
model.get_camera_settings(100)
def test_get_camera_settings_below_minimum_returns_first():
model = ZoomModel(
z={
100: SampleCameraSettings(gain=1.0, exposure=0.1),
200: SampleCameraSettings(gain=2.0, exposure=0.2),
}
)
settings = model.get_camera_settings(50)
assert settings.gain == 1.0
assert settings.exposure == 0.1
+14 -1
View File
@@ -24,4 +24,17 @@ def test_prediction_score_uses_count_and_max_confidence():
model.add_box(MLBoxType.Pin, (0, 0, 10, 10), 0.4)
model.add_box(MLBoxType.Crystal, (1, 1, 9, 9), 0.8)
assert MlBox._prediction_score(model) == (2, 0.8)
assert MlBox._prediction_score(model) == (2, 0.8)
def test_best_by_class_keeps_highest_confidence_per_class():
results = [
{"class": 1, "confidence": 0.4, "box": {"x1": 0, "y1": 0, "x2": 10, "y2": 10}},
{"class": 1, "confidence": 0.8, "box": {"x1": 1, "y1": 1, "x2": 11, "y2": 11}},
{"class": 2, "confidence": 0.6, "box": {"x1": 2, "y1": 2, "x2": 12, "y2": 12}},
]
out = MlBox._best_by_class(results)
assert out is not None
assert out.get_best_for_class(MLBoxType.Pin).conf == 0.8
assert out.get_best_for_class(MLBoxType.Crystal).conf == 0.6
@@ -1,11 +1,2 @@
import sys
import pytest
from PySide6.QtWidgets import QApplication
@pytest.fixture(scope="session")
def qapp():
app = QApplication.instance()
if app is None:
app = QApplication(sys.argv)
return app