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

Upgrading to widget-code-input 4 and adding tests for lab 4 #45

Merged
merged 12 commits into from
Jul 3, 2024
Merged
37 changes: 37 additions & 0 deletions .github/workflows/tests-lab-4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests - lab 4

on:
push:
branches: [main]
pull_request:
# Check all PR

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
python-version: "3.11"

steps:
- uses: actions/checkout@v3
- name: Install Firefox
uses: browser-actions/setup-firefox@latest

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install tox

- name: run Python tests
run: tox -e tests-lab-4

- name: run Python tests for coverage
run: tox -e coverage
- uses: codecov/codecov-action@v3
with:
files: coverage.xml
verbose: true
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
dependencies = [
"ipywidgets>=8.0.0",
"numpy<2.0.0",
"widget_code_input<4.0.0",
"widget_code_input>=4.0.13",
"matplotlib",
"termcolor"
]
Expand Down
21 changes: 18 additions & 3 deletions src/scwidgets/cue/_widget_cue_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ def __init__(
# we close the figure so the figure is only contained in this widget
# and not shown using plt.show()
plt.close(self.figure)
elif matplotlib.backends.backend == "module://ipympl.backend_nbagg":
elif (
matplotlib.backends.backend == "module://ipympl.backend_nbagg"
or matplotlib.backends.backend == "widget"
):
# jupyter lab 3 uses "module://ipympl.backend_nbagg"
# jupyter lab 4 uses "widget"
with self:
self.figure.canvas.show()
else:
Expand All @@ -83,7 +88,12 @@ def clear_display(self, wait=False):
if matplotlib.backends.backend == "module://matplotlib_inline.backend_inline":
self.clear_figure()
self.clear_output(wait=wait)
elif matplotlib.backends.backend == "module://ipympl.backend_nbagg":
elif (
matplotlib.backends.backend == "module://ipympl.backend_nbagg"
or matplotlib.backends.backend == "widget"
):
# jupyter lab 3 uses "module://ipympl.backend_nbagg"
# jupyter lab 4 uses "widget"
self.clear_figure()
if not (wait):
self.figure.canvas.draw_idle()
Expand All @@ -100,7 +110,12 @@ def draw_display(self):
if matplotlib.backends.backend == "module://matplotlib_inline.backend_inline":
with self:
display(self.figure)
elif matplotlib.backends.backend == "module://ipympl.backend_nbagg":
elif (
matplotlib.backends.backend == "module://ipympl.backend_nbagg"
or matplotlib.backends.backend == "widget"
):
# jupyter lab 3 uses "module://ipympl.backend_nbagg"
# jupyter lab 4 uses "widget"
self.figure.canvas.draw_idle()
self.figure.canvas.flush_events()
else:
Expand Down
23 changes: 15 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from urllib.parse import urljoin

import pytest
from packaging.version import Version
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
Expand All @@ -17,7 +18,7 @@
JUPYTER_VERSION = None


def get_jupyter_version() -> str:
def get_jupyter_version() -> Version:
"""
Function so we can update the jupyter version during initialization
and use it in other files
Expand Down Expand Up @@ -45,7 +46,7 @@ def notebook_service():
["jupyter", f"{JUPYTER_TYPE}", "--version"]
)
# convert to string
JUPYTER_VERSION = jupyter_version.decode().replace("\n", "")
JUPYTER_VERSION = Version(jupyter_version.decode().replace("\n", ""))

jupyter_process = subprocess.Popen(
[
Expand Down Expand Up @@ -106,17 +107,20 @@ def _selenium_driver(nb_path):

# jupyter lab < 4
if JUPYTER_TYPE == "lab":
if get_jupyter_version() < "4.0.0":
if get_jupyter_version() < Version("4.0.0"):
restart_kernel_button_class_name = (
"bp3-button.bp3-minimal.jp-ToolbarButtonComponent.minimal.jp-Button"
)
restart_kernel_button_title_attribute = (
"Restart Kernel and Run All Cells…"
)
else:
raise ValueError("jupyter lab > 4.0.0 is not supported.")
restart_kernel_button_class_name = "jp-ToolbarButtonComponent"
restart_kernel_button_title_attribute = (
"Restart the kernel and run all cells"
)
elif JUPYTER_TYPE == "notebook":
if get_jupyter_version() < "7.0.0":
if get_jupyter_version() < Version("7.0.0"):
restart_kernel_button_class_name = "btn.btn-default"
restart_kernel_button_title_attribute = (
"restart the kernel, then re-run the whole notebook (with dialog)"
Expand Down Expand Up @@ -169,15 +173,18 @@ def _selenium_driver(nb_path):
# -------------------------------

if JUPYTER_TYPE == "lab":
if get_jupyter_version() < "4.0.0":
if get_jupyter_version() < Version("4.0.0"):
restart_button_class_name = (
"jp-Dialog-button.jp-mod-accept.jp-mod-warn.jp-mod-styled"
)
restart_button_text = "Restart"
else:
raise ValueError("jupyter lab > 4.0.0 is not supported.")
restart_button_class_name = (
"jp-Dialog-button.jp-mod-accept.jp-mod-warn.jp-mod-styled"
)
restart_button_text = "Restart"
elif JUPYTER_TYPE == "notebook":
if get_jupyter_version() < "7.0.0":
if get_jupyter_version() < Version("7.0.0"):
restart_button_class_name = "btn.btn-default.btn-sm.btn-danger"
restart_button_text = "Restart and Run All Cells"
else:
Expand Down
Loading
Loading