Enforce configurable height and pixel limits for tablet documents
This commit is contained in:
1 parent
8918d64452
commit
a38c1ff4b3
10 files changed
+187
-57
No files matched your search
@@ -54,7 +54,7 @@ class CheckedDocumentTests(unittest.TestCase):
|
||||
overwrite=overwrite, output_mode='checks')
|
||||
|
||||
def test_splits_on_labels_and_resets_geometry_at_each_part(self):
|
||||
self.assertEqual(MAX_HEIGHT_PX, 32000)
|
||||
self.assertEqual(MAX_HEIGHT_PX, 33000)
|
||||
self.assertEqual(self.generate(), 'success')
|
||||
parts = copy_documents(self.output)
|
||||
self.assertEqual([part.name for part in parts], ['Part1', 'Part2'])
|
||||
@@ -75,6 +75,30 @@ class CheckedDocumentTests(unittest.TestCase):
|
||||
self.assertTrue((self.output / 'Concat.pdf').is_file())
|
||||
self.assertFalse((self.output / 'Part1').exists())
|
||||
|
||||
def test_pixel_limit_splits_documents_at_exact_boundary(self):
|
||||
with patch.object(checks, 'MAX_PIXELS', 6000):
|
||||
self.assertEqual(self.generate(), 'success')
|
||||
parts = copy_documents(self.output)
|
||||
self.assertEqual([read_json(p / 'bnote.json')['height'] for p in parts], [60, 40, 60])
|
||||
|
||||
def test_pixel_limit_accounts_for_width_growth_and_preserves_previous_copy(self):
|
||||
original = self.compose
|
||||
def wider(base, label, *args, **kwargs):
|
||||
image, header = original(base, label, *args, **kwargs)
|
||||
if label == 'Ex 2':
|
||||
image = image.resize((200, image.height))
|
||||
return image, header
|
||||
with patch.object(self, 'compose', side_effect=wider), patch.object(checks, 'MAX_PIXELS', 12000):
|
||||
self.assertEqual(self.generate(), 'success')
|
||||
parts = copy_documents(self.output)
|
||||
self.assertEqual([read_json(p / 'bnote.json')['width'] for p in parts], [100, 200, 100])
|
||||
sentinel = self.output / 'sentinel'
|
||||
sentinel.write_text('previous')
|
||||
with patch.object(checks, 'MAX_PIXELS', 5999):
|
||||
with self.assertRaisesRegex(CliError, 'Copie01.*Ex 1'):
|
||||
self.generate(overwrite=True)
|
||||
self.assertEqual(sentinel.read_text(), 'previous')
|
||||
|
||||
def test_single_oversized_answer_and_save_failure_preserve_previous_copy(self):
|
||||
self.generate()
|
||||
sentinel = self.output / 'sentinel'
|
||||
|
||||
Reference in new issue
Block a user