Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of exercise_key without ExerciseRegistry #88

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/scwidgets/exercise/_widget_code_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,13 @@ def __init__(
"code and params do no match: " + compatibility_result
)

CheckableWidget.__init__(self, check_registry, exercise_key)
ExerciseWidget.__init__(self, exercise_registry, exercise_key)
name = kwargs.get("name", exercise_key)
CheckableWidget.__init__(self, check_registry, name)
if exercise_registry is not None:
ExerciseWidget.__init__(self, exercise_registry, exercise_key)
else:
# otherwise ExerciseWidget constructor will raise an error
ExerciseWidget.__init__(self, None, None)

self._code = code
self._output = CueOutput()
Expand Down
18 changes: 18 additions & 0 deletions tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,21 @@ def test_figure(self):
assert isinstance(code_ex.figure, Figure)
assert code_ex.output.figure is code_ex.figure
assert code_ex.outputs[0] is code_ex.output

def test_consrtuction_with_registries(self):
"""Because the exercise key is used for the `ExerciseRegistry` and the
`CheckRegistry` we need to ensure the `CodeExercise` can be run with
each individual one and both"""
CodeExercise(
exercise_key="some_key",
check_registry=CheckRegistry(),
)
CodeExercise(
exercise_key="some_key",
exercise_registry=ExerciseRegistry(),
)
CodeExercise(
exercise_key="some_key",
check_registry=CheckRegistry(),
exercise_registry=ExerciseRegistry(),
)
Loading