|
4 | 4 | from urllib.parse import urljoin |
5 | 5 |
|
6 | 6 | import pytest |
| 7 | +from packaging.version import Version |
7 | 8 | from selenium.common.exceptions import StaleElementReferenceException |
8 | 9 | from selenium.webdriver.common.by import By |
9 | 10 | from selenium.webdriver.support import expected_conditions |
|
17 | 18 | JUPYTER_VERSION = None |
18 | 19 |
|
19 | 20 |
|
20 | | -def get_jupyter_version() -> str: |
| 21 | +def get_jupyter_version() -> Version: |
21 | 22 | """ |
22 | 23 | Function so we can update the jupyter version during initialization |
23 | 24 | and use it in other files |
@@ -45,7 +46,7 @@ def notebook_service(): |
45 | 46 | ["jupyter", f"{JUPYTER_TYPE}", "--version"] |
46 | 47 | ) |
47 | 48 | # convert to string |
48 | | - JUPYTER_VERSION = jupyter_version.decode().replace("\n", "") |
| 49 | + JUPYTER_VERSION = Version(jupyter_version.decode().replace("\n", "")) |
49 | 50 |
|
50 | 51 | jupyter_process = subprocess.Popen( |
51 | 52 | [ |
@@ -106,17 +107,20 @@ def _selenium_driver(nb_path): |
106 | 107 |
|
107 | 108 | # jupyter lab < 4 |
108 | 109 | if JUPYTER_TYPE == "lab": |
109 | | - if get_jupyter_version() < "4.0.0": |
| 110 | + if get_jupyter_version() < Version("4.0.0"): |
110 | 111 | restart_kernel_button_class_name = ( |
111 | 112 | "bp3-button.bp3-minimal.jp-ToolbarButtonComponent.minimal.jp-Button" |
112 | 113 | ) |
113 | 114 | restart_kernel_button_title_attribute = ( |
114 | 115 | "Restart Kernel and Run All Cells…" |
115 | 116 | ) |
116 | 117 | 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 | + ) |
118 | 122 | elif JUPYTER_TYPE == "notebook": |
119 | | - if get_jupyter_version() < "7.0.0": |
| 123 | + if get_jupyter_version() < Version("7.0.0"): |
120 | 124 | restart_kernel_button_class_name = "btn.btn-default" |
121 | 125 | restart_kernel_button_title_attribute = ( |
122 | 126 | "restart the kernel, then re-run the whole notebook (with dialog)" |
@@ -169,15 +173,18 @@ def _selenium_driver(nb_path): |
169 | 173 | # ------------------------------- |
170 | 174 |
|
171 | 175 | if JUPYTER_TYPE == "lab": |
172 | | - if get_jupyter_version() < "4.0.0": |
| 176 | + if get_jupyter_version() < Version("4.0.0"): |
173 | 177 | restart_button_class_name = ( |
174 | 178 | "jp-Dialog-button.jp-mod-accept.jp-mod-warn.jp-mod-styled" |
175 | 179 | ) |
176 | 180 | restart_button_text = "Restart" |
177 | 181 | 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" |
179 | 186 | elif JUPYTER_TYPE == "notebook": |
180 | | - if get_jupyter_version() < "7.0.0": |
| 187 | + if get_jupyter_version() < Version("7.0.0"): |
181 | 188 | restart_button_class_name = "btn.btn-default.btn-sm.btn-danger" |
182 | 189 | restart_button_text = "Restart and Run All Cells" |
183 | 190 | else: |
|
0 commit comments