Skip to content
Snippets Groups Projects
Commit 7a534ced authored by James Briggs's avatar James Briggs
Browse files

fix: tests and errors messages

parent 567e4c9f
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ class VitEncoder(BaseEncoder): ...@@ -27,7 +27,7 @@ class VitEncoder(BaseEncoder):
from transformers import ViTImageProcessor, ViTModel from transformers import ViTImageProcessor, ViTModel
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"Please install transformers to use HuggingFaceEncoder. " "Please install transformers to use VitEncoder. "
"You can install it with: " "You can install it with: "
"`pip install semantic-router[vision]`" "`pip install semantic-router[vision]`"
) )
...@@ -37,7 +37,7 @@ class VitEncoder(BaseEncoder): ...@@ -37,7 +37,7 @@ class VitEncoder(BaseEncoder):
import torchvision.transforms as T import torchvision.transforms as T
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"Please install Pytorch to use HuggingFaceEncoder. " "Please install Pytorch to use VitEncoder. "
"You can install it with: " "You can install it with: "
"`pip install semantic-router[vision]`" "`pip install semantic-router[vision]`"
) )
...@@ -46,7 +46,7 @@ class VitEncoder(BaseEncoder): ...@@ -46,7 +46,7 @@ class VitEncoder(BaseEncoder):
from PIL import Image from PIL import Image
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"Please install PIL to use HuggingFaceEncoder. " "Please install PIL to use VitEncoder. "
"You can install it with: " "You can install it with: "
"`pip install semantic-router[vision]`" "`pip install semantic-router[vision]`"
) )
......
from unittest.mock import patch
import os import os
import numpy as np import numpy as np
import pytest import pytest
...@@ -33,15 +35,14 @@ def misshaped_pil_image(): ...@@ -33,15 +35,14 @@ def misshaped_pil_image():
class TestVitEncoder: class TestVitEncoder:
def test_vit_encoder__import_errors_transformers(self, mocker): def test_vit_encoder__import_errors_transformers(self):
mocker.patch.dict("sys.modules", {"transformers": None}) with patch.dict("sys.modules", {"transformers": None}):
with pytest.raises(ImportError): with pytest.raises(ImportError) as error:
VitEncoder() VitEncoder()
def test_vit_encoder__import_errors_torch(self, mocker): assert "Please install transformers to use VitEncoder" in str(
mocker.patch.dict("sys.modules", {"torch": None}) error.value
with pytest.raises(ImportError): )
VitEncoder()
@pytest.mark.skipif( @pytest.mark.skipif(
os.environ.get("RUN_HF_TESTS") is None, reason="Set RUN_HF_TESTS=1 to run" os.environ.get("RUN_HF_TESTS") is None, reason="Set RUN_HF_TESTS=1 to run"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment