Skip to content

Commit 196ee55

Browse files
committed
fix(cli): allow Content Understanding conversion from stdin
1 parent fd239d5 commit 196ee55

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

packages/markitdown/src/markitdown/__main__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ def main():
216216
_exit_with_error(
217217
"Content Understanding Endpoint (--cu-endpoint) is required when using --use-cu."
218218
)
219-
elif args.filename is None:
220-
_exit_with_error("Filename is required when using Content Understanding.")
221219

222220
cu_kwargs: Dict[str, Any] = {
223221
"cu_endpoint": args.cu_endpoint,

packages/markitdown/tests/test_cu_converter.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,41 @@ def test_use_cu_wires_kwargs_to_markitdown(self, capsys):
902902
)
903903
assert capsys.readouterr().out == "converted\n"
904904

905+
def test_use_cu_reads_from_stdin(self, capsys):
906+
"""--use-cu should preserve the CLI's filename-optional stdin mode."""
907+
import markitdown.__main__ as markitdown_cli
908+
909+
input_buffer = io.BytesIO(b"fake pdf")
910+
stdin = MagicMock(buffer=input_buffer)
911+
markitdown_instance = MagicMock()
912+
markitdown_instance.convert_stream.return_value.markdown = "converted"
913+
markitdown_cls = MagicMock(return_value=markitdown_instance)
914+
915+
with patch.object(
916+
sys,
917+
"argv",
918+
[
919+
"markitdown",
920+
"--use-cu",
921+
"--cu-endpoint",
922+
"https://fake-cu",
923+
],
924+
), patch.object(sys, "stdin", stdin), patch.object(
925+
markitdown_cli, "MarkItDown", markitdown_cls
926+
):
927+
markitdown_cli.main()
928+
929+
markitdown_cls.assert_called_once_with(
930+
enable_plugins=False,
931+
cu_endpoint="https://fake-cu",
932+
)
933+
markitdown_instance.convert_stream.assert_called_once_with(
934+
input_buffer,
935+
stream_info=None,
936+
keep_data_uris=False,
937+
)
938+
assert capsys.readouterr().out == "converted\n"
939+
905940

906941
# ---------------------------------------------------------------------------
907942
# MissingDependencyException test

0 commit comments

Comments
 (0)