Skip to content

Commit

Permalink
fix: handle missing LibreOffice in DocConverter
Browse files Browse the repository at this point in the history
Update DocConverter to return an error message when LibreOffice 
is not found. Add a new test to verify the error handling 
behavior when the `shutil.which` function is mocked to return 
None, ensuring that users receive clear instructions to 
install LibreOffice.
refactor(tests): update test_markitdown_soffice_mocked
  • Loading branch information
l-lumin authored and gitbutler-client committed Dec 20, 2024
1 parent d07020a commit 0e4e6c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/markitdown/_markitdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,10 @@ def convert(self, local_path, **kwargs) -> Union[None, DocumentConverterResult]:
return None

if not (soffice := shutil.which("soffice")):
return None
return DocumentConverterResult(
title=None,
text_content="[ERROR] LibreOffice not found. Please install LibreOffice and try again.",
)

local_path = Path(local_path)
outdir = local_path.parent
Expand Down
8 changes: 8 additions & 0 deletions tests/test_markitdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ def test_markitdown_soffice() -> None:
text_content = result.text_content.replace("\\", "")
assert test_string in text_content

def test_markitdown_soffice_mocked(mocker) -> None:
mocker.patch("shutil.which", return_value=None)
markitdown = MarkItDown()

# Test DOC processing
result = markitdown.convert(os.path.join(TEST_FILES_DIR, "test.doc"))
text_content = result.text_content.replace("\\", "")
assert text_content == "[ERROR] LibreOffice not found. Please install LibreOffice and try again."


def test_markitdown_deprecation() -> None:
Expand Down

0 comments on commit 0e4e6c0

Please sign in to comment.