Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests #495

Merged
merged 5 commits into from
Jan 13, 2025
Merged
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: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
name: ruff-import-sort
stages: [pre-commit]
args: ["--select", "I", "--fix"]
# format code using rff
# format code using ruff
- id: ruff
name: ruff-format
stages: [pre-commit]
2 changes: 1 addition & 1 deletion feluda/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ServerConfig:
class OperatorParameters:
name: str
type: str
parameters: object
parameters: Optional[object] = None


@dataclass
Expand Down
2 changes: 0 additions & 2 deletions operators/image_vec_rep_resnet/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ dependencies = [
"torchvision>=0.20.1",
"numpy>=2.2.1",
"pillow>=11.1.0",
"memray>=1.15.0",
"pyinstrument>=5.0.0",
]

[build-system]
Expand Down
6 changes: 5 additions & 1 deletion scripts/validate_toml_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def validate_pyproject_toml(file_path: Path) -> tuple[bool, list[str]]:

# Check semantic release configuration
try:
tag_format = content["tool"]["semantic_release"]["branches"]["main"]["tag_format"]
tag_format = content["tool"]["semantic_release"]["branches"]["main"][
"tag_format"
]
if tag_format != "{name}-{version}":
errors.append(
f"{file_path}: Invalid tag_format. Expected '{{name}}-{{version}}', got '{tag_format}'"
Expand All @@ -40,6 +42,7 @@ def validate_pyproject_toml(file_path: Path) -> tuple[bool, list[str]]:

return len(errors) == 0, errors


def main():
# Find all pyproject.toml files
root_dir = Path(".")
Expand Down Expand Up @@ -70,5 +73,6 @@ def main():
print(f" - {error}")
sys.exit(1)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch

import numpy as np
import yaml
from requests.exceptions import ConnectTimeout

from feluda import Feluda
from feluda.models.media_factory import ImageFactory


class TestFeludaImageVectorIntegration(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Create a temporary test configuration file that will be used for all tests."""
cls.config = {
"operators": {
"label": "Operators",
"parameters": [
{
"name": "image vectors",
"type": "image_vec_rep_resnet",
"parameters": {"index_name": "image"},
}
],
}
}

# Create temporary config file
cls.temp_file = tempfile.NamedTemporaryFile(
mode="w", suffix=".yml", delete=False
)
yaml.dump(cls.config, cls.temp_file)
cls.temp_file.close()

# Initialize Feluda
cls.feluda = Feluda(cls.temp_file.name)
cls.feluda.setup()

def test_image_vector_generation(self):
"""Test that image vector generation works end-to-end."""

test_image_url = "https://tattle-media.s3.amazonaws.com/test-data/tattle-search/text-in-image-test-hindi.png"
image_obj = ImageFactory.make_from_url(test_image_url)
operator = self.feluda.operators.get()["image_vec_rep_resnet"]
image_vec = operator.run(image_obj)

# Basic validation
self.assertTrue(
isinstance(image_vec, (list, np.ndarray)),
"Vector should be a list or numpy array",
)
self.assertTrue(len(image_vec) > 0, "Vector should not be empty")

expected_dim = 512
self.assertEqual(
len(image_vec), expected_dim, f"Vector should have dimension {expected_dim}"
)

if isinstance(image_vec, np.ndarray):
self.assertFalse(np.all(image_vec == 0), "Vector should not be all zeros")

def test_invalid_image_url(self):
"""Test handling of invalid image URL."""
invalid_url = "https://nonexistent-url/image.jpg"

with patch("requests.get") as mock_get:
mock_get.side_effect = ConnectTimeout
result = ImageFactory.make_from_url(invalid_url)
self.assertIsNone(result)

def test_operator_configuration(self):
"""Test that operator is properly configured."""
operator = self.feluda.operators.get()["image_vec_rep_resnet"]

self.assertIsNotNone(operator, "Operator should be properly initialized")
self.assertTrue(hasattr(operator, "run"), "Operator should have 'run' method")

@classmethod
def tearDownClass(cls):
"""Clean up temporary files after all tests are done."""
Path(cls.temp_file.name).unlink()
Loading