CoolFace
Apppublic

imran-decoder/filecrackhead1

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
test_conversion_engine.py60 linesDownload Raw Back to tests
1"""2Tests for the conversion engine dispatch table.3"""4 5import pytest6from app.services.conversion_engine import (7    CONVERSION_MAP,8    ConversionError,9    get_handler,10)11from app.validators import SUPPORTED_CONVERSIONS12 13 14class TestDispatchTable:15    def test_all_supported_pairs_have_handlers(self):16        """Every pair in SUPPORTED_CONVERSIONS must have a handler in CONVERSION_MAP."""17        from app.validators import normalize_extension18        missing = []19        for src, tgt in SUPPORTED_CONVERSIONS:20            key = (normalize_extension(src), normalize_extension(tgt))21            if key not in CONVERSION_MAP:22                missing.append(key)23        assert not missing, f"Missing handlers for: {missing}"24 25    def test_get_handler_returns_callable(self):26        handler = get_handler("pdf", "docx")27        assert callable(handler)28 29    def test_get_handler_pdf_to_txt(self):30        handler = get_handler("pdf", "txt")31        assert callable(handler)32 33    def test_get_handler_docx_to_pdf(self):34        handler = get_handler("docx", "pdf")35        assert callable(handler)36 37    def test_get_handler_md_to_pdf(self):38        handler = get_handler("md", "pdf")39        assert callable(handler)40 41    def test_get_handler_epub_to_docx(self):42        handler = get_handler("epub", "docx")43        assert callable(handler)44 45    def test_unsupported_pair_raises_conversion_error(self):46        with pytest.raises(ConversionError) as exc_info:47            get_handler("jpg", "xlsx")48        assert exc_info.value.status_code == 42249 50    def test_unknown_source_raises(self):51        with pytest.raises(ConversionError):52            get_handler("xyz", "pdf")53 54    def test_handler_names_are_descriptive(self):55        """Handlers should have meaningful names (not lambda)."""56        for (src, tgt), handler in CONVERSION_MAP.items():57            assert handler.__name__ != "<lambda>", (58                f"Handler for ({src}, {tgt}) is an anonymous lambda — use named function"59            )60