|
4 | 4 |
|
5 | 5 | import importlib
|
6 | 6 |
|
| 7 | +import pytest |
| 8 | + |
7 | 9 | import clustrix.notebook_magic
|
8 | 10 | from clustrix.config import ClusterConfig
|
9 | 11 |
|
| 12 | +# Check if widget dependencies are available |
| 13 | +try: |
| 14 | + import IPython |
| 15 | + import ipywidgets |
| 16 | + WIDGET_DEPS_AVAILABLE = True |
| 17 | +except ImportError: |
| 18 | + WIDGET_DEPS_AVAILABLE = False |
| 19 | + |
10 | 20 | # Reload to ensure fresh state
|
11 | 21 | importlib.reload(clustrix.notebook_magic)
|
12 | 22 |
|
13 | 23 | # Import after reload to get the refreshed module
|
14 | 24 | DEFAULT_CONFIGS = clustrix.notebook_magic.DEFAULT_CONFIGS
|
15 |
| -ClusterConfigWidget = clustrix.notebook_magic.ClusterConfigWidget |
| 25 | +if WIDGET_DEPS_AVAILABLE: |
| 26 | + ClusterConfigWidget = clustrix.notebook_magic.ClusterConfigWidget |
16 | 27 |
|
17 | 28 |
|
18 | 29 | class TestWidgetConfigurationFixes:
|
@@ -57,6 +68,7 @@ def test_cloud_provider_field_mapping(self):
|
57 | 68 | assert "hf_hardware" in hf_config
|
58 | 69 | assert "hf_sdk" in hf_config
|
59 | 70 |
|
| 71 | + @pytest.mark.skipif(not WIDGET_DEPS_AVAILABLE, reason="Widget dependencies not available") |
60 | 72 | def test_widget_safe_value_setting(self):
|
61 | 73 | """Test that widget safely handles values not in dropdown options."""
|
62 | 74 | widget = ClusterConfigWidget(auto_display=False)
|
@@ -87,6 +99,7 @@ def test_widget_safe_value_setting(self):
|
87 | 99 | assert widget.azure_region.value in widget.azure_region.options
|
88 | 100 | assert widget.azure_instance_type.value in widget.azure_instance_type.options
|
89 | 101 |
|
| 102 | + @pytest.mark.skipif(not WIDGET_DEPS_AVAILABLE, reason="Widget dependencies not available") |
90 | 103 | def test_widget_save_load_cycle(self):
|
91 | 104 | """Test that widget can save and load configurations correctly."""
|
92 | 105 | widget = ClusterConfigWidget(auto_display=False)
|
@@ -178,6 +191,7 @@ def test_cloud_provider_fields_in_config(self):
|
178 | 191 | assert hf_config.hf_username == "test-user"
|
179 | 192 | assert hf_config.hf_sdk == "gradio"
|
180 | 193 |
|
| 194 | + @pytest.mark.skipif(not WIDGET_DEPS_AVAILABLE, reason="Widget dependencies not available") |
181 | 195 | def test_widget_dropdown_population(self):
|
182 | 196 | """Test that widget properly populates dropdown options."""
|
183 | 197 | widget = ClusterConfigWidget(auto_display=False)
|
@@ -214,6 +228,7 @@ def test_no_name_description_in_default_configs(self):
|
214 | 228 | "description" not in test_config
|
215 | 229 | ), f"Config '{config_name}' should not have 'description' field initially"
|
216 | 230 |
|
| 231 | + @pytest.mark.skipif(not WIDGET_DEPS_AVAILABLE, reason="Widget dependencies not available") |
217 | 232 | def test_widget_cluster_type_change_updates_options(self):
|
218 | 233 | """Test that changing cluster type updates dropdown options."""
|
219 | 234 | widget = ClusterConfigWidget(auto_display=False)
|
|
0 commit comments