Skip to content

Commit

Permalink
Merge pull request #18 from mvdwetering/make_subunit_init_more_robust
Browse files Browse the repository at this point in the history
Make subunit init more robust
  • Loading branch information
mvdwetering authored Aug 5, 2024
2 parents 426353c + 21385d3 commit e738412
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit e738412

Please sign in to comment.