From ae22504a18ad415bc27bf762ad131c19873b1535 Mon Sep 17 00:00:00 2001 From: Markus Heikkinen Date: Tue, 14 Mar 2023 15:33:22 +0100 Subject: [PATCH] Session to raise ToolkitError instead of RuntimeError --- src/zhinst/toolkit/session.py | 13 +++++++++---- tests/test_data_server_session.py | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/zhinst/toolkit/session.py b/src/zhinst/toolkit/session.py index ef6e8703..b698f319 100644 --- a/src/zhinst/toolkit/session.py +++ b/src/zhinst/toolkit/session.py @@ -881,13 +881,18 @@ def raw_path_to_node( Corresponding toolkit node object. Raises: - RuntimeError: If the node does not belong to the optional module or + ValueError: If the `raw_path` does not start with a leading dash. + ToolkitError: If the node does not belong to the optional module or to a connected device. + + .. versionchanged:: 0.5.3 + + Changed `RuntimeError` to `ValueError`. """ if not raw_path.startswith("/"): - raise RuntimeError( + raise ValueError( f"{raw_path} does not seem to be an absolute path. " - "(it must start with a leading slash)" + "It must start with a leading slash." ) if module is not None: node = module.root.raw_path_to_node(raw_path) @@ -899,7 +904,7 @@ def raw_path_to_node( return self.root.raw_path_to_node(raw_path) return self.devices[serial].root.raw_path_to_node(raw_path) except KeyError as error: - raise RuntimeError( + raise ToolkitError( f"Node belongs to a device({raw_path.split('/')[1]}) not connected to " "the Data Server." ) from error diff --git a/tests/test_data_server_session.py b/tests/test_data_server_session.py index 8b958801..37ba5db1 100644 --- a/tests/test_data_server_session.py +++ b/tests/test_data_server_session.py @@ -312,7 +312,7 @@ def get_string_side_effect(arg): assert result.root.prefix_hide == "dev1234" # Only absolut paths are supported - with pytest.raises(RuntimeError) as e_info: + with pytest.raises(ValueError) as e_info: session.raw_path_to_node("dev1234/test/a/b/c") # Not connected device