|
1 | 1 | # SPDX-License-Identifier: LGPL-2.1-or-later |
2 | 2 |
|
3 | | -# Copyright (C) 2020, 2021 igo95862 |
| 3 | +# Copyright (C) 2020-2023 igo95862 |
4 | 4 |
|
5 | 5 | # This file is part of python-sdbus |
6 | 6 |
|
|
22 | 22 |
|
23 | 23 | from asyncio import Event, get_running_loop, sleep, wait_for |
24 | 24 | from asyncio.subprocess import create_subprocess_exec |
25 | | -from typing import Tuple |
| 25 | +from typing import Tuple, cast |
26 | 26 | from unittest import SkipTest |
27 | 27 |
|
28 | 28 | from sdbus.dbus_common_funcs import PROPERTY_FLAGS_MASK, count_bits |
| 29 | +from sdbus.dbus_proxy_async_interfaces import DBUS_PROPERTIES_CHANGED_TYPING |
29 | 30 | from sdbus.exceptions import ( |
30 | 31 | DbusFailedError, |
31 | 32 | DbusFileExistsError, |
|
41 | 42 | is_interface_name_valid, |
42 | 43 | ) |
43 | 44 | from sdbus.unittest import IsolatedDbusTestCase |
| 45 | +from sdbus.utils import parse_properties_changed |
44 | 46 |
|
45 | 47 | from sdbus import ( |
46 | 48 | DbusInterfaceCommonAsync, |
@@ -823,3 +825,42 @@ async def test_empty_signal(self) -> None: |
823 | 825 | self.assertIsNone(await wait_for(aw_dbus, timeout=1)) |
824 | 826 |
|
825 | 827 | self.assertIsNone(await wait_for(q.get(), timeout=1)) |
| 828 | + |
| 829 | + async def test_properties_changed(self) -> None: |
| 830 | + test_object, test_object_connection = initialize_object() |
| 831 | + |
| 832 | + test_str = 'should_be_emited' |
| 833 | + |
| 834 | + q = await test_object_connection.properties_changed._get_dbus_queue() |
| 835 | + |
| 836 | + async def set_property() -> None: |
| 837 | + await test_object_connection.test_property.set_async(test_str) |
| 838 | + |
| 839 | + await set_property() |
| 840 | + |
| 841 | + properties_changed_data = cast( |
| 842 | + DBUS_PROPERTIES_CHANGED_TYPING, |
| 843 | + (await q.get()).get_contents(), |
| 844 | + ) |
| 845 | + |
| 846 | + parsed_dict_from_class = parse_properties_changed( |
| 847 | + TestInterface, properties_changed_data) |
| 848 | + self.assertEqual( |
| 849 | + test_str, |
| 850 | + parsed_dict_from_class['test_property'], |
| 851 | + ) |
| 852 | + |
| 853 | + parsed_dict_from_object = parse_properties_changed( |
| 854 | + test_object_connection, properties_changed_data) |
| 855 | + self.assertEqual( |
| 856 | + test_str, |
| 857 | + parsed_dict_from_object['test_property'], |
| 858 | + ) |
| 859 | + |
| 860 | + properties_changed_data[2].append('invalidated_property') |
| 861 | + parsed_dict_with_invalidation = parse_properties_changed( |
| 862 | + test_object, properties_changed_data, |
| 863 | + on_unknown_member='reuse', |
| 864 | + ) |
| 865 | + self.assertIsNone( |
| 866 | + parsed_dict_with_invalidation['invalidated_property']) |
0 commit comments