Cleanup: Delete ALL 242 shims, update ALL consumer imports
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 41s
CI / test-go-edu-search (push) Successful in 32s
CI / test-python-klausur (push) Failing after 2m41s
CI / test-python-agent-core (push) Successful in 34s
CI / test-nodejs-website (push) Successful in 39s

klausur-service: 183 shims deleted, 26 test files + 8 source files updated
backend-lehrer: 59 shims deleted, main.py + 8 source files updated

All imports now use the new package paths directly.
Zero shims remaining in the entire codebase.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-04-26 00:11:33 +02:00
parent d093a4d388
commit 5f2ed44654
288 changed files with 214 additions and 1182 deletions

View File

@@ -19,8 +19,8 @@ import importlib
# ---------------------------------------------------------------------------
def _fresh_import():
"""Re-import cv_doclayout_detect with reset globals."""
import cv_doclayout_detect as mod
"""Re-import ocr.detect.doclayout_detect with reset globals."""
import ocr.detect.doclayout_detect as mod
# Reset module-level caching so each test starts clean
mod._onnx_session = None
mod._model_path = None
@@ -62,7 +62,7 @@ class TestIsDoclayoutAvailableNoModel:
class TestLayoutRegionDataclass:
def test_basic_creation(self):
from cv_doclayout_detect import LayoutRegion
from ocr.detect.doclayout_detect import LayoutRegion
region = LayoutRegion(
x=10, y=20, width=100, height=200,
label="figure", confidence=0.95, label_index=1,
@@ -76,14 +76,14 @@ class TestLayoutRegionDataclass:
assert region.label_index == 1
def test_all_fields_present(self):
from cv_doclayout_detect import LayoutRegion
from ocr.detect.doclayout_detect import LayoutRegion
import dataclasses
field_names = {f.name for f in dataclasses.fields(LayoutRegion)}
expected = {"x", "y", "width", "height", "label", "confidence", "label_index"}
assert field_names == expected
def test_different_labels(self):
from cv_doclayout_detect import LayoutRegion, DOCLAYOUT_CLASSES
from ocr.detect.doclayout_detect import LayoutRegion, DOCLAYOUT_CLASSES
for idx, label in enumerate(DOCLAYOUT_CLASSES):
region = LayoutRegion(
x=0, y=0, width=50, height=50,
@@ -125,7 +125,7 @@ class TestDetectLayoutRegionsNoModel:
class TestPreprocessingShapes:
def test_square_image(self):
from cv_doclayout_detect import preprocess_image
from ocr.detect.doclayout_detect import preprocess_image
img = np.random.randint(0, 255, (800, 800, 3), dtype=np.uint8)
tensor, scale, pad_x, pad_y = preprocess_image(img)
assert tensor.shape == (1, 3, 800, 800)
@@ -134,7 +134,7 @@ class TestPreprocessingShapes:
assert tensor.max() <= 1.0
def test_landscape_image(self):
from cv_doclayout_detect import preprocess_image
from ocr.detect.doclayout_detect import preprocess_image
img = np.random.randint(0, 255, (600, 1200, 3), dtype=np.uint8)
tensor, scale, pad_x, pad_y = preprocess_image(img)
assert tensor.shape == (1, 3, 800, 800)
@@ -144,7 +144,7 @@ class TestPreprocessingShapes:
assert pad_y > 0 # vertical padding expected
def test_portrait_image(self):
from cv_doclayout_detect import preprocess_image
from ocr.detect.doclayout_detect import preprocess_image
img = np.random.randint(0, 255, (1200, 600, 3), dtype=np.uint8)
tensor, scale, pad_x, pad_y = preprocess_image(img)
assert tensor.shape == (1, 3, 800, 800)
@@ -154,20 +154,20 @@ class TestPreprocessingShapes:
assert pad_x > 0 # horizontal padding expected
def test_small_image(self):
from cv_doclayout_detect import preprocess_image
from ocr.detect.doclayout_detect import preprocess_image
img = np.random.randint(0, 255, (100, 200, 3), dtype=np.uint8)
tensor, scale, pad_x, pad_y = preprocess_image(img)
assert tensor.shape == (1, 3, 800, 800)
def test_typical_scan_a4(self):
"""A4 scan at 300dpi: roughly 2480x3508 pixels."""
from cv_doclayout_detect import preprocess_image
from ocr.detect.doclayout_detect import preprocess_image
img = np.random.randint(0, 255, (3508, 2480, 3), dtype=np.uint8)
tensor, scale, pad_x, pad_y = preprocess_image(img)
assert tensor.shape == (1, 3, 800, 800)
def test_values_normalized(self):
from cv_doclayout_detect import preprocess_image
from ocr.detect.doclayout_detect import preprocess_image
# All white image
img = np.full((400, 400, 3), 255, dtype=np.uint8)
tensor, _, _, _ = preprocess_image(img)
@@ -182,20 +182,20 @@ class TestPreprocessingShapes:
class TestNmsLogic:
def test_empty_input(self):
from cv_doclayout_detect import nms
from ocr.detect.doclayout_detect import nms
boxes = np.array([]).reshape(0, 4)
scores = np.array([])
assert nms(boxes, scores) == []
def test_single_box(self):
from cv_doclayout_detect import nms
from ocr.detect.doclayout_detect import nms
boxes = np.array([[10, 10, 100, 100]], dtype=np.float32)
scores = np.array([0.9])
kept = nms(boxes, scores, iou_threshold=0.5)
assert kept == [0]
def test_non_overlapping_boxes(self):
from cv_doclayout_detect import nms
from ocr.detect.doclayout_detect import nms
boxes = np.array([
[0, 0, 50, 50],
[200, 200, 300, 300],
@@ -207,7 +207,7 @@ class TestNmsLogic:
assert set(kept) == {0, 1, 2}
def test_overlapping_boxes_suppressed(self):
from cv_doclayout_detect import nms
from ocr.detect.doclayout_detect import nms
# Two boxes that heavily overlap
boxes = np.array([
[10, 10, 110, 110], # 100x100
@@ -219,7 +219,7 @@ class TestNmsLogic:
assert kept == [0]
def test_partially_overlapping_boxes_kept(self):
from cv_doclayout_detect import nms
from ocr.detect.doclayout_detect import nms
# Two boxes that overlap ~25% (below 0.5 threshold)
boxes = np.array([
[0, 0, 100, 100], # 100x100
@@ -231,7 +231,7 @@ class TestNmsLogic:
assert len(kept) == 2
def test_nms_respects_score_ordering(self):
from cv_doclayout_detect import nms
from ocr.detect.doclayout_detect import nms
# Three overlapping boxes — highest confidence should be kept first
boxes = np.array([
[10, 10, 110, 110],
@@ -244,7 +244,7 @@ class TestNmsLogic:
assert kept[0] == 1
def test_iou_computation(self):
from cv_doclayout_detect import _compute_iou
from ocr.detect.doclayout_detect import _compute_iou
box_a = np.array([0, 0, 100, 100], dtype=np.float32)
box_b = np.array([0, 0, 100, 100], dtype=np.float32)
assert abs(_compute_iou(box_a, box_b) - 1.0) < 1e-5
@@ -259,7 +259,7 @@ class TestNmsLogic:
class TestDoclayoutClasses:
def test_correct_class_list(self):
from cv_doclayout_detect import DOCLAYOUT_CLASSES
from ocr.detect.doclayout_detect import DOCLAYOUT_CLASSES
expected = [
"table", "figure", "title", "text", "list",
"header", "footer", "equation", "reference", "abstract",
@@ -267,15 +267,15 @@ class TestDoclayoutClasses:
assert DOCLAYOUT_CLASSES == expected
def test_class_count(self):
from cv_doclayout_detect import DOCLAYOUT_CLASSES
from ocr.detect.doclayout_detect import DOCLAYOUT_CLASSES
assert len(DOCLAYOUT_CLASSES) == 10
def test_no_duplicates(self):
from cv_doclayout_detect import DOCLAYOUT_CLASSES
from ocr.detect.doclayout_detect import DOCLAYOUT_CLASSES
assert len(DOCLAYOUT_CLASSES) == len(set(DOCLAYOUT_CLASSES))
def test_all_lowercase(self):
from cv_doclayout_detect import DOCLAYOUT_CLASSES
from ocr.detect.doclayout_detect import DOCLAYOUT_CLASSES
for cls in DOCLAYOUT_CLASSES:
assert cls == cls.lower(), f"Class '{cls}' should be lowercase"
@@ -303,7 +303,7 @@ class TestGetDoclayoutStatus:
class TestPostprocessing:
def test_single_tensor_format_6cols(self):
"""Test parsing of (1, N, 6) output format: x1,y1,x2,y2,score,class."""
from cv_doclayout_detect import _postprocess
from ocr.detect.doclayout_detect import _postprocess
# One detection: figure at (100,100)-(300,300) in 800x800 space
raw = np.array([[[100, 100, 300, 300, 0.92, 1]]], dtype=np.float32)
@@ -320,7 +320,7 @@ class TestPostprocessing:
def test_three_tensor_format(self):
"""Test parsing of 3-tensor output: boxes, scores, class_ids."""
from cv_doclayout_detect import _postprocess
from ocr.detect.doclayout_detect import _postprocess
boxes = np.array([[50, 50, 200, 150]], dtype=np.float32)
scores = np.array([0.88], dtype=np.float32)
@@ -338,7 +338,7 @@ class TestPostprocessing:
def test_confidence_filtering(self):
"""Detections below threshold should be excluded."""
from cv_doclayout_detect import _postprocess
from ocr.detect.doclayout_detect import _postprocess
raw = np.array([
[100, 100, 200, 200, 0.9, 1], # above threshold
@@ -357,7 +357,7 @@ class TestPostprocessing:
def test_coordinate_scaling(self):
"""Verify coordinates are correctly scaled back to original image."""
from cv_doclayout_detect import _postprocess
from ocr.detect.doclayout_detect import _postprocess
# Image was 1600x1200, scaled to fit 800x800 → scale=0.5, pad_y offset
scale = 800 / 1600 # 0.5
@@ -382,7 +382,7 @@ class TestPostprocessing:
assert r.y == 200
def test_empty_output(self):
from cv_doclayout_detect import _postprocess
from ocr.detect.doclayout_detect import _postprocess
raw = np.array([]).reshape(1, 0, 6).astype(np.float32)
regions = _postprocess(
outputs=[raw],