From 7416ccdf74a2ce1aa4ef69f4a9e0518639e5bb4c Mon Sep 17 00:00:00 2001 From: Alpamys Date: Wed, 1 Apr 2026 13:55:12 +0500 Subject: [PATCH] test: add edge-case tests for Ollama deploy (TDD review findings) Add 7 tests for previously uncovered branches: - deploy_to_ollama OSError path - remove_model timeout and OSError paths - list_soup_models timeout and nonzero returncode - validate_model_name 128-char boundary - detect_ollama version-in-stderr fallback --- tests/test_deploy_ollama.py | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/test_deploy_ollama.py b/tests/test_deploy_ollama.py index 580886e..93fd92c 100644 --- a/tests/test_deploy_ollama.py +++ b/tests/test_deploy_ollama.py @@ -85,6 +85,12 @@ def test_validate_model_name_starts_with_hyphen(): assert "alphanumeric" in err.lower() +def test_validate_model_name_exactly_128_chars(): + valid, err = validate_model_name("a" * 128) + assert valid is True + assert err == "" + + # ─── validate_gguf_path ─── @@ -171,6 +177,15 @@ def test_detect_ollama_no_version_match(mock_run): assert version == "ollama unknown" +@patch(f"{_OLLAMA}.subprocess.run") +def test_detect_ollama_version_in_stderr(mock_run): + mock_run.return_value = MagicMock( + returncode=0, stdout="", stderr="ollama version is 0.7.0" + ) + version = detect_ollama() + assert version == "0.7.0" + + # ─── infer_chat_template ─── @@ -315,6 +330,14 @@ def test_deploy_to_ollama_timeout(mock_run): assert "timed out" in msg.lower() +@patch(f"{_OLLAMA}.subprocess.run") +def test_deploy_to_ollama_oserror(mock_run): + mock_run.side_effect = OSError("Permission denied") + success, msg = deploy_to_ollama("test-model", "FROM m.gguf\n") + assert success is False + assert "failed to run ollama" in msg.lower() + + # ─── list_soup_models ─── @@ -350,6 +373,18 @@ def test_list_soup_models_ollama_not_found(mock_run): assert list_soup_models() == [] +@patch(f"{_OLLAMA}.subprocess.run") +def test_list_soup_models_timeout(mock_run): + mock_run.side_effect = subprocess.TimeoutExpired(cmd="ollama", timeout=10) + assert list_soup_models() == [] + + +@patch(f"{_OLLAMA}.subprocess.run") +def test_list_soup_models_nonzero(mock_run): + mock_run.return_value = MagicMock(returncode=1, stdout="") + assert list_soup_models() == [] + + # ─── remove_model ─── @@ -376,6 +411,22 @@ def test_remove_model_not_installed(mock_run): assert "not found" in msg.lower() +@patch(f"{_OLLAMA}.subprocess.run") +def test_remove_model_timeout(mock_run): + mock_run.side_effect = subprocess.TimeoutExpired(cmd="ollama", timeout=30) + success, msg = remove_model("soup-test") + assert success is False + assert "timed out" in msg.lower() + + +@patch(f"{_OLLAMA}.subprocess.run") +def test_remove_model_oserror(mock_run): + mock_run.side_effect = OSError("Permission denied") + success, msg = remove_model("soup-test") + assert success is False + assert "failed to run ollama" in msg.lower() + + # ─── Constants ───