From b78010107187bf827c9b5569945af7650b6bdf76 Mon Sep 17 00:00:00 2001 From: Guy Kerem Date: Thu, 7 Oct 2021 17:47:10 +0300 Subject: [PATCH] raise error if element does not exist --- entropylab_qpudb/_qpudatabase.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/entropylab_qpudb/_qpudatabase.py b/entropylab_qpudb/_qpudatabase.py index 5d02b24..5e7d288 100644 --- a/entropylab_qpudb/_qpudatabase.py +++ b/entropylab_qpudb/_qpudatabase.py @@ -283,6 +283,11 @@ def set( :param new_confidence_interval: (optional) a ConfidenceInterval object which holds the error in this parameter """ root = self._con.root() + + if element not in root["elements"]: + raise AttributeError( + f"element {element} does not exist for element {element}" + ) if attribute not in root["elements"][element]: raise AttributeError( f"attribute {attribute} does not exist for element {element}" @@ -319,6 +324,11 @@ def add_attribute( :param new_confidence_interval: (optional) a ConfidenceInterval object which holds the error in this parameter """ root = self._con.root() + + if element not in root["elements"]: + raise AttributeError( + f"element {element} does not exist for element {element}" + ) if attribute in root["elements"][element]: raise AttributeError( f"attribute {attribute} already exists for element {element}" @@ -342,6 +352,11 @@ def remove_attribute(self, element: str, attribute: str) -> None: :param attribute: the name of the attribute to remove """ root = self._con.root() + + if element not in root["elements"]: + raise AttributeError( + f"element {element} does not exist for element {element}" + ) if attribute not in root["elements"][element]: raise AttributeError( f"attribute {attribute} does not exist for element {element}" @@ -372,6 +387,10 @@ def get(self, element: str, attribute: str) -> FrozenQpuParameter: data can be obtained """ root = self._con.root() + if element not in root["elements"]: + raise AttributeError( + f"element {element} does not exist for element {element}" + ) if attribute not in root["elements"][element]: raise AttributeError( f"attribute {attribute} does not exist for element {element}"