Skip to content

Commit e025b01

Browse files
committed
Upgrade to widget_code_input version 4 and tests for lab 4 (PR #45)
With widget_code_input 4 the WidgetCodeInput can now be used in lab 4. The tests have been updated to test support lab 4.
2 parents 989f7c1 + 79680a2 commit e025b01

File tree

6 files changed

+244
-70
lines changed

6 files changed

+244
-70
lines changed

.github/workflows/tests-lab-4.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Tests - lab 4
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
# Check all PR
8+
9+
jobs:
10+
tests:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
include:
15+
- os: ubuntu-22.04
16+
python-version: "3.11"
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Install Firefox
21+
uses: browser-actions/setup-firefox@latest
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- run: pip install tox
28+
29+
- name: run Python tests
30+
run: tox -e tests-lab-4
31+
32+
- name: run Python tests for coverage
33+
run: tox -e coverage
34+
- uses: codecov/codecov-action@v3
35+
with:
36+
files: coverage.xml
37+
verbose: true

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ classifiers = [
3030
dependencies = [
3131
"ipywidgets>=8.0.0",
3232
"numpy<2.0.0",
33-
"widget_code_input<4.0.0",
33+
"widget_code_input>=4.0.13",
3434
"matplotlib",
3535
"termcolor"
3636
]

src/scwidgets/cue/_widget_cue_figure.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ def __init__(
6565
# we close the figure so the figure is only contained in this widget
6666
# and not shown using plt.show()
6767
plt.close(self.figure)
68-
elif matplotlib.backends.backend == "module://ipympl.backend_nbagg":
68+
elif (
69+
matplotlib.backends.backend == "module://ipympl.backend_nbagg"
70+
or matplotlib.backends.backend == "widget"
71+
):
72+
# jupyter lab 3 uses "module://ipympl.backend_nbagg"
73+
# jupyter lab 4 uses "widget"
6974
with self:
7075
self.figure.canvas.show()
7176
else:
@@ -83,7 +88,12 @@ def clear_display(self, wait=False):
8388
if matplotlib.backends.backend == "module://matplotlib_inline.backend_inline":
8489
self.clear_figure()
8590
self.clear_output(wait=wait)
86-
elif matplotlib.backends.backend == "module://ipympl.backend_nbagg":
91+
elif (
92+
matplotlib.backends.backend == "module://ipympl.backend_nbagg"
93+
or matplotlib.backends.backend == "widget"
94+
):
95+
# jupyter lab 3 uses "module://ipympl.backend_nbagg"
96+
# jupyter lab 4 uses "widget"
8797
self.clear_figure()
8898
if not (wait):
8999
self.figure.canvas.draw_idle()
@@ -100,7 +110,12 @@ def draw_display(self):
100110
if matplotlib.backends.backend == "module://matplotlib_inline.backend_inline":
101111
with self:
102112
display(self.figure)
103-
elif matplotlib.backends.backend == "module://ipympl.backend_nbagg":
113+
elif (
114+
matplotlib.backends.backend == "module://ipympl.backend_nbagg"
115+
or matplotlib.backends.backend == "widget"
116+
):
117+
# jupyter lab 3 uses "module://ipympl.backend_nbagg"
118+
# jupyter lab 4 uses "widget"
104119
self.figure.canvas.draw_idle()
105120
self.figure.canvas.flush_events()
106121
else:

tests/conftest.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from urllib.parse import urljoin
55

66
import pytest
7+
from packaging.version import Version
78
from selenium.common.exceptions import StaleElementReferenceException
89
from selenium.webdriver.common.by import By
910
from selenium.webdriver.support import expected_conditions
@@ -17,7 +18,7 @@
1718
JUPYTER_VERSION = None
1819

1920

20-
def get_jupyter_version() -> str:
21+
def get_jupyter_version() -> Version:
2122
"""
2223
Function so we can update the jupyter version during initialization
2324
and use it in other files
@@ -45,7 +46,7 @@ def notebook_service():
4546
["jupyter", f"{JUPYTER_TYPE}", "--version"]
4647
)
4748
# convert to string
48-
JUPYTER_VERSION = jupyter_version.decode().replace("\n", "")
49+
JUPYTER_VERSION = Version(jupyter_version.decode().replace("\n", ""))
4950

5051
jupyter_process = subprocess.Popen(
5152
[
@@ -106,17 +107,20 @@ def _selenium_driver(nb_path):
106107

107108
# jupyter lab < 4
108109
if JUPYTER_TYPE == "lab":
109-
if get_jupyter_version() < "4.0.0":
110+
if get_jupyter_version() < Version("4.0.0"):
110111
restart_kernel_button_class_name = (
111112
"bp3-button.bp3-minimal.jp-ToolbarButtonComponent.minimal.jp-Button"
112113
)
113114
restart_kernel_button_title_attribute = (
114115
"Restart Kernel and Run All Cells…"
115116
)
116117
else:
117-
raise ValueError("jupyter lab > 4.0.0 is not supported.")
118+
restart_kernel_button_class_name = "jp-ToolbarButtonComponent"
119+
restart_kernel_button_title_attribute = (
120+
"Restart the kernel and run all cells"
121+
)
118122
elif JUPYTER_TYPE == "notebook":
119-
if get_jupyter_version() < "7.0.0":
123+
if get_jupyter_version() < Version("7.0.0"):
120124
restart_kernel_button_class_name = "btn.btn-default"
121125
restart_kernel_button_title_attribute = (
122126
"restart the kernel, then re-run the whole notebook (with dialog)"
@@ -169,15 +173,18 @@ def _selenium_driver(nb_path):
169173
# -------------------------------
170174

171175
if JUPYTER_TYPE == "lab":
172-
if get_jupyter_version() < "4.0.0":
176+
if get_jupyter_version() < Version("4.0.0"):
173177
restart_button_class_name = (
174178
"jp-Dialog-button.jp-mod-accept.jp-mod-warn.jp-mod-styled"
175179
)
176180
restart_button_text = "Restart"
177181
else:
178-
raise ValueError("jupyter lab > 4.0.0 is not supported.")
182+
restart_button_class_name = (
183+
"jp-Dialog-button.jp-mod-accept.jp-mod-warn.jp-mod-styled"
184+
)
185+
restart_button_text = "Restart"
179186
elif JUPYTER_TYPE == "notebook":
180-
if get_jupyter_version() < "7.0.0":
187+
if get_jupyter_version() < Version("7.0.0"):
181188
restart_button_class_name = "btn.btn-default.btn-sm.btn-danger"
182189
restart_button_text = "Restart and Run All Cells"
183190
else:

0 commit comments

Comments
 (0)