-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add multiprocessing tests for block overriding
- Loading branch information
1 parent
ead37b3
commit 52e4d3f
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
import multiprocessing as mp | ||
|
||
import pytest | ||
|
||
from marker.v2.providers.pdf import PdfProvider | ||
from marker.v2.schema import BlockTypes | ||
from marker.v2.schema.document import Document | ||
from marker.v2.schema.blocks import SectionHeader | ||
from marker.v2.schema.document import Document | ||
from marker.v2.schema.registry import register_block_class | ||
from marker.v2.schema.text import Line | ||
from tests.utils import setup_pdf_provider | ||
|
||
|
||
class NewSectionHeader(SectionHeader): | ||
pass | ||
|
||
|
||
class NewLine(Line): | ||
pass | ||
|
||
|
||
@pytest.mark.config({ | ||
"page_range": [0], | ||
"override_map": {BlockTypes.SectionHeader: NewSectionHeader} | ||
}) | ||
def test_overriding(pdf_document: Document): | ||
assert pdf_document.pages[0]\ | ||
.get_block(pdf_document.pages[0].structure[0]).__class__ == NewSectionHeader | ||
|
||
|
||
def get_lines(pdf: str, config=None): | ||
provider: PdfProvider = setup_pdf_provider(pdf, config) | ||
return provider.get_page_lines(0) | ||
|
||
|
||
def test_overriding_mp(): | ||
config = { | ||
"page_range": [0], | ||
"override_map": {BlockTypes.Line: NewLine} | ||
} | ||
|
||
for block_type, block_cls in config["override_map"].items(): | ||
register_block_class(block_type, block_cls) | ||
|
||
pdf_list = ["adversarial.pdf", "adversarial_rot.pdf"] | ||
|
||
with mp.Pool(processes=2) as pool: | ||
results = pool.starmap(get_lines, [(pdf, config) for pdf in pdf_list]) | ||
assert all([r[0].__class__ == NewLine for r in results]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters