Skip to content

Commit

Permalink
rename code.CodeDemo exercise.CodeExercise
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Dec 25, 2023
1 parent e02ee6d commit 820d104
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 81 deletions.
2 changes: 0 additions & 2 deletions src/scwidgets/code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from ._widget_code_demo import CodeDemo
from ._widget_code_input import CodeInput
from ._widget_parameter_panel import ParameterPanel

__all__ = [
"CodeDemo",
"CodeInput",
"ParameterPanel",
]
5 changes: 3 additions & 2 deletions src/scwidgets/code/_widget_parameter_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ParameterPanel(VBox):
:param parameters:
Can be any input that is allowed as keyword arguments in ipywidgets.interactive
for the parameters. _options and other widget layout parameter are controlled
by CodeDemo.
by CodeExercise.
"""

Expand All @@ -25,7 +25,8 @@ def __init__(
if "_option" in parameters.keys():
raise ValueError(
"Found interactive argument `_option` in paramaters, but "
"CodeDemo controls this parameter to ensure correct initialization."
"ParameterPanels should be controled by an exercise widget "
"to ensure correct initialization."
)

# we use a dummy function because interactive executes it once on init
Expand Down
3 changes: 2 additions & 1 deletion src/scwidgets/exercise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._widget_code_exercise import CodeExercise
from ._widget_text_exercise import TextExercise

__all__ = ["TextExercise"]
__all__ = ["CodeExercise", "TextExercise"]
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from .._utils import Formatter
from ..answer import AnswerRegistry, AnswerWidget
from ..check import Check, CheckableWidget, CheckRegistry, ChecksResult
from ..code._widget_code_input import CodeInput
from ..code._widget_parameter_panel import ParameterPanel
from ..cue import (
CheckCueBox,
CheckResetCueButton,
Expand All @@ -21,11 +23,9 @@
UpdateCueBox,
UpdateResetCueButton,
)
from ._widget_code_input import CodeInput
from ._widget_parameter_panel import ParameterPanel


class CodeDemo(VBox, CheckableWidget, AnswerWidget):
class CodeExercise(VBox, CheckableWidget, AnswerWidget):
"""
A widget to demonstrate code interactively in a variety of ways. It is a combination
of the several widgets that allow to check check, run and visualize code.
Expand All @@ -50,7 +50,7 @@ class CodeDemo(VBox, CheckableWidget, AnswerWidget):
:param update_func:
A function that is run during the update process. The function takes as argument
the CodeDemo, so it can update all cue_ouputs
the CodeExercise, so it can update all cue_ouputs
"""

Expand All @@ -66,7 +66,7 @@ def __init__(
update_mode: str = "release",
cue_outputs: Union[None, CueOutput, List[CueOutput]] = None,
update_func: Optional[
Callable[[CodeDemo], Union[Any, Check.FunOutParamsT]]
Callable[[CodeExercise], Union[Any, Check.FunOutParamsT]]
] = None,
exercise_description: Optional[str] = None,
exercise_title: Optional[str] = None,
Expand Down
9 changes: 4 additions & 5 deletions tests/notebooks/widget_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

import scwidgets
from scwidgets.answer import AnswerRegistry
from scwidgets.code import CodeDemo
from scwidgets.exercise import TextExercise
from scwidgets.exercise import CodeExercise, TextExercise

sys.path.insert(0, os.path.abspath("../.."))

Expand All @@ -46,20 +45,20 @@

# Test 3:
# -------
# Test if CodeDemo shows correct output
# Test if CodeExercise shows correct output


# +
def foo(x):
return x


code_demo = CodeDemo(
code_ex = CodeExercise(
foo,
parameters={"x": (0, 2, 1)},
update_mode="manual",
answer_registry=answer_registry,
answer_key="exercise_2",
)
code_demo
code_ex
# -
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@

sys.path.insert(0, os.path.abspath("../.."))
from tests.test_check import single_param_check # noqa: E402
from tests.test_code import get_code_demo # noqa: E402
from tests.test_code import get_code_exercise # noqa: E402

# -

scwidgets.get_css_style()

# Test 1:
# -------
# Test if CodeDemo shows correct output
# Test if CodeExercise shows correct output

# Test 1.1
get_code_demo(
get_code_exercise(
[single_param_check(use_fingerprint=False, failing=False, buggy=False)],
include_checks=True,
include_params=True,
Expand All @@ -41,7 +41,7 @@
)

# Test 1.2
get_code_demo(
get_code_exercise(
[single_param_check(use_fingerprint=False, failing=True, buggy=False)],
include_checks=True,
include_params=True,
Expand All @@ -50,7 +50,7 @@
)

# Test 1.3
get_code_demo(
get_code_exercise(
[single_param_check(use_fingerprint=False, failing=False, buggy=True)],
include_checks=True,
include_params=True,
Expand All @@ -59,7 +59,7 @@
)

# Test 1.4
get_code_demo(
get_code_exercise(
[single_param_check(use_fingerprint=False, failing=False, buggy=False)],
include_checks=True,
include_params=True,
Expand All @@ -68,7 +68,7 @@
)

# Test 1.5
get_code_demo(
get_code_exercise(
[single_param_check(use_fingerprint=False, failing=False, buggy=False)],
include_checks=True,
include_params=True,
Expand All @@ -77,7 +77,7 @@
)

# Test 1.6
get_code_demo(
get_code_exercise(
[single_param_check(use_fingerprint=False, failing=False, buggy=False)],
include_checks=True,
include_params=True,
Expand All @@ -88,7 +88,7 @@

# Test 2:
# -------
# Test if CodeDemo works correct for only update
# Test if CodeExercise works correct for only update


# +
Expand All @@ -99,7 +99,7 @@ def function_to_check():
return 5


get_code_demo(
get_code_exercise(
[],
code=function_to_check,
include_checks=False,
Expand All @@ -111,25 +111,39 @@ def function_to_check():

# Test 2.2
# TODO
# get_code_demo([single_param_check(use_fingerprint=False, failing=True, buggy=False)],
# include_checks=False, include_params=True, tunable_params)
# get_code_exercise(
# [single_param_check(use_fingerprint=False, failing=True, buggy=False)],
# include_checks=False,
# include_params=True,
# tunable_params=True,
# )

# Test 2.3
# TODO
# get_code_demo([single_param_check(use_fingerprint=True, failing=True, buggy=False)],
# include_checks=False, include_params=True, tunable_params)
# get_code_exercise(
# [single_param_check(use_fingerprint=True, failing=True, buggy=False)],
# include_checks=False,
# include_params=True,
# tunable_params=True,
# )


# Test 3:
# -------
# Test if CodeDemo works correct for only checks
# Test if CodeExercise works correct for only checks

# Test 3.1
# TODO
# get_code_demo([single_param_check(use_fingerprint=False, failing=True, buggy=False)],
# include_checks=True, include_params=False)
# get_code_exercise(
# [single_param_check(use_fingerprint=False, failing=True, buggy=False)],
# include_checks=True,
# include_params=False,
# )

# Test 3.2
# TODO
# get_code_demo([single_param_check(use_fingerprint=True, failing=True, buggy=False)],
# include_checks=True, include_params=False)
# get_code_exercise(
# [single_param_check(use_fingerprint=True, failing=True, buggy=False)],
# include_checks=True,
# include_params=False,
# )
Loading

0 comments on commit 820d104

Please sign in to comment.