"""The personal configuration controls both annotation generators.""" import os from pathlib import Path import subprocess import sys import tempfile import unittest class AnnotationHeightConfigTests(unittest.TestCase): def load_generators(self, setting): with tempfile.TemporaryDirectory() as directory: config = Path(directory) / "config.py" config.write_text("from default_config import *\n" + setting, encoding="utf-8") return subprocess.run( [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)"], cwd=Path(__file__).resolve().parents[1], env={**os.environ, "COPIENATOR_CONFIG": str(config)}, capture_output=True, text=True, check=False, ) def test_custom_height_reaches_both_generators(self): result = self.load_generators("ANNOTATION_MAX_HEIGHT_PX = 16000\n") self.assertEqual(result.returncode, 0, result.stderr) self.assertEqual(result.stdout.strip(), "16000 16000") 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") def test_invalid_heights_are_rejected(self): for value in ("0", "-1", "1.5", "True", "'32000'"): with self.subTest(value=value): 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)