miscs
This commit is contained in:
1 parent
c30aac0572
commit
834ffe32f2
7 files changed
+116
-14
No files matched your search
@@ -12,6 +12,7 @@ from copienator.annotation_layout import (
|
||||
move_answer_pdf, save_parts,
|
||||
)
|
||||
from copienator.commands import annotating, annotating_by_label, splitting_int
|
||||
from copienator.commands.annotating_with_checks import CheckboxRenderer
|
||||
from copienator.commands import reading_grouped_annotations as reader
|
||||
from copienator.left_margin import analyse_margins
|
||||
from copienator.pdf_cut import split_pdf
|
||||
@@ -113,6 +114,26 @@ class AnnotationLayoutTests(unittest.TestCase):
|
||||
self.assertEqual(low.getpixel((400, height + 80)), (0, 0, 255))
|
||||
self.assertEqual(low.getpixel((399, height + 80)), (255, 255, 255))
|
||||
|
||||
def test_later_rectangle_cannot_draw_inside_comment_checkbox(self):
|
||||
renderer = CheckboxRenderer('Ex 1')
|
||||
result = {'score': 2, 'feedback': [
|
||||
{'text': 'First comment', 'box_2d': [10, 50, 50, 200]},
|
||||
{'text': 'Later rectangle', 'box_2d': [10, 300, 80, 400]},
|
||||
]}
|
||||
with patch.object(annotating, 'render_score_text', return_value=Image.new('RGB', (800, 80), 'white')):
|
||||
image, _ = annotating.compose_label_image(
|
||||
Image.new('RGB', (1654, 100), 'white'), 'Ex 1', result, 0,
|
||||
render_fn=lambda *args, **kwargs: Image.new('RGBA', (620, 50), (255, 200, 200, 180)),
|
||||
draw_callback=renderer.callback, layout=legacy_layout())
|
||||
# The later rectangle's left edge crosses the first comment's checkbox.
|
||||
checkbox = next(item for item in renderer.checkboxes
|
||||
if item['type'] == 'del_local' and item['index'] == 0)
|
||||
x1, y1, x2, y2 = checkbox['final_box']
|
||||
interior = image.crop((x1 + 5, y1 + 5, x2 - 5, y2 - 5))
|
||||
self.assertEqual(interior.getextrema(), ((255, 255),) * 3)
|
||||
# The rectangle still exists outside the checkbox.
|
||||
self.assertEqual(image.getpixel((650, 90)), (255, 0, 0))
|
||||
|
||||
def test_mixed_bgnot_widths_and_saved_geometry_survive_config_change(self):
|
||||
normal, height, _ = self.render(legacy_layout())
|
||||
low, _, _ = self.render({**legacy_layout(), 'margin_left': 400})
|
||||
|
||||
@@ -372,6 +372,50 @@ class GuiConvenienceTests(unittest.TestCase):
|
||||
self.assertEqual(self.app.state_store.step("correction")["variant"], "integrate")
|
||||
self.assertIn("--deal-with-batched", self.app._make_command())
|
||||
|
||||
def test_batch_integration_success_selects_conflicts_or_cleanup(self):
|
||||
for conflicts, visited in product((None, "### Aucun conflit\n", "Copie01 A -> B\n"), (False, True)):
|
||||
with self.subTest(conflicts=conflicts, visited=visited):
|
||||
manual = self.evaluation / "manual_resolutions.txt"
|
||||
if conflicts is None:
|
||||
manual.unlink(missing_ok=True)
|
||||
else:
|
||||
manual.write_text(conflicts, encoding="utf-8")
|
||||
(self.evaluation / "correction.json").write_text("{}", encoding="utf-8")
|
||||
self.app.state_store.update_step(
|
||||
"correction", variant="integrate", last_run_variant="integrate"
|
||||
)
|
||||
self.app.state_store.update_step("manual_resolution", visited=visited, status="stale")
|
||||
self.app._populate_tree()
|
||||
self.app.tree.selection_set("correction")
|
||||
self.app.update()
|
||||
self.app.active_step_id = "correction"
|
||||
with patch.object(self.app.runner, "start") as start:
|
||||
self.app._finish_process(0, False)
|
||||
self.app.update()
|
||||
start.assert_not_called()
|
||||
expected = "manual_resolution" if conflicts == "Copie01 A -> B\n" else "post_correction"
|
||||
self.assertEqual(self.app.current_step.id, expected)
|
||||
expected_status = "stale" if expected == "manual_resolution" else "success"
|
||||
self.assertEqual(self.app.state_store.step("manual_resolution")["status"], expected_status)
|
||||
if expected_status == "success":
|
||||
self.assertEqual(self.app.tree.item("manual_resolution", "values"), ("Réussie",))
|
||||
for step_id in ("submit_batches", "batch_status", "fetch_batches", "prepare_recorrection"):
|
||||
self.assertFalse(self.app.state_store.step(step_id).get("visited"))
|
||||
|
||||
def test_unsuccessful_batch_integration_stays_on_correction(self):
|
||||
self.app.state_store.update_step(
|
||||
"correction", variant="integrate", last_run_variant="integrate"
|
||||
)
|
||||
self.app._populate_tree()
|
||||
self.app.tree.selection_set("correction")
|
||||
self.app.update()
|
||||
for code, interrupted in ((4, False), (1, False), (0, True)):
|
||||
with self.subTest(code=code, interrupted=interrupted):
|
||||
self.app.active_step_id = "correction"
|
||||
self.app._finish_process(code, interrupted)
|
||||
self.app.update()
|
||||
self.assertEqual(self.app.current_step.id, "correction")
|
||||
|
||||
def test_correction_invalidates_batches_only_when_regenerating_or_resetting(self):
|
||||
for variant, action in product(
|
||||
("integrate", "live", "refaire", "batch", "hybrid", "reset"), ("run", "mark")
|
||||
|
||||
Reference in new issue
Block a user