From 26bf738605d252289bd52f11ef2c64c763756530 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Burfeind Date: Tue, 13 Feb 2024 12:14:23 +0100 Subject: [PATCH] fix: Correct the type of shelf files in internal_server and address_space. Path.is_file does not consume strings, as shelf.open does only consume string and not pathlib.Path. --- asyncua/server/address_space.py | 2 +- asyncua/server/internal_server.py | 2 +- tests/test_sync.py | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/asyncua/server/address_space.py b/asyncua/server/address_space.py index c10031a9f..07de08c86 100644 --- a/asyncua/server/address_space.py +++ b/asyncua/server/address_space.py @@ -707,7 +707,7 @@ def make_aspace_shelf(self, path: Path): Note: Intended for slow devices, such as Raspberry Pi, to greatly improve start up time """ - with shelve.open(path, 'n', protocol=pickle.HIGHEST_PROTOCOL) as s: + with shelve.open(str(path), 'n', protocol=pickle.HIGHEST_PROTOCOL) as s: for nodeid, ndata in self._nodes.items(): s[nodeid.to_string()] = ndata diff --git a/asyncua/server/internal_server.py b/asyncua/server/internal_server.py index a6fc411f3..ccbf19399 100644 --- a/asyncua/server/internal_server.py +++ b/asyncua/server/internal_server.py @@ -139,7 +139,7 @@ async def load_standard_address_space(self, shelf_file: Optional[Path] = None): if shelf_file: is_file = await asyncio.get_running_loop().run_in_executor( None, Path.is_file, shelf_file - ) or await asyncio.get_running_loop().run_in_executor(None, Path.is_file, f'{shelf_file}.db') + ) or await asyncio.get_running_loop().run_in_executor(None, Path.is_file, shelf_file / '.db') if is_file: # import address space from shelf await asyncio.get_running_loop().run_in_executor(None, self.aspace.load_aspace_shelf, shelf_file) diff --git a/tests/test_sync.py b/tests/test_sync.py index 25219aed9..d1d9b9083 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -187,9 +187,6 @@ def test_sync_server_get_node(server, idx): assert vars[0].read_value() == 6.7 -@pytest.mark.xfail( - raises=AttributeError, reason="asyncua introduced a regression, likely when we switched to pathlib", strict=True - ) async def test_sync_server_creating_shelf_files_works(tloop: ThreadLoop, tmp_path: Path) -> None: shelf_file_path: Path = tmp_path / "shelf_file"