|
14 | 14 |
|
15 | 15 | """Unit tests for skill utilities.""" |
16 | 16 |
|
| 17 | +import builtins |
17 | 18 | import io |
| 19 | +import sys |
18 | 20 | from unittest import mock |
19 | 21 | import zipfile |
20 | 22 |
|
@@ -363,3 +365,33 @@ def test__load_skill_from_zip_bytes(): |
363 | 365 | assert skill.instructions == "Body instructions" |
364 | 366 | assert skill.resources.get_reference("ref1.md") == "ref1 content" |
365 | 367 | assert skill.resources.get_script("script1.sh").src == "echo hello" |
| 368 | + |
| 369 | + |
| 370 | +def test__list_skills_in_gcs_dir_import_error(): |
| 371 | + """Tests list_skills_in_gcs_dir raises ImportError when storage missing.""" |
| 372 | + real_import = builtins.__import__ |
| 373 | + |
| 374 | + def mock_import(name, globals=None, locals=None, fromlist=(), level=0): |
| 375 | + if name == "google.cloud" and "storage" in (fromlist or ()): |
| 376 | + raise ImportError("No module named 'google.cloud.storage'") |
| 377 | + return real_import(name, globals, locals, fromlist, level) |
| 378 | + |
| 379 | + with mock.patch("builtins.__import__", mock_import): |
| 380 | + with pytest.raises(ImportError, match="google-cloud-storage is required"): |
| 381 | + _list_skills_in_gcs_dir("my-bucket", "skills/") |
| 382 | + |
| 383 | + |
| 384 | +def test__load_skill_from_gcs_dir_import_error(): |
| 385 | + """Tests load_skill_from_gcs_dir raises ImportError when storage missing.""" |
| 386 | + real_import = builtins.__import__ |
| 387 | + |
| 388 | + def mock_import(name, globals=None, locals=None, fromlist=(), level=0): |
| 389 | + if name == "google.cloud" and "storage" in (fromlist or ()): |
| 390 | + raise ImportError("No module named 'google.cloud.storage'") |
| 391 | + return real_import(name, globals, locals, fromlist, level) |
| 392 | + |
| 393 | + with mock.patch("builtins.__import__", mock_import): |
| 394 | + with pytest.raises(ImportError, match="google-cloud-storage is required"): |
| 395 | + _load_skill_from_gcs_dir("my-bucket", "skills/my-skill/") |
| 396 | + |
| 397 | + |
0 commit comments