Skip to content

Commit

Permalink
Update ui validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseMckinzie committed Oct 8, 2024
1 parent 2f1c5af commit 0fd0ab5
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/sophios/api/utils/ict/ict_spec/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,31 @@ class ICT(Metadata):

inputs: list[IO]
outputs: list[IO]
ui: Optional[list[UIItem]]
ui: Optional[list[UIItem]] = None
hardware: Optional[HardwareRequirements] = None

@model_validator(mode="after")
def validate_ui(self) -> "ICT":
"""Validate that the ui matches the inputs and outputs."""
io_dict = {"inputs": [], "outputs": []} # type: ignore
ui_keys = [ui.key.root.split(".") for ui in self.ui]
for ui_ in ui_keys:
io_dict[ui_[0]].append(ui_[1])
input_names = [io.name for io in self.inputs]
output_names = [io.name for io in self.outputs]
inp_bool = [x in input_names for x in io_dict["inputs"]]
out_bool = [x in output_names for x in io_dict["outputs"]]

if not all(inp_bool):
raise ValueError(
f"The ui keys must match the inputs and outputs keys. Unmatched: inputs.{set(io_dict['inputs'])-set(input_names)}"
)
if not all(out_bool):
raise ValueError(
f"The ui keys must match the inputs and outputs keys. Unmatched: outputs.{set(io_dict['outputs'])-set(output_names)}"
)
if self.ui is not None:
io_dict = {"inputs": [], "outputs": []} # type: ignore
ui_keys = [ui.key.root.split(".") for ui in self.ui]
for ui_ in ui_keys:
io_dict[ui_[0]].append(ui_[1])
input_names = [io.name for io in self.inputs]
output_names = [io.name for io in self.outputs]
inp_bool = [x in input_names for x in io_dict["inputs"]]
out_bool = [x in output_names for x in io_dict["outputs"]]

if not all(inp_bool):
raise ValueError(
f"The ui keys must match the inputs and outputs keys. Unmatched: inputs.{set(io_dict['inputs'])-set(input_names)}"
)
if not all(out_bool):
raise ValueError(
f"The ui keys must match the inputs and outputs keys. Unmatched: outputs.{set(io_dict['outputs'])-set(output_names)}"
)

return self

def to_clt(self, network_access: bool = False) -> dict:
Expand Down

0 comments on commit 0fd0ab5

Please sign in to comment.