From b02df03c90061935bde5451ada866c089775e087 Mon Sep 17 00:00:00 2001 From: Michel van de Wetering Date: Mon, 5 Aug 2024 19:34:11 +0200 Subject: [PATCH 1/3] Add test to check failure --- tests/test_subunit.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test_subunit.py b/tests/test_subunit.py index 2610961..25e379f 100644 --- a/tests/test_subunit.py +++ b/tests/test_subunit.py @@ -1,6 +1,7 @@ """Test Zone subunit""" from unittest import mock +from unittest.mock import create_autospec import pytest from ynca import Avail @@ -8,6 +9,7 @@ from ynca.subunit import SubunitBase from ynca.function import IntFunctionMixin from ynca.errors import YncaInitializationFailedException +from ynca.subunits.system import System SYS = "SYS" @@ -140,7 +142,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) + From c95afc4e9993948fc2bf37715070dfc417027230 Mon Sep 17 00:00:00 2001 From: Michel van de Wetering Date: Mon, 5 Aug 2024 19:36:28 +0200 Subject: [PATCH 2/3] Don't fail on non-readable attributes --- ynca/subunit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ynca/subunit.py b/ynca/subunit.py index ef0f253..b3507a8 100644 --- a/ynca/subunit.py +++ b/ynca/subunit.py @@ -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) From 21385d3a53287f4fa15e3c3b5f63975b767e25da Mon Sep 17 00:00:00 2001 From: Michel van de Wetering Date: Mon, 5 Aug 2024 19:43:38 +0200 Subject: [PATCH 3/3] Remove unused imports --- tests/test_subunit.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_subunit.py b/tests/test_subunit.py index 25e379f..7f08670 100644 --- a/tests/test_subunit.py +++ b/tests/test_subunit.py @@ -1,7 +1,6 @@ """Test Zone subunit""" from unittest import mock -from unittest.mock import create_autospec import pytest from ynca import Avail @@ -9,7 +8,6 @@ from ynca.subunit import SubunitBase from ynca.function import IntFunctionMixin from ynca.errors import YncaInitializationFailedException -from ynca.subunits.system import System SYS = "SYS"