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
+34
-17
@@ -2330,7 +2330,7 @@ class StandardCliTests(unittest.TestCase):
|
||||
all(sum(item[2].height for item in batch) <= 100 for batch in batches)
|
||||
)
|
||||
|
||||
def test_grouped_batching_never_splits_one_student(self) -> None:
|
||||
def test_grouped_batching_splits_oversized_student_between_answers(self) -> None:
|
||||
module = self.modules["annotating_by_label"]
|
||||
image = Image.new("RGB", (10, 60), "white")
|
||||
rendered = [
|
||||
@@ -2340,26 +2340,43 @@ class StandardCliTests(unittest.TestCase):
|
||||
]
|
||||
with patch.object(module, "MAX_HEIGHT_PX", 100):
|
||||
batches = module.split_batches(rendered)
|
||||
self.assertEqual(batches, [rendered[:2], rendered[2:]])
|
||||
self.assertEqual(batches, [[rendered[0]], [rendered[1]], [rendered[2]]])
|
||||
|
||||
def test_grouped_oversized_answer_is_saved_as_its_own_group(self) -> None:
|
||||
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 self.assertRaisesRegex(CliError, "Copie02.*Ex 1"):
|
||||
module.split_batches(rendered)
|
||||
with self.assertRaises(CliError):
|
||||
module.save_batch(rendered, "Ex 1", 1, Path(directory))
|
||||
self.assertFalse((Path(directory) / "Ex 1 G1").exists())
|
||||
|
||||
def test_grouped_pixels_include_padding_to_the_widest_answer(self) -> None:
|
||||
module = self.modules["annotating_by_label"]
|
||||
rendered = [
|
||||
("01", "Ex 1", Image.new("RGB", (10, 40)), 0, []),
|
||||
("02", "Ex 1", Image.new("RGB", (10, 120)), 0, []),
|
||||
("03", "Ex 1", Image.new("RGB", (10, 50)), 0, []),
|
||||
("01", "Ex 1", Image.new("RGB", (10, 60)), 0, []),
|
||||
("02", "Ex 1", Image.new("RGB", (30, 20)), 0, []),
|
||||
("03", "Ex 1", Image.new("RGB", (10, 40)), 0, []),
|
||||
]
|
||||
with tempfile.TemporaryDirectory() as directory, patch.object(module, "MAX_HEIGHT_PX", 100):
|
||||
with patch.object(module, "MAX_HEIGHT_PX", 100), patch.object(module, "MAX_PIXELS", 2000):
|
||||
batches = module.split_batches(rendered)
|
||||
self.assertEqual(batches, [[rendered[0], rendered[2]], [rendered[1]]])
|
||||
for index, batch in enumerate(batches, start=1):
|
||||
module.save_batch(batch, "Ex 1", index, Path(directory))
|
||||
metadata = read_json(Path(directory) / "Ex 1 G2/bnote.json")
|
||||
self.assertEqual(metadata["height"], 120)
|
||||
self.assertEqual([item["id"] for item in metadata["images"]], ["02"])
|
||||
self.assertTrue((Path(directory) / "Ex 1 G2/Concat.pdf").is_file())
|
||||
with self.assertRaises(CliError):
|
||||
module.save_batch(rendered[:2], "Ex 1", 3, Path(directory))
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
for index, batch in enumerate(batches):
|
||||
module.save_batch(batch, "Ex 1", index, Path(directory))
|
||||
with self.assertRaises(CliError):
|
||||
module.save_batch(rendered[:2], "Ex 1", 3, Path(directory))
|
||||
|
||||
def test_grouped_pixel_limit_splits_student_and_rejects_single_answer(self) -> None:
|
||||
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):
|
||||
self.assertEqual(module.split_batches(rendered), [[rendered[0]], [rendered[1]]])
|
||||
with patch.object(module, "MAX_PIXELS", 1199):
|
||||
with self.assertRaisesRegex(CliError, "single answer cannot be split"):
|
||||
module.split_batches(rendered)
|
||||
|
||||
def test_grouped_batching_reuses_space_in_earlier_groups(self) -> None:
|
||||
module = self.modules["annotating_by_label"]
|
||||
@@ -2378,9 +2395,9 @@ class StandardCliTests(unittest.TestCase):
|
||||
[100, 100])
|
||||
self.assertEqual(batches[0][-2:], rendered[-2:])
|
||||
|
||||
def test_grouped_annotation_height_limit_is_32000_pixels(self) -> None:
|
||||
def test_grouped_annotation_height_limit_is_33000_pixels(self) -> None:
|
||||
module = self.modules["annotating_by_label"]
|
||||
self.assertEqual(module.MAX_HEIGHT_PX, 32000)
|
||||
self.assertEqual(module.MAX_HEIGHT_PX, 33000)
|
||||
|
||||
|
||||
class WorkflowTests(unittest.TestCase):
|
||||
|
||||
Reference in new issue
Block a user