From 084dedcf0673cb31593488547c742d0f9d1e1f72 Mon Sep 17 00:00:00 2001 From: jamescalam <james.briggs@hotmail.com> Date: Sat, 30 Nov 2024 21:53:52 +0100 Subject: [PATCH] fix: add conditional for tests on lib installs --- tests/unit/encoders/test_clip.py | 11 +++++++---- tests/unit/encoders/test_vit.py | 9 ++++++--- tests/unit/llms/test_llm_llamacpp.py | 9 ++++++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/unit/encoders/test_clip.py b/tests/unit/encoders/test_clip.py index 1cfc7d43..29776151 100644 --- a/tests/unit/encoders/test_clip.py +++ b/tests/unit/encoders/test_clip.py @@ -1,11 +1,14 @@ import os import numpy as np import pytest -import torch -from PIL import Image -from unittest.mock import patch -from semantic_router.encoders import CLIPEncoder +_ = pytest.importorskip("torch") + +import torch # noqa: E402 +from PIL import Image # noqa: E402 +from unittest.mock import patch # noqa: E402 + +from semantic_router.encoders import CLIPEncoder # noqa: E402 test_model_name = "aurelio-ai/sr-test-clip" embed_dim = 64 diff --git a/tests/unit/encoders/test_vit.py b/tests/unit/encoders/test_vit.py index b598a818..622b2268 100644 --- a/tests/unit/encoders/test_vit.py +++ b/tests/unit/encoders/test_vit.py @@ -3,10 +3,13 @@ from unittest.mock import patch import os import numpy as np import pytest -import torch -from PIL import Image -from semantic_router.encoders import VitEncoder +_ = pytest.importorskip("torch") + +import torch # noqa: E402 +from PIL import Image # noqa: E402 + +from semantic_router.encoders import VitEncoder # noqa: E402 test_model_name = "aurelio-ai/sr-test-vit" embed_dim = 32 diff --git a/tests/unit/llms/test_llm_llamacpp.py b/tests/unit/llms/test_llm_llamacpp.py index 04a3ad3b..fc9813fa 100644 --- a/tests/unit/llms/test_llm_llamacpp.py +++ b/tests/unit/llms/test_llm_llamacpp.py @@ -1,10 +1,13 @@ from unittest.mock import patch import pytest -from llama_cpp import Llama -from semantic_router.llms.llamacpp import LlamaCppLLM -from semantic_router.schema import Message +_ = pytest.importorskip("llama_cpp") + +from llama_cpp import Llama # noqa: E402 + +from semantic_router.llms.llamacpp import LlamaCppLLM # noqa: E402 +from semantic_router.schema import Message # noqa: E402 @pytest.fixture -- GitLab