# -*- coding: utf-8 -*- """Tests fuer die Mouseover-Texte des --track-Graphen (material_flow.py).""" from __future__ import annotations from material_flow import TrackNode, _tooltip_context, _track_node_tooltip from test_kreisel_junctions import KREISEL, SEPARATOREN, WEICHEN, _el, _kreisel def _anlage() -> list: kreisel = [_kreisel(*k) for k in KREISEL] for k in kreisel: k.name = f"Kreisel{int(k.teile_id)}" # wie im Export kreisel[2].track_ids = ["0015"] # Kreisel 0003 laut Export kreisel[4].track_ids = ["0025", "0026", "0020"] # Kreisel 0005 seps = [] for teile_id, pos in SEPARATOREN: zuordnung = {"0015": "0003-L", "0010": "0009-L"}.get(teile_id, "") seps.append(_el(teile_id, "Separator", pos, Zuordnung=zuordnung)) weichen = [_el(i, "Weiche", p) for i, p in WEICHEN] weichen[0].merkmale.update({"Kreisel A": "0009", "Kreisel B": "0001"}) beladung = _el("0020", "Beladung", (14374.25, 1186.94)) return kreisel + seps + weichen + [beladung] def _tooltip(elements: list, teile_id: str, kind: str) -> list[str]: ctx = _tooltip_context(elements) el = next(e for e in elements if e.teile_id == teile_id) return _track_node_tooltip(TrackNode(teile_id, kind, el), ctx).split("\\n") def test_separator_shows_zuordnung_kette_and_geometry_conflict() -> None: lines = _tooltip(_anlage(), "0015", "Separator") assert "Zuordnung: Kreisel3 (0003) Bahn L" in lines assert "TrackIds-Kette: Kreisel3 (0003)" in lines assert "Geometrie: liegt auf Kreisel2 (0002) Bahn R" in lines assert "! Zuordnung Kreisel 0003, liegt aber auf Kreisel 0002" in lines def test_separator_without_conflict_has_no_warning() -> None: lines = _tooltip(_anlage(), "0010", "Separator") assert "Geometrie: liegt auf Kreisel9 (0009) Bahn L" in lines assert not any(line.startswith("! Zuordnung") for line in lines) def test_weiche_shows_both_kreisel() -> None: lines = _tooltip(_anlage(), "0022", "Weiche") assert "Kreisel A: Kreisel9 (0009)" in lines assert "Kreisel B: Kreisel1 (0001)" in lines assert "Geometrie: Beruehrpunkt Kreisel 0001 / 0009" in lines def test_beladung_shows_its_kreisel() -> None: lines = _tooltip(_anlage(), "0020", "Beladung") assert "TrackIds-Kette: Kreisel5 (0005)" in lines assert lines[-1].startswith("Geometrie: naechster Kreisel Kreisel5 (0005)")