Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/python/feast/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def validate_image_format(image_bytes: bytes) -> bool:
Returns:
True if valid image, False otherwise
"""
_check_image_dependencies()
try:
with Image.open(io.BytesIO(image_bytes)) as img:
img.verify()
Expand All @@ -259,6 +260,7 @@ def get_image_metadata(image_bytes: bytes) -> dict:
Raises:
ValueError: If image cannot be processed
"""
_check_image_dependencies()
try:
with Image.open(io.BytesIO(image_bytes)) as img:
return {
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/unit/test_image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io

import pytest
from PIL import Image

import feast.image_utils as image_utils
from feast.image_utils import (
Expand All @@ -28,6 +27,7 @@
torch = pytest.importorskip("torch")
pytest.importorskip("timm")
pytest.importorskip("sklearn")
Image = pytest.importorskip("PIL.Image")


@pytest.fixture(autouse=True)
Expand Down
37 changes: 37 additions & 0 deletions sdk/python/tests/unit/test_image_utils_optional_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2024 The Feast Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest


def test_validate_image_format_raises_when_deps_missing(monkeypatch):
from feast import image_utils

monkeypatch.setattr(image_utils, "_image_dependencies_available", False)

with pytest.raises(
ImportError, match="Image processing dependencies are not installed"
):
image_utils.validate_image_format(b"anything")


def test_get_image_metadata_raises_when_deps_missing(monkeypatch):
from feast import image_utils

monkeypatch.setattr(image_utils, "_image_dependencies_available", False)

with pytest.raises(
ImportError, match="Image processing dependencies are not installed"
):
image_utils.get_image_metadata(b"anything")
3 changes: 2 additions & 1 deletion sdk/python/tests/unit/test_rag_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy as np
import pytest
import torch
from transformers import (
BartConfig,
BertConfig,
Expand All @@ -17,6 +16,8 @@
from feast.repo_config import RepoConfig
from tests.utils.rag_test_utils import MockVectorStore

torch = pytest.importorskip("torch")


class MockTokenizer(PreTrainedTokenizer):
"""Mock tokenizer for testing."""
Expand Down