Support evaluation-local configuration and names overrides

This commit is contained in:
sebastien committed 2026-11-03 18:44:56 +01:00
1 parent 0bb6f7d97c
commit d4404e4c27
36 files changed
+409 -184

No files matched your search

+15 -14
View File
@@ -18,6 +18,7 @@ from unittest.mock import Mock, patch
from PIL import Image
from pypdf import PdfReader, PdfWriter
from copienator import configuration
from copienator import (
CliError,
EvaluationWorkspace,
@@ -531,7 +532,7 @@ class StandardCliTests(unittest.TestCase):
evaluation = base / "Exam"
evaluation.mkdir()
export_dir = base / "Export"
with patch.object(module, "EXPORT_DIR", export_dir), redirect_stderr(
with patch.object(module.configuration, "EXPORT_DIR", export_dir), redirect_stderr(
io.StringIO()
):
self.assertEqual(module.main([str(evaluation)]), 3)
@@ -706,7 +707,7 @@ class StandardCliTests(unittest.TestCase):
source = evaluation / "BGnot" / "Ex 1"
source.mkdir(parents=True)
(source / "Concat.pdf").write_bytes(b"annotated")
with patch.object(module, "EXPORT_DIR", base / "Export"):
with patch.object(module.configuration, "EXPORT_DIR", base / "Export"):
self.assertEqual(module.main([str(evaluation)]), 0)
exported = base / "Export" / "Exam" / "Ex 1.pdf"
self.assertEqual(exported.read_bytes(), b"annotated")
@@ -721,7 +722,7 @@ class StandardCliTests(unittest.TestCase):
source.mkdir(parents=True)
suffix = ".jpg" if annotation_dir == "Anot" else ".pdf"
(source / f"Concat{suffix}").write_bytes(annotation_dir.encode())
with patch.object(module, "EXPORT_DIR", base / "Export"):
with patch.object(module.configuration, "EXPORT_DIR", base / "Export"):
self.assertEqual(module.main([str(evaluation), annotation_dir]), 0)
self.assertEqual(
(base / "Export" / "Exam" / f"Copie01{suffix}").read_bytes(),
@@ -738,7 +739,7 @@ class StandardCliTests(unittest.TestCase):
import_dir = base / "Import"
import_dir.mkdir()
(import_dir / "Ex 1.pdf").write_bytes(b"handwritten")
with patch.object(module, "IMPORT_DIR", import_dir):
with patch.object(module.configuration, "IMPORT_DIR", import_dir):
self.assertEqual(module.main([str(evaluation)]), 0)
self.assertEqual(
(target / "Concat_annotated.pdf").read_bytes(), b"handwritten"
@@ -756,7 +757,7 @@ class StandardCliTests(unittest.TestCase):
import_dir.mkdir()
suffix = ".jpg" if annotation_dir == "Anot" else ".pdf"
(import_dir / f"Copie01{suffix}").write_bytes(b"handwritten")
with patch.object(module, "IMPORT_DIR", import_dir):
with patch.object(module.configuration, "IMPORT_DIR", import_dir):
self.assertEqual(module.main([str(evaluation), annotation_dir]), 0)
self.assertEqual(
(target / f"Concat_annotated{suffix}").read_bytes(), b"handwritten"
@@ -2323,7 +2324,7 @@ class StandardCliTests(unittest.TestCase):
("02", "Ex 1", small, 0, []),
("02", "Ex 2", small, 0, []),
]
with patch.object(module, "MAX_HEIGHT_PX", 100):
with patch.object(configuration, "ANNOTATION_MAX_HEIGHT_PX", 100):
batches = module.split_batches(rendered)
self.assertEqual([len(batch) for batch in batches], [1, 2])
self.assertTrue(
@@ -2338,14 +2339,14 @@ class StandardCliTests(unittest.TestCase):
("01", "Ex 2", image, 0, []),
("02", "Ex 1", image, 0, []),
]
with patch.object(module, "MAX_HEIGHT_PX", 100):
with patch.object(configuration, "ANNOTATION_MAX_HEIGHT_PX", 100):
batches = module.split_batches(rendered)
self.assertEqual(batches, [[rendered[0]], [rendered[1]], [rendered[2]]])
def test_grouped_oversized_answer_is_rejected(self) -> None:
module = self.modules["annotating_by_label"]
rendered = [("02", "Ex 1", Image.new("RGB", (10, 120)), 0, [])]
with tempfile.TemporaryDirectory() as directory, patch.object(module, "MAX_HEIGHT_PX", 100):
with tempfile.TemporaryDirectory() as directory, patch.object(configuration, "ANNOTATION_MAX_HEIGHT_PX", 100):
with self.assertRaisesRegex(CliError, "Copie02.*Ex 1"):
module.split_batches(rendered)
with self.assertRaises(CliError):
@@ -2359,7 +2360,7 @@ class StandardCliTests(unittest.TestCase):
("02", "Ex 1", Image.new("RGB", (30, 20)), 0, []),
("03", "Ex 1", Image.new("RGB", (10, 40)), 0, []),
]
with patch.object(module, "MAX_HEIGHT_PX", 100), patch.object(module, "MAX_PIXELS", 2000):
with patch.object(configuration, "ANNOTATION_MAX_HEIGHT_PX", 100), patch.object(configuration, "ANNOTATION_MAX_PIXELS", 2000):
batches = module.split_batches(rendered)
self.assertEqual(batches, [[rendered[0], rendered[2]], [rendered[1]]])
with tempfile.TemporaryDirectory() as directory:
@@ -2372,9 +2373,9 @@ class StandardCliTests(unittest.TestCase):
module = self.modules["annotating_by_label"]
image = Image.new("RGB", (30, 40))
rendered = [("01", label, image, 0, []) for label in ("Ex 1", "Ex 2")]
with patch.object(module, "MAX_HEIGHT_PX", 100), patch.object(module, "MAX_PIXELS", 1200):
with patch.object(configuration, "ANNOTATION_MAX_HEIGHT_PX", 100), patch.object(configuration, "ANNOTATION_MAX_PIXELS", 1200):
self.assertEqual(module.split_batches(rendered), [[rendered[0]], [rendered[1]]])
with patch.object(module, "MAX_PIXELS", 1199):
with patch.object(configuration, "ANNOTATION_MAX_PIXELS", 1199):
with self.assertRaisesRegex(CliError, "single answer cannot be split"):
module.split_batches(rendered)
@@ -2387,7 +2388,7 @@ class StandardCliTests(unittest.TestCase):
("04", "Ex 1", Image.new("RGB", (10, 15)), 0, []),
("04", "Ex 2", Image.new("RGB", (10, 15)), 0, []),
]
with patch.object(module, "MAX_HEIGHT_PX", 100):
with patch.object(configuration, "ANNOTATION_MAX_HEIGHT_PX", 100):
batches = module.split_batches(rendered)
self.assertEqual([[item[0] for item in batch] for batch in batches],
[["01", "04", "04"], ["02", "03"]])
@@ -2397,7 +2398,7 @@ class StandardCliTests(unittest.TestCase):
def test_grouped_annotation_height_limit_is_33000_pixels(self) -> None:
module = self.modules["annotating_by_label"]
self.assertEqual(module.MAX_HEIGHT_PX, 33000)
self.assertEqual(module.annotation_limits()[0], 33000)
class WorkflowTests(unittest.TestCase):
@@ -2511,7 +2512,7 @@ class WorkflowTests(unittest.TestCase):
def test_crop_auto_start_follows_always_crop_configuration(self) -> None:
for enabled in (False, True):
with self.subTest(enabled=enabled), patch(
"copienator_gui.workflow.ALWAYS_CROP", enabled
"copienator_gui.workflow.configuration.ALWAYS_CROP", enabled
):
steps = {step.id: step for step in build_workflow(False)}
self.assertEqual(