feat: a ready sheet can carry the empty strips cut from its top and bottom, and prints without them
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 7m49s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m23s

Step 1 of trimming empty strips (Marcus, 2026-11-18): the server side.

- ProductionSource has trim_top_cm and trim_bottom_cm (default 0); only
  a measured finished sheet may carry them, and length_cm is what is
  left, billed and printed.
- The generator leaves those file rows out (whole decode and banded PNG
  reading), and the proportion check compares the art with what is left.
  A PDF with a cut, or a cut that does not match the file, goes to hand
  preparation.
- The Prumo report says "Faixas vazias cortadas: N cm".

The Site does not send the cut yet (step 2).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-18 11:44:48 -03:00
parent ad3a966ae2
commit 06f4ec9f20
6 changed files with 120 additions and 6 deletions

View File

@@ -115,6 +115,26 @@ class PngRenderTests(unittest.TestCase):
self.assertGreater(film.crop((0, 59, film.width, film.height)).getextrema()[3][1], 0)
self.assertEqual(detail['format'], 'png')
def test_a_trimmed_sheet_prints_only_what_is_between_its_empty_strips(self):
# The Site cut 1 cm of transparency above and below 0,5 cm of art
# (Marcus, 2026-11-18): the film is the art alone, read whole or in bands.
art = quadrants(118, 59, alpha=True)
sheet = Image.new('RGBA', (118, 118 + 59 + 118))
sheet.paste(art, (0, 118))
spec = item([placement(0, 0, 1, 0.5)], [{**source(1, 0.5), 'kind': 'sheet',
'trim_top_cm': 1, 'trim_bottom_cm': 1}], 0.5)
for stream in (False, True):
with mock.patch.object(printpng, 'STREAM_ABOVE_PIXELS', 0 if stream else 10 ** 9):
parts, detail = self.render(spec, [self.save(sheet, 'trimmed.png')])
film = Image.open(parts[0][0])
self.assertEqual(film.size, (px(57), 59), stream)
self.assertEqual(film.crop((0, 0, 118, 59)).tobytes(), art.tobytes(), stream)
self.assertEqual(detail['height_cm'], '0.5')
# A cut that does not match the file is refused, so the room prepares it.
spec['production']['sources'][0].update(trim_top_cm=2, trim_bottom_cm=2)
with self.assertRaises(printpng.Unsupported):
self.render(spec, [self.save(sheet, 'trimmed.png')])
def test_loose_art_is_turned_and_mirrored_like_the_site(self):
art = quadrants(80, 40, alpha=True)
# 80 x 40 px at 300 DPI is 6,773 x 3,387 cm; placed turned 90 degrees.

50
tests/test_sheet_trim.py Normal file
View File

@@ -0,0 +1,50 @@
"""Empty strips cut from a ready sheet (Marcus, 2026-11-18): only a measured
finished sheet may carry them, and they never change what is placed.
Run from the repository root: python3 -m unittest tests.test_sheet_trim -v.
"""
import unittest
from uuid import uuid4
from pydantic import ValidationError
from app.core.models import Item
def sheet_item(mode='file', kind='sheet', measurement='file', top=10, bottom=40):
upload = str(uuid4())
width = 27 if mode in ('uvfile', 'uv') else 57
return {'mode': mode, 'metres': '4.6', 'grade': 100, 'uploads': [upload],
'quality_status': 'ok', 'quality_acknowledged': False,
'production': {'version': 3, 'film_width_cm': width, 'height_cm': '453.8',
'sources': [{'upload_id': upload, 'kind': kind, 'width_cm': width,
'length_cm': '453.8', 'copies': 1, 'measurement': measurement,
'trim_top_cm': top, 'trim_bottom_cm': bottom}],
'placements': [{'source_index': 0, 'copy_index': 0, 'x_cm': 0, 'y_cm': 0,
'width_cm': width, 'length_cm': '453.8',
'rotation_degrees': 0, 'mirrored': False}]}}
class SheetTrimTests(unittest.TestCase):
def test_a_measured_ready_sheet_carries_its_cut_strips(self):
item = Item.model_validate(sheet_item(mode='uvfile'))
source = item.production.sources[0]
self.assertEqual((source.trim_top_cm, source.trim_bottom_cm), (10, 40))
def test_no_strips_by_default(self):
data = sheet_item()
del data['production']['sources'][0]['trim_top_cm'], data['production']['sources'][0]['trim_bottom_cm']
source = Item.model_validate(data).production.sources[0]
self.assertEqual((source.trim_top_cm, source.trim_bottom_cm), (0, 0))
def test_only_a_measured_ready_sheet_is_trimmed(self):
with self.assertRaises(ValidationError):
Item.model_validate(sheet_item(measurement='customer'))
with self.assertRaises(ValidationError):
Item.model_validate(sheet_item(mode='avulsa', kind='artwork'))
with self.assertRaises(ValidationError):
Item.model_validate(sheet_item(top=-1))
if __name__ == '__main__':
unittest.main()