Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
raise error if element does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
qguyk committed Oct 12, 2021
1 parent 22baa28 commit b780101
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions entropylab_qpudb/_qpudatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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}"
Expand All @@ -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}"
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit b780101

Please sign in to comment.