from __future__ import annotations from pathlib import Path from ocrtech.external_outputs import bundle_page_paths, document_from_markdown def test_document_from_markdown_parses_text_and_tables(tmp_path: Path) -> None: document = document_from_markdown( tmp_path / "sample.md", "# नेपाल सरकार\n\n| नाम | उमेर |\n| --- | --- |\n| राम | ३२ |\n| Sita | 29 |\n", metadata={"engine": "fixture"}, ) assert document.text.startswith("नेपाल सरकार") assert len(document.tables) == 1 grid = {(cell.row, cell.col): cell.text for cell in document.tables[0].cells} assert grid[(0, 0)] == "नाम" assert grid[(1, 0)] == "राम" assert document.pages[0].blocks[0].block_type == "title" assert any(block.block_type == "table" for block in document.pages[0].blocks) def test_document_from_markdown_splits_pagebreaks(tmp_path: Path) -> None: document = document_from_markdown( tmp_path / "sample.md", "Page one\n\n\n\nPage two\n", ) assert len(document.pages) == 2 assert document.pages[0].text_lines[0].text == "Page one" assert document.pages[1].text_lines[0].text == "Page two" def test_bundle_page_paths_accepts_single_file_and_sorted_directory(tmp_path: Path) -> None: first = tmp_path / "b.png" second = tmp_path / "a.png" first.write_bytes(b"b") second.write_bytes(b"a") assert bundle_page_paths(first) == [first] assert bundle_page_paths(tmp_path) == [second, first]