Skip to content

Commit

Permalink
Change APIparameters to params
Browse files Browse the repository at this point in the history
This effects the classes `CodeExercise` and `ParameterPanel`
  • Loading branch information
agoscinski committed Nov 28, 2024
1 parent 4b64b65 commit 5e615d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/scwidgets/code/_widget_parameter_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def parameters_trait(self) -> List[str]:
return ["value"] * len(self._parameters_widget)

@property
def parameters(self) -> dict:
def params(self) -> dict:
"""
:return: All parameters that were given on input are returned. Including also
fixed parameters.
:return: All parameters that were given on initialization are returned,
also including also fixed parameters.
"""
return self._interactive_widget.kwargs.copy()

@parameters.setter
def parameters(self, parameters: dict):
@params.setter
def params(self, parameters: dict):
for i, key in enumerate(self._interactive_widget.kwargs.keys()):
self._interactive_widget.kwargs_widgets[i].value = parameters[key]

Expand Down
18 changes: 8 additions & 10 deletions src/scwidgets/exercise/_widget_code_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __init__(
)
elif isinstance(parameters, ParameterPanel):
compatibility_result = code.compatible_with_signature(
list(parameters.parameters.keys())
list(parameters.params.keys())
)
if compatibility_result != "":
raise ValueError(
Expand Down Expand Up @@ -480,9 +480,7 @@ def answer(self) -> dict:
return {
"code": None if self._code is None else self._code.function_body,
"parameter_panel": (
None
if self._parameter_panel is None
else self._parameter_panel.parameters
None if self._parameter_panel is None else self._parameter_panel.params
),
}

Expand All @@ -498,7 +496,7 @@ def answer(self, answer: dict):
if answer["code"] is not None and self._code is not None:
self._code.function_body = answer["code"]
if answer["parameter_panel"] is not None and self._parameter_panel is not None:
self._parameter_panel.parameters = answer["parameter_panel"]
self._parameter_panel.params = answer["parameter_panel"]

if self._save_cue_box is not None:
self._save_cue_box.observe_widgets()
Expand All @@ -519,14 +517,14 @@ def panel_parameters(self) -> Dict[str, Check.FunInParamT]:
return {}

@property
def parameters(self) -> Dict[str, Check.FunInParamT]:
def params(self) -> Dict[str, Check.FunInParamT]:
"""
:return: All parameters that were given on input are returned. Including also
fixed parameters.
:return: All parameters that were given on initialization are returned,
also including also fixed parameters.
"""
if self._parameter_panel is not None:
parameter_panel = self._parameter_panel
return parameter_panel.parameters
return parameter_panel.params
return {}

@property
Expand Down Expand Up @@ -680,7 +678,7 @@ def _on_click_update_action(self) -> bool:
else:
self._update_func(self) # type: ignore[call-arg]
elif self._code is not None:
self.run_code(**self.parameters)
self.run_code(**self.params)

for cue_output in self.cue_outputs:
if hasattr(cue_output, "draw_display"):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ def get_code_exercise(
if update_func_argless:

def update_print():
output = code_ex.run_code(**code_ex.parameters)
output = code_ex.run_code(**code_ex.params)
code_ex.cue_outputs[0].display_object = f"Output:\n{output}"

else:

def update_print(code_ex: CodeExercise):
output = code_ex.run_code(**code_ex.parameters)
output = code_ex.run_code(**code_ex.params)
code_ex.cue_outputs[0].display_object = f"Output:\n{output}"

code_ex = CodeExercise(
Expand Down Expand Up @@ -224,7 +224,7 @@ def test_compute_and_set_references(self, code_ex):
],
)
def test_run_code(self, code_ex):
output = code_ex.run_code(**code_ex.parameters)
output = code_ex.run_code(**code_ex.params)
assert np.allclose((output,), code_ex.checks[0].outputs_references[0])

@pytest.mark.parametrize(
Expand All @@ -240,7 +240,7 @@ def test_erroneous_run_code(self, code_ex):
CodeValidationError,
match="name 'bug' is not defined.*",
):
code_ex.run_code(**code_ex.parameters)
code_ex.run_code(**code_ex.params)

@pytest.mark.parametrize(
"function",
Expand Down

0 comments on commit 5e615d9

Please sign in to comment.