Skip to content

Commit 7ed0727

Browse files
committed
Merge branch 'feat/document-engine' into feat/degradations
2 parents f1ac474 + be840a6 commit 7ed0727

6 files changed

Lines changed: 28 additions & 16 deletions

File tree

src/ocrsmith/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .augmentation import NoiseAugmentation
22
from .AugmentationManager import AugmentationManager
33
from .BackgroundManager import BackgroundManager
4+
from .engine import OCRSmithEngine
45
from .FontManager import FontManager
5-
from .OCRSmithEngine import OCRSmithEngine
66
from .TextPlacementManager import TextPlacementManager
77
from .TextRenderingManager import TextRenderingManager

src/ocrsmith/core/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22

33
from ocrsmith.config.loader import load_config
4-
from ocrsmith.core.OCRSmithEngine import OCRSmithEngine
4+
from ocrsmith.core.engine import OCRSmithEngine
55

66

77
def parse_overrides(pairs):

tests/test_documents_layout.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,27 @@ def test_no_text_is_lost_across_page_breaks(self, renderer, typography, rng, lat
253253
# Bullet markers and page furniture can add tokens; nothing may go missing.
254254
assert rendered_words >= expected
255255

256-
def test_two_columns_hold_more_per_page_than_one(self, renderer, typography, rng, latin_source):
256+
def test_columns_are_narrower_and_both_get_used(self, renderer, typography, rng, latin_source):
257+
# Not "two columns need fewer pages": narrower columns wrap more, and with orphan
258+
# control a two-column layout can legitimately need one page more. What the
259+
# feature actually guarantees is that blocks are confined to a column and that a
260+
# page with enough content uses both of them.
257261
content = ArticleTemplate(min_sections=5, max_sections=5).build(latin_source, rng)
258-
one = PageSpec.from_paper("a5", dpi=100, columns=1)
259-
two = PageSpec.from_paper("a5", dpi=100, columns=2)
262+
spec = PageSpec.from_paper("a5", dpi=100, columns=2)
260263

261-
single = renderer.render(content, one, typography, rng=random.Random(1), max_pages=40)
262-
double = renderer.render(content, two, typography, rng=random.Random(1), max_pages=40)
264+
pages = renderer.render(content, spec, typography, rng=random.Random(1), max_pages=40)
263265

264-
assert len(double) <= len(single)
266+
column_width = spec.column_width
267+
midpoint = spec.content_box.x0 + spec.content_box.width / 2
268+
used_left = used_right = False
269+
for page in pages:
270+
for region in page.page.regions:
271+
assert region.bbox.width <= column_width + 2
272+
if region.bbox.center[0] < midpoint:
273+
used_left = True
274+
else:
275+
used_right = True
276+
assert used_left and used_right
265277

266278
def test_right_to_left_documents_fill_the_right_column_first(
267279
self, renderer, typography, rng, arabic_source

tests/test_engine.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# --- Import all necessary classes ---
1111
from ocrsmith.config.schema import AppConfig
12-
from ocrsmith.core.OCRSmithEngine import OCRSmithEngine
12+
from ocrsmith.core.engine import OCRSmithEngine
1313
from ocrsmith.core.text_placement import PlacementResult
1414

1515
# --- Fixtures ---
@@ -66,12 +66,12 @@ def temp_dir():
6666

6767
# Patch all managers at the class level to ensure they are mocked for every test.
6868
# This prevents real managers from being initialized with mock configs.
69-
@patch("ocrsmith.core.OCRSmithEngine.BackgroundManager")
70-
@patch("ocrsmith.core.OCRSmithEngine.TextRenderingManager")
71-
@patch("ocrsmith.core.OCRSmithEngine.TextPlacementManager")
72-
@patch("ocrsmith.core.OCRSmithEngine.AugmentationManager")
73-
@patch("ocrsmith.core.OCRSmithEngine.FontManager")
74-
@patch("ocrsmith.core.OCRSmithEngine.TextDataManager")
69+
@patch("ocrsmith.core.engine.BackgroundManager")
70+
@patch("ocrsmith.core.engine.TextRenderingManager")
71+
@patch("ocrsmith.core.engine.TextPlacementManager")
72+
@patch("ocrsmith.core.engine.AugmentationManager")
73+
@patch("ocrsmith.core.engine.FontManager")
74+
@patch("ocrsmith.core.engine.TextDataManager")
7575
class TestOCRSmithEngine:
7676
"""Tests for the main OCRSmithEngine class with all dependencies mocked."""
7777

tests/test_multiprocessing_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from ocrsmith.config.schema import AppConfig
6-
from ocrsmith.core.OCRSmithEngine import OCRSmithEngine
6+
from ocrsmith.core.engine import OCRSmithEngine
77

88

99
@pytest.fixture

0 commit comments

Comments
 (0)