From 8235b0528e5fe02224cdf993e58ae8605aee4958 Mon Sep 17 00:00:00 2001 From: Rob Berwick Date: Sun, 16 Feb 2025 08:31:10 +0000 Subject: [PATCH] fix: ensure backend check correctly raises exception when not set --- src/blinkstick/clients/blinkstick.py | 2 +- tests/clients/test_blinkstick.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/blinkstick/clients/blinkstick.py b/src/blinkstick/clients/blinkstick.py index ca3d4e8..d03c9d8 100644 --- a/src/blinkstick/clients/blinkstick.py +++ b/src/blinkstick/clients/blinkstick.py @@ -71,7 +71,7 @@ def __getattribute__(self, name): if callable(attr) and not getattr(attr, "no_backend_required", False): def wrapper(*args, **kwargs): - if self.backend is None: + if not getattr(self, "backend", None): raise NotConnected("No backend set") return attr(*args, **kwargs) diff --git a/tests/clients/test_blinkstick.py b/tests/clients/test_blinkstick.py index 6ac420f..067ac7a 100644 --- a/tests/clients/test_blinkstick.py +++ b/tests/clients/test_blinkstick.py @@ -17,10 +17,11 @@ def test_instantiate(): assert bs is not None -def test_all_methods_require_backend(make_blinkstick): +def test_all_methods_require_backend(): """Test that all methods require a backend.""" - bs = make_blinkstick() - bs.backend = None # noqa + # Create an instance of BlinkStick. Note that we do not use the mock, or pass a device. + # This is deliberate, as we want to test that all methods raise an exception when the backend is not set. + bs = BlinkStick() class_methods = ( method