def __init__( self, serial: str, device_type: str, session: "Session", ): self._serial = serial self._device_type = device_type self._session = session try: self._options = session.daq_server.getString(f"/{serial}/features/options") except RuntimeError: self._options = "" # HF2 does not support listNodesJSON so we have the information hardcoded # (the node of HF2 will not change any more so this is safe) preloaded_json = None if "HF2" in self._device_type: preloaded_json = self._load_preloaded_json( Path(__file__).parent / "../../resources/nodedoc_hf2.json" ) nodetree = NodeTree( self._session.daq_server, prefix_hide=self._serial, list_nodes=[f"/{self._serial}/*"], preloaded_json=preloaded_json, ) # Add predefined parseres (in node_parser) to nodetree nodes nodetree.update_nodes( node_parser.get(self.__class__.__name__, {}), raise_for_invalid_node=False ) super().__init__(nodetree, tuple())
def test_update_nodes(connection): tree = NodeTree(connection, "DEV1234") tree.update_nodes({ "demods/0/rate": { "Unit": "test" }, "demods/0/order": { "Unit": "test2" } }) assert tree.demods[0].rate.node_info.unit == "test" assert tree.demods[0].order.node_info.unit == "test2" with pytest.raises(KeyError) as e_info: tree.update_nodes({ "demods/0/rate": { "Unit": "test3" }, "test": { "Node": "test" } }) assert tree.demods[0].rate.node_info.unit == "test3" tree.update_nodes( { "demods/0/rate": { "Unit": "test3" }, "test": { "Node": "test4" } }, add=True) assert tree.test.node_info.path == "test4" assert tree.test.is_valid() is True # Test for not raising any errors tree.update_nodes( { "312/123": { "Unit": "test5" }, "testNOtexists": { "Node": "test5" } }, add=False, raise_for_invalid_node=False, ) assert tree.testNOtexists.is_valid() is False