Add failing unit test for sangaboard version before v1

This commit is contained in:
Julian Stirling 2025-12-02 11:00:41 +00:00
parent 70e052fa21
commit 797dda3514
2 changed files with 21 additions and 1 deletions

View file

@ -44,12 +44,12 @@ class SangaboardThing(BaseStage):
"""
self.sangaboard_kwargs = copy(kwargs)
self.sangaboard_kwargs["port"] = port
self._sangaboard_lock = threading.RLock()
super().__init__(**kwargs)
def __enter__(self) -> None:
"""Connect to the sangaboard when the Thing context manager is opened."""
self._sangaboard = sangaboard.Sangaboard(**self.sangaboard_kwargs)
self._sangaboard_lock = threading.RLock()
with self.sangaboard() as sb:
sb.query("blocking_moves false")
self.check_firmware()

20
tests/test_sangaboard.py Normal file
View file

@ -0,0 +1,20 @@
"""Tests for the Sangaboard thing."""
import pytest
from openflexure_microscope_server.things.stage.sangaboard import SangaboardThing
@pytest.fixture
def mock_sanga_thing(mocker):
"""Return a Sangaboard thing with a MagicMock for self._sangaboard."""
sanga_thing = SangaboardThing()
sanga_thing._sangaboard = mocker.MagicMock()
return sanga_thing
def test_check_old_firmware(mock_sanga_thing):
"""Check firmware prior to version 1 throws a Runtime Error."""
mock_sanga_thing._sangaboard.firmware_version.return_value = "0.1.1"
with pytest.raises(RuntimeError):
mock_sanga_thing.check_firmware()