File size: 1,577 Bytes
1ef1de7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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<!-- pagebreak -->\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]