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
@@ -8,7 +8,7 @@ import unittest
|
||||
|
||||
|
||||
class AnnotationHeightConfigTests(unittest.TestCase):
|
||||
def load_generators(self, setting):
|
||||
def load_generators(self, setting, attribute="MAX_HEIGHT_PX"):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
config = Path(directory) / "config.py"
|
||||
config.write_text("from default_config import *\n" + setting, encoding="utf-8")
|
||||
@@ -16,7 +16,7 @@ class AnnotationHeightConfigTests(unittest.TestCase):
|
||||
[sys.executable, "-c",
|
||||
"from copienator.commands import annotating_by_label as grouped; "
|
||||
"from copienator.commands import annotating_with_checks as checks; "
|
||||
"print(grouped.MAX_HEIGHT_PX, checks.MAX_HEIGHT_PX)"],
|
||||
f"print(grouped.{attribute}, checks.{attribute})"],
|
||||
cwd=Path(__file__).resolve().parents[1],
|
||||
env={**os.environ, "COPIENATOR_CONFIG": str(config)},
|
||||
capture_output=True, text=True, check=False,
|
||||
@@ -30,7 +30,7 @@ class AnnotationHeightConfigTests(unittest.TestCase):
|
||||
def test_older_configuration_keeps_current_default(self):
|
||||
result = self.load_generators("del ANNOTATION_MAX_HEIGHT_PX\n")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout.strip(), "32000 32000")
|
||||
self.assertEqual(result.stdout.strip(), "33000 33000")
|
||||
|
||||
def test_invalid_heights_are_rejected(self):
|
||||
for value in ("0", "-1", "1.5", "True", "'32000'"):
|
||||
@@ -38,3 +38,20 @@ class AnnotationHeightConfigTests(unittest.TestCase):
|
||||
result = self.load_generators(f"ANNOTATION_MAX_HEIGHT_PX = {value}\n")
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("ANNOTATION_MAX_HEIGHT_PX must be a positive integer", result.stderr)
|
||||
|
||||
def test_custom_pixel_limit_reaches_both_generators(self):
|
||||
result = self.load_generators("ANNOTATION_MAX_PIXELS = 50000000\n", "MAX_PIXELS")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout.strip(), "50000000 50000000")
|
||||
|
||||
def test_older_configuration_keeps_default_pixel_limit(self):
|
||||
result = self.load_generators("del ANNOTATION_MAX_PIXELS\n", "MAX_PIXELS")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout.strip(), "67108864 67108864")
|
||||
|
||||
def test_invalid_pixel_limits_are_rejected(self):
|
||||
for value in ("0", "-1", "1.5", "True", "'67108864'"):
|
||||
with self.subTest(value=value):
|
||||
result = self.load_generators(f"ANNOTATION_MAX_PIXELS = {value}\n")
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("ANNOTATION_MAX_PIXELS must be a positive integer", result.stderr)
|
||||
Reference in new issue
Block a user