test(magazine): use a fixed fixture for the page-159 delete-picture test
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0244fceb55
commit
b50855ea2e
@ -2235,20 +2235,32 @@ class DeletePictureTests(unittest.TestCase):
|
||||
self.assertEqual(json.dumps(layout, sort_keys=True), snapshot)
|
||||
self.assertEqual(self.ids(delete_region(layout, "nope")), self.ids(layout))
|
||||
|
||||
def test_the_real_page_159_pictures_leave_nothing_behind(self):
|
||||
"""Measured on the production c't issue: deleting either picture of page 159 used to leave its empty figure block."""
|
||||
def test_a_page_laid_out_like_the_real_page_159_leaves_nothing_behind(self):
|
||||
"""Page 159 of the production c't issue had two picture regions, each stored as a figure block plus a region
|
||||
image, and two hand-drawn pictures; deleting either region image used to leave its empty figure block. A fixed
|
||||
copy of that shape, not the live file (which the reader edits)."""
|
||||
import copy
|
||||
from core.magazine import delete_region
|
||||
path = Path(__file__).resolve().parents[1] / "config" / "reader_library" / "bd871c7c22f0449984d3b0e3d603d6d6" / "layout.json"
|
||||
if not path.is_file():
|
||||
self.skipTest("the production layout is not on this machine")
|
||||
real = json.loads(path.read_text("utf-8"))
|
||||
real = {"pages": [{"page": 159, "width": 580.0, "height": 680.0}], "blocks": [
|
||||
{"id": "b0159-v008", "page": 159, "bbox": [75, 204, 121, 136], "type": "figure", "text": "", "reading_order": 3},
|
||||
{"id": "b0159-v011", "page": 159, "bbox": [202, 204, 121, 224], "type": "figure", "text": "", "reading_order": 5},
|
||||
{"id": "b0159-v001", "page": 159, "bbox": [75, 60, 250, 120], "type": "body", "text": "Fliesstext.", "reading_order": 1}],
|
||||
"images": [
|
||||
{"id": "p0159-region-b0159-v008", "page": 159, "bbox": [75, 204, 121, 136], "source_block": "b0159-v008", "type": "figure"},
|
||||
{"id": "p0159-region-b0159-v011", "page": 159, "bbox": [202, 204, 121, 224], "source_block": "b0159-v011", "type": "figure"},
|
||||
{"id": "p0159-manual-000", "page": 159, "bbox": [393, 301, 164, 327], "source_block": None},
|
||||
{"id": "p0159-manual-001", "page": 159, "bbox": [150, 360, 39, 59], "source_block": None}]}
|
||||
for image_id, block_id in (("p0159-region-b0159-v008", "b0159-v008"), ("p0159-region-b0159-v011", "b0159-v011")):
|
||||
after = delete_region(copy.deepcopy(real), image_id)
|
||||
self.assertNotIn(block_id, {b["id"] for b in after["blocks"]})
|
||||
self.assertNotIn(image_id, {i["id"] for i in after["images"]})
|
||||
self.assertEqual(len(after["blocks"]), len(real["blocks"]) - 1)
|
||||
self.assertEqual(len(after["images"]), len(real["images"]) - 1)
|
||||
self.assertIn("b0159-v001", {b["id"] for b in after["blocks"]}) # the text is still there
|
||||
for manual in ("p0159-manual-000", "p0159-manual-001"):
|
||||
after = delete_region(copy.deepcopy(real), manual)
|
||||
self.assertEqual(len(after["blocks"]), len(real["blocks"])) # a hand-drawn picture takes nothing else
|
||||
self.assertEqual(len(after["images"]), len(real["images"]) - 1)
|
||||
|
||||
def test_clean_up_retypes_what_earlier_deletes_left_behind_but_not_real_pictures(self):
|
||||
from core.magazine import clean_up_regions
|
||||
|
||||
Loading…
Reference in New Issue
Block a user