import ast from pathlib import Path import unittest APP_PATH = Path(__file__).resolve().parents[1] / "app.py" def _render_matrix_source() -> str: source = APP_PATH.read_text(encoding="utf-8") tree = ast.parse(source) for node in ast.walk(tree): if isinstance(node, ast.FunctionDef) and node.name == "render_matrix": return ast.get_source_segment(source, node) or "" raise AssertionError("render_matrix not found") class MatrixRenderingStaticTest(unittest.TestCase): def test_render_matrix_uses_dynamic_contrast_helpers(self) -> None: source = _render_matrix_source() self.assertIn("matrix_color_domain", source) self.assertIn("matrix_color_ticks", source) self.assertIn("matrix_text_colors", source) self.assertIn("zmin=zmin", source) self.assertIn("zmax=zmax", source) self.assertIn("annotations=annotations", source) self.assertIn("font=dict(size=12, color=text_colors", source) self.assertNotIn("[zmin, 0.5, zmax]", source) self.assertNotIn("zmin=0", source) self.assertNotIn("zmax=1", source) if __name__ == "__main__": unittest.main()