Update addon tests, bootstrap runtime, download progress, and worker functionality

- Modified status messages and stage labels in `test_addon.py` for clarity and consistency.
- Added tests to ensure proper host termination and command execution in `test_addon.py`.
- Enhanced `test_bootstrap_runtime.py` with additional tests for installation behavior, including handling of CUDA and MPS devices, and improved error handling for disk space and network checks.
- Updated download progress reporting in `test_download_progress.py` to include download speed and improved message formatting.
- Added new tests in `test_worker.py` for device selection, NPZ file validation, and model downloading behavior with Hugging Face endpoints.
- Bumped version in `uv.lock` to 0.9.30.
This commit is contained in:
2026-08-07 13:11:04 +08:00
parent e0cb995473
commit d08d0e9c1a
17 changed files with 1799 additions and 262 deletions

View File

@@ -517,27 +517,27 @@ class AddonTest(unittest.TestCase):
operator._format_status(
{
"progress": 0.5,
"message": "Downloaded 3 packages",
"message": "2 downloaded",
"stage": 3,
"stages": 12,
"stage_label": "Install PyTorch",
"stages": 8,
"stage_label": "pytorch",
},
"fallback",
),
"Step 3/12 Install PyTorch: Downloaded 3 packages",
"3/8 pytorch: 2 downloaded",
)
self.assertEqual(
operator._format_status(
{
"progress": 0.0,
"message": "",
"stage": 10,
"stages": 12,
"stage_label": "Download DA3 Small",
"stage": 6,
"stages": 8,
"stage_label": "da3 small",
},
"fallback",
),
"Step 10/12 Download DA3 Small",
"6/8 da3 small",
)
self.assertEqual(
operator._format_status(
@@ -865,6 +865,31 @@ class AddonTest(unittest.TestCase):
self.assertIn("ProxyHandler({})", inspect.getsource(runtime))
self.assertIn('return storage_root() / "host.json"', inspect.getsource(runtime.host_discovery_path))
def test_closing_blender_terminates_host_it_started(self):
runtime = importlib.import_module("snapform.runtime")
previous_connection = runtime._host_connection
previous_registered = runtime._registered_instance_id
runtime._host_connection = SimpleNamespace(port=12345)
runtime._registered_instance_id = "instance"
try:
with patch.object(
runtime,
"_host_http_request",
) as request, patch.object(
runtime,
"_close_launched_host",
) as close_host:
runtime.detach_host_client()
request.assert_called_once()
self.assertEqual(request.call_args.args[1], "DELETE")
close_host.assert_called_once_with(terminate=True)
finally:
runtime._host_connection = previous_connection
runtime._registered_instance_id = previous_registered
self.assertIsNone(runtime._host_connection)
self.assertIsNone(runtime._registered_instance_id)
def test_host_jobs_complete_from_status_state(self):
source = inspect.getsource(self.addon.RunJob.modal)
@@ -1357,6 +1382,37 @@ class AddonTest(unittest.TestCase):
if value == "--allow-pattern"
]
self.assertEqual(patterns, ["config.json", "model.safetensors"])
label_index = command.index("--label")
self.assertEqual(command[label_index + 1], "BEN2 Base")
def test_install_runtime_command_has_no_model_label_reference(self):
runtime = importlib.import_module("snapform.runtime")
with patch.object(
runtime,
"uv_executable",
return_value="C:/uv/uv.exe",
), patch.object(
runtime,
"preferences",
return_value=SimpleNamespace(torch_backend="CU128"),
), patch.object(
runtime,
"runtime_directory",
return_value=Path("runtime"),
), patch.object(
runtime,
"models_directory",
return_value=Path("models"),
):
command = runtime.install_runtime_command(Path("status.json"))
self.assertNotIn("--label", command)
self.assertEqual(command[0], sys.executable)
self.assertIn("--uv", command)
self.assertIn("C:/uv/uv.exe", command)
self.assertTrue(
any("bootstrap_runtime.py" in str(value) for value in command)
)
def test_preferences_install_button_is_disabled_while_busy(self):
draw_source = inspect.getsource(self.addon.SnapFormPreferences.draw)
@@ -1526,7 +1582,7 @@ class AddonTest(unittest.TestCase):
],
)
def test_force_flag_triggers_window_draw_and_swap(self):
def test_force_flag_refreshes_status_text(self):
redrawn = []
context = SimpleNamespace(
window_manager=SimpleNamespace(
@@ -1553,29 +1609,17 @@ class AddonTest(unittest.TestCase):
),
)
with patch.object(
self.addon.status_bar.bpy,
"ops",
SimpleNamespace(
wm=SimpleNamespace(
redraw_timer=lambda **options: redrawn.append(
("swap", options)
),
),
),
):
self.addon.status_bar.redraw_ui(context, force=True)
self.addon.status_bar.redraw_ui(context, force=True)
self.assertEqual(
redrawn,
[
"status",
("swap", {"type": "DRAW_WIN_SWAP", "iterations": 1}),
"status-text",
],
)
def test_force_flag_ignores_missing_redraw_helpers(self):
def test_force_flag_ignores_missing_workspace(self):
redrawn = []
context = SimpleNamespace(
window_manager=SimpleNamespace(