Skip to content

Commit 92fe2c9

Browse files
committed
Tests: Adding tests for fix of #53
Adding tests if invalid code theme returns error. Adding tests if widget view is updated on change of function_body trait.
1 parent f5fb308 commit 92fe2c9

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ---
2+
# jupyter:
3+
# jupytext:
4+
# cell_metadata_filter: -all
5+
# text_representation:
6+
# extension: .py
7+
# format_name: light
8+
# format_version: '1.5'
9+
# jupytext_version: 1.15.0
10+
# kernelspec:
11+
# display_name: Python 3 (ipykernel)
12+
# language: python
13+
# name: python3
14+
# ---
15+
16+
# +
17+
import scwidgets
18+
from scwidgets.code import CodeInput
19+
20+
# -
21+
22+
scwidgets.get_css_style()
23+
24+
# Test 1:
25+
# -------
26+
# Test if CodeInput traits are updading the widget view
27+
28+
29+
# +
30+
def foo():
31+
return "init"
32+
33+
34+
ci = CodeInput(foo)
35+
ci
36+
# -
37+
38+
ci.function_body = """return 'change'"""

tests/test_code.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ def test_get_code(self):
6767
):
6868
CodeInput.get_code(lambda x: x)
6969

70+
def test_invalid_code_theme_raises_error(self):
71+
with pytest.raises(
72+
ValueError, match=r"Given code_theme 'invalid_theme' invalid.*"
73+
):
74+
CodeInput(TestCodeInput.mock_function_1, code_theme="invalid_theme")
75+
7076

7177
def get_code_exercise(
7278
checks: List[Check],

tests/test_widgets.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,23 @@ def test_privacy_policy(selenium_driver):
249249
).click()
250250

251251

252+
def test_scwidgets_code_input(selenium_driver):
253+
"""
254+
Tests the widget of the module code
255+
256+
:param selenium_driver: see conftest.py
257+
"""
258+
driver = selenium_driver("tests/notebooks/widget_scwidgets_code_input.ipynb")
259+
260+
nb_cells = NotebookCellList(driver)
261+
# Test 1:
262+
# -------
263+
264+
# Tests if change in function_body changed the widget view
265+
code_input_lines = nb_cells[2].find_elements(By.CLASS_NAME, CODE_MIRROR_CLASS_NAME)
266+
assert "return 'change'" in code_input_lines[-1].text
267+
268+
252269
class TestExerciseWidgets:
253270
prefix = "pytest"
254271

0 commit comments

Comments
 (0)