Skip to content

fix: ensure backend check correctly raises exception when not set #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/blinkstick/clients/blinkstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions tests/clients/test_blinkstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down