Skip to content

Commit

Permalink
Add json renderer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VikParuchuri committed Nov 19, 2024
1 parent 43cbd2c commit 4591f31
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion marker/v2/renderers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def compute_toc(self, document, block_output: BlockOutput):
toc = []
if hasattr(block_output, "id") and block_output.id.block_type == BlockTypes.SectionHeader:
toc.append({
"title": self.extract_block_html(document, block_output),
"title": self.extract_block_html(document, block_output)[0],
"level": document.get_block(block_output.id).heading_level,
"page": block_output.id.page_id
})
Expand Down
13 changes: 13 additions & 0 deletions tests/renderers/test_json_renderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from marker.v2.renderers.json import JSONRenderer


@pytest.mark.config({"page_range": [0]})
def test_markdown_renderer_pagination(pdf_document):
renderer = JSONRenderer()
pages = renderer(pdf_document).children

assert len(pages) == 1
assert pages[0].block_type == "Page"
assert pages[0].children[0].block_type == "SectionHeader"
11 changes: 10 additions & 1 deletion tests/renderers/test_markdown_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ def test_markdown_renderer_pagination(pdf_document):
md = renderer(pdf_document).markdown

assert "{0}-" in md
assert "{1}-" in md
assert "{1}-" in md


@pytest.mark.config({"page_range": [0, 1]})
def test_markdown_renderer_metadata(pdf_document):
renderer = MarkdownRenderer({"paginate_output": True})
metadata = renderer(pdf_document).metadata
assert "table_of_contents" in metadata

assert "Subspace Adversarial Training" in metadata["table_of_contents"][0]["title"]

0 comments on commit 4591f31

Please sign in to comment.