From 7ddc71ceeea7caff4413c977054733df7b8cae02 Mon Sep 17 00:00:00 2001 From: VivienP Date: Mon, 17 Aug 2026 16:48:59 +0200 Subject: [PATCH] fix(resources): make TipTracker.get_tip use pending state Align get_tip() with has_tip and VolumeTracker so public getters expose the same transactional view. Add regression tests for pending add and remove. Co-authored-by: Cursor --- pylabrobot/resources/tip_tracker.py | 6 +++--- pylabrobot/resources/tip_tracker_tests.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pylabrobot/resources/tip_tracker.py b/pylabrobot/resources/tip_tracker.py index 1a876ce86f5..4b1ee76b92c 100644 --- a/pylabrobot/resources/tip_tracker.py +++ b/pylabrobot/resources/tip_tracker.py @@ -57,15 +57,15 @@ def has_tip(self) -> bool: return self._pending_tip is not None def get_tip(self) -> "Tip": - """Get the tip. Note that does includes pending operations. + """Get the tip. Note that this includes pending operations. Raises: NoTipError: If the tip spot does not have a tip. """ - if self._tip is None: + if self._pending_tip is None: raise NoTipError(f"{self.thing} does not have a tip.") - return self._tip + return self._pending_tip def disable(self) -> None: """Disable the tip tracker.""" diff --git a/pylabrobot/resources/tip_tracker_tests.py b/pylabrobot/resources/tip_tracker_tests.py index dabd924a528..6fff42bb598 100644 --- a/pylabrobot/resources/tip_tracker_tests.py +++ b/pylabrobot/resources/tip_tracker_tests.py @@ -43,3 +43,17 @@ def test_remove_tip(self): with self.assertRaises(NoTipError): tracker.get_tip() + + def test_get_tip_includes_pending_add(self): + tracker = TipTracker(thing="tester") + tracker.add_tip(self.tip, commit=False) + self.assertEqual(tracker.has_tip, True) + self.assertEqual(tracker.get_tip(), self.tip) + + def test_get_tip_includes_pending_remove(self): + tracker = TipTracker(thing="tester") + tracker.add_tip(self.tip) + tracker.remove_tip(commit=False) + self.assertEqual(tracker.has_tip, False) + with self.assertRaises(NoTipError): + tracker.get_tip()