Skip to content
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

Make subunit init more robust #18

Merged
merged 3 commits into from
Aug 5, 2024
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
16 changes: 15 additions & 1 deletion tests/test_subunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,21 @@ def test_status_not_ok_ignored(


def test_write_function_calls_connection_put(
connection, initialized_dummysubunit: SubunitBase, update_callback
connection, initialized_dummysubunit: DummySubunit, update_callback
):
initialized_dummysubunit.dummy_function = 123
connection.put.assert_called_with("UAW", "DUMMY_FUNCTION", "123")

def test_unreadable_attributes_ignored(connection):
'''
This test is specifically to check handling of unreadable attributes
as found with issue https://github.com/mvdwetering/yamaha_ynca/issues/315
'''

class descriptor:
def __get__(self, instance, owner):
raise AttributeError("unreadable attribute")

DummySubunit.__provides__ = descriptor()
DummySubunit(connection)

2 changes: 1 addition & 1 deletion ynca/subunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, connection: YncaConnection) -> None:
# otherwise the YncaFunction descriptors get/set functions would trigger.
# Sort the list to have a deterministic/understandable order for easier testing
for attribute_name in sorted(dir(self.__class__)):
attribute = getattr(self.__class__, attribute_name)
attribute = getattr(self.__class__, attribute_name, None)
if isinstance(attribute, FunctionMixinBase):
self.function_handlers[attribute.name] = YncaFunctionHandler(attribute)

Expand Down