Skip to content

Commit cf1fb98

Browse files
authored
Print empty char after updated code exercise (#80)
To enforce `clear_output` even when the update is not printing anything we used `print("", end"")` this seems not to always work so we print an empty char now. In the tests this introduces another output that makes the tests fail checking the number of outputs. Because the number of outputs is testing anything meaningful we remove these tests. There are tests that check the joined texts of the outputs that cover the outputs already good enough.
1 parent eb1e3a9 commit cf1fb98

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/scwidgets/exercise/_widget_code_exercise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ def _on_click_update_action(self) -> bool:
727727

728728
# The clear_output command at the beginning of the function waits till
729729
# something is printed. If nothing is printed, it is not cleared. We
730-
# enforce it to be invoked by printing an empty string
731-
print("", end="")
730+
# enforce it to be invoked by printing an empty char
731+
print("\0", end="")
732732

733733
return not (raised_error)
734734

tests/test_widgets.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,6 @@ def test_code_exercise(
12341234
if tunable_params:
12351235
outputs = nb_cell.find_elements(By.CLASS_NAME, OUTPUT_CLASS_NAME)
12361236
# In the code we print a text that adds another output
1237-
assert len(outputs) == 1 + include_code
12381237
before_parameter_change_text = "".join([output.text for output in outputs])
12391238

12401239
slider_input_box = nb_cell.find_element(By.CLASS_NAME, "widget-readout")
@@ -1257,15 +1256,13 @@ def test_code_exercise(
12571256
# Check if output has changed only after click when manual
12581257
outputs = nb_cell.find_elements(By.CLASS_NAME, OUTPUT_CLASS_NAME)
12591258
# In the code we print a text that adds another output
1260-
assert len(outputs) == 1 + include_code
12611259
after_parameter_change_text = "".join(
12621260
[output.text for output in outputs]
12631261
)
12641262
assert before_parameter_change_text == after_parameter_change_text
12651263
update_button.click()
12661264

12671265
outputs = nb_cell.find_elements(By.CLASS_NAME, OUTPUT_CLASS_NAME)
1268-
assert len(outputs) == 1 + include_code
12691266
after_parameter_change_text = "".join([output.text for output in outputs])
12701267
assert before_parameter_change_text != after_parameter_change_text
12711268

0 commit comments

Comments
 (0)