From fcf7892bfba842581c2b3a78d5ef0c28e974b34f Mon Sep 17 00:00:00 2001 From: Adam Fourney Date: Fri, 28 Feb 2025 16:05:13 -0800 Subject: [PATCH] Added unit tests for exceptions. --- .../markitdown/tests/test_files/random.bin | Bin 0 -> 1024 bytes packages/markitdown/tests/test_markitdown.py | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 packages/markitdown/tests/test_files/random.bin diff --git a/packages/markitdown/tests/test_files/random.bin b/packages/markitdown/tests/test_files/random.bin new file mode 100644 index 0000000000000000000000000000000000000000..e673935e3fe247eb568b532edda79cfa6d7cfd23 GIT binary patch literal 1024 zcmV+b1poVZqDUF|I@MPm@I2ba$0^0xsbp5=o$th>YH+h(LnR-*n?R?s5~^bsp5l$X z7!7%l(k=#N0Jw)Mg|7LqVl#M>YgXS>F_7qT+Ta$BOcL@<=D?8&Tyzbza0M!}1$;|W zE280En|hWp5mqOnj+8dseB-OIb=`)1NzxJ`L~!o}I7|^;+VBtH0Eryk+!aOZQtBbu z+d)OC*Sj!C8hXD<05H0AteX&eRn;m*M-^4a)GnCF&Oy_Xtl2HYT$Q4Cl5VSs&Ep6m zBH}pJ@5V)56TBb@{sw}78^asVLNQvD&&bza?s=)<`Aum^Nwp9aYfaNz@n1(ZtEb3T zn1_qrM48Xdk_Sp=F9@=dlt0+n(CwH7(8{%|5AU1C`0=y}c8wJ(VA?k|Fxn_-03S<% z$$npfgt!B__+tzm3hvzTwmBh^;BS#Xmy#m!uK{z{@z~TV;a{SJXCFB0G0>@izrxvx zLDXFsvXHb$p}6ONcFotcO_yhBU>g^5`itQOtrNzb33~pIm^}+Nu)R^|`okXdo2=yR zql__p$hJ^g1zP)QpcN+YcA2?NB5#bK&KyY*C&eZHEFLGUm&Zeypx-Y>RQV_7eJE?j{;Fovw#+-GF2oxJtV}EyPNi0fN&@c zy$8z^dxzdPjCj{s>*ZM6XASd9ew9-p$NFR)ABLs}(MEP|*<4wZP9tC-Dmu2BTG{ez zM9(1*o!NO|rTs52NkHUb8t^@X;Gb=?g5W+B@PHq)d9}wi50J=^)9pDfUine~u}mW@EAyzV60qXX@FPW%u??=}_W#YoyH!tqHeq^X1rTURVlV uZ!;^~(Qhc=?1Mm6xcY{dXP^%X3G4bAv$;g8TUZ literal 0 HcmV?d00001 diff --git a/packages/markitdown/tests/test_markitdown.py b/packages/markitdown/tests/test_markitdown.py index 55afcc3..0a3b56e 100644 --- a/packages/markitdown/tests/test_markitdown.py +++ b/packages/markitdown/tests/test_markitdown.py @@ -8,7 +8,7 @@ import requests from warnings import catch_warnings, resetwarnings -from markitdown import MarkItDown +from markitdown import MarkItDown, UnsupportedFormatException, FileConversionException skip_remote = ( True if os.environ.get("GITHUB_ACTIONS") else False @@ -272,6 +272,21 @@ def test_markitdown_local() -> None: assert "# Test" in result.text_content +def test_exceptions() -> None: + # Check that an exception is raised when trying to convert an unsupported format + markitdown = MarkItDown() + with pytest.raises(UnsupportedFormatException): + markitdown.convert(os.path.join(TEST_FILES_DIR, "random.bin")) + + # Check that an exception is raised when trying to convert a file that is corrupted + with pytest.raises(FileConversionException) as exc_info: + markitdown.convert( + os.path.join(TEST_FILES_DIR, "random.bin"), file_extension=".pptx" + ) + assert len(exc_info.value.attempts) == 1 + assert type(exc_info.value.attempts[0].converter).__name__ == "PptxConverter" + + @pytest.mark.skipif( skip_exiftool, reason="do not run if exiftool is not installed", @@ -329,6 +344,7 @@ if __name__ == "__main__": """Runs this file's tests from the command line.""" test_markitdown_remote() test_markitdown_local() + test_exceptions() test_markitdown_exiftool() # test_markitdown_llm() print("All tests passed!")