| """Provider tests for QR code + barcode providers.""" |
|
|
| from __future__ import annotations |
|
|
| import cv2 |
| import numpy as np |
| import pytest |
|
|
| from config.settings import Settings |
| from pipeline.feature_extraction import PipelineOutput |
| from providers.object_intelligence.qr_code import QRCodeProvider |
|
|
|
|
| @pytest.fixture |
| def qr_provider(): |
| return QRCodeProvider(settings=Settings(environment="test", db_path=":memory:")) |
|
|
|
|
| @pytest.fixture |
| def pipeline_output(sample_image_bytes): |
| img = cv2.imdecode(np.frombuffer(sample_image_bytes, np.uint8), cv2.IMREAD_COLOR) |
| return PipelineOutput( |
| image=img, image_hash="h", width=img.shape[1], height=img.shape[0], source="bytes", |
| original_bytes=sample_image_bytes, original_format=".jpg", |
| ) |
|
|
|
|
| class TestQRCodeProvider: |
| def test_name(self, qr_provider): |
| assert qr_provider.name == "qr_code" |
|
|
| def test_capability(self, qr_provider): |
| from models.providers import ProviderCapability |
| assert qr_provider.capability == ProviderCapability.OBJECT_DETECTION |
|
|
| def test_is_available(self, qr_provider): |
| |
| assert qr_provider.is_available() is True |
|
|
| def test_execute_no_qr(self, qr_provider, pipeline_output): |
| """An image without a QR code should return empty results.""" |
| result = qr_provider.execute(pipeline_output) |
| assert result.success is True |
| assert len(result.normalized["objects"]) == 0 |
|
|
| def test_execute_synthetic_qr(self, qr_provider): |
| """Verify the provider handles an arbitrary image without crashing. |
| |
| We don't generate a real QR code (cv2.QRCodeGenerator isn't available |
| in all OpenCV builds); we just verify the provider runs. |
| """ |
| img = np.zeros((200, 200, 3), dtype=np.uint8) |
| po = PipelineOutput( |
| image=img, image_hash="qr", width=200, height=200, source="bytes", |
| ) |
| result = qr_provider.execute(po) |
| assert result.success is True |
| assert "objects" in result.normalized |
|
|