Skip to content

Commit 465e700

Browse files
fix: testing] Cover ImportError from builtins.__import__ in _check_llama_cpp (#240)
* 🧪 [Testing] Cover ImportError from builtins.__import__ in _check_llama_cpp Co-authored-by: n24q02m <135627235+n24q02m@users.noreply.github.com> * 🧪 [Testing] Fix ruff formatting issues to pass CI Co-authored-by: n24q02m <135627235+n24q02m@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 683af0d commit 465e700

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

tests/test_gguf_embedding.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ def test_check_llama_cpp_missing():
3535
_check_llama_cpp()
3636

3737

38+
def test_check_llama_cpp_import_error_with_mock():
39+
"""Test that _check_llama_cpp raises ImportError from builtins.__import__."""
40+
original_import = __import__
41+
42+
def mock_import(name, *args, **kwargs):
43+
if name == "llama_cpp":
44+
raise ImportError("Mocked import error for llama_cpp")
45+
return original_import(name, *args, **kwargs)
46+
47+
with (
48+
patch("builtins.__import__", side_effect=mock_import),
49+
pytest.raises(ImportError, match="llama-cpp-python is required"),
50+
):
51+
_check_llama_cpp()
52+
53+
3854
def test_check_llama_cpp_present():
3955
"""Test that _check_llama_cpp does not raise when llama_cpp is present."""
4056
mock_module = MagicMock()

0 commit comments

Comments
 (0)