File indexing completed on 2026-11-20 09:34:02
0001 """ROOT legend-lifetime regression; requires the production fix in upstream #94."""
0002 import os
0003 from pathlib import Path
0004 import shlex
0005 import shutil
0006 import subprocess
0007 import tempfile
0008 import unittest
0009
0010
0011 class LegendLifetimeTest(unittest.TestCase):
0012 def test_temporary_fit_survives_repaint(self):
0013 source = Path(os.environ.get("LFHCAL_SOURCE_DIR", Path(__file__).resolve().parents[2]))
0014 header = source / "NewStructure" / "FitCurveDrawing.h"
0015 if not header.is_file() or "AddMipFitLegendEntry" not in header.read_text():
0016 self.skipTest("requires production legend-lifetime fix (upstream PR #94); not validated")
0017 root_config = shutil.which("root-config")
0018 self.assertIsNotNone(root_config, "root-config is required once the production fix is present")
0019 flags = subprocess.check_output([root_config, "--cflags", "--libs"], text=True, timeout=30)
0020 compiler = shlex.split(os.environ.get("CXX", "c++"))
0021 with tempfile.TemporaryDirectory(prefix="lfhcal-legend-") as directory:
0022 executable = Path(directory) / "test_fit_curve_legend"
0023 command = compiler + [str(Path(__file__).with_name("test_fit_curve_legend.cc")),
0024 "-I" + str(source / "NewStructure"), "-o", str(executable)] + shlex.split(flags)
0025 subprocess.run(command, check=True, timeout=120)
0026 fixed = subprocess.run([str(executable)], capture_output=True, text=True, timeout=60)
0027 self.assertEqual(fixed.returncode, 0, fixed.stdout + fixed.stderr)
0028 self.assertIn("passed across 10 layers", fixed.stdout)
0029 legacy = subprocess.run([str(executable), "--legacy"], capture_output=True, text=True, timeout=60)
0030 self.assertEqual(legacy.returncode, 3, legacy.stdout + legacy.stderr)
0031 self.assertIn("legend retains a destroyed source TF1", legacy.stderr)
0032
0033
0034 if __name__ == "__main__":
0035 unittest.main(verbosity=2)