- Introduced `build_ai_placeholder_caption` function in `placeholder_registry.py` to generate AI context captions based on placeholder metadata. - Updated `resolve_placeholders` in `placeholder_resolver.py` to support modifiers for AI context, allowing for enhanced descriptions when placeholders are resolved. - Modified `get_placeholder_catalog` to include AI captions in the output, improving the metadata available for placeholders. - Adjusted `export_placeholder_values` to include AI captions in the exported data, enhancing the information provided to users. These changes improve the flexibility and functionality of the placeholder system, enabling richer context generation for dynamic content.
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
"""Tests für {{key|d}}, ai_caption und Unbekannt-Erkennung."""
|
||
from placeholder_registry import (
|
||
PlaceholderMetadata,
|
||
PlaceholderType,
|
||
OutputType,
|
||
build_ai_placeholder_caption,
|
||
)
|
||
import placeholder_resolver as pr
|
||
|
||
|
||
def test_build_ai_caption_prefers_business_meaning():
|
||
m = PlaceholderMetadata(
|
||
key="test_x",
|
||
category="Test",
|
||
description="Kurzbeschreibung",
|
||
resolver_module="m",
|
||
resolver_function="f",
|
||
semantic_contract="Lang Vertrag " * 50,
|
||
business_meaning="Kernbedeutung für die KI.",
|
||
unit="g/day",
|
||
placeholder_type=PlaceholderType.INTERPRETED,
|
||
output_type=OutputType.NUMERIC,
|
||
)
|
||
cap = build_ai_placeholder_caption(m)
|
||
assert "Kernbedeutung" in cap
|
||
|
||
|
||
def test_build_ai_caption_score_adds_scale():
|
||
m = PlaceholderMetadata(
|
||
key="test_score",
|
||
category="Test",
|
||
description="Score",
|
||
resolver_module="m",
|
||
resolver_function="f",
|
||
business_meaning="Gewichteter Gesamtscore.",
|
||
unit="Score (0-100)",
|
||
placeholder_type=PlaceholderType.SCORE,
|
||
output_type=OutputType.NUMERIC,
|
||
)
|
||
cap = build_ai_placeholder_caption(m)
|
||
assert "0–100" in cap or "0-100" in cap
|
||
assert "Gewichteter" in cap
|
||
|
||
|
||
def test_placeholder_token_regex_optional_modifier():
|
||
m0 = pr._PLACEHOLDER_TOKEN_RE.search("{{fat_avg}}")
|
||
assert m0 and m0.group(1) == "fat_avg" and m0.group(2) is None
|
||
m1 = pr._PLACEHOLDER_TOKEN_RE.search("{{fat_avg|d}}")
|
||
assert m1 and m1.group(1) == "fat_avg" and m1.group(2).strip() == "d"
|
||
m2 = pr._PLACEHOLDER_TOKEN_RE.search("{{ protein_avg | d }}")
|
||
assert m2 and m2.group(1) == "protein_avg" and m2.group(2).strip() == "d"
|
||
|
||
|
||
def test_get_unknown_placeholders_strips_modifier():
|
||
unk = pr.get_unknown_placeholders("{{not_a_real_key|d}}")
|
||
assert set(unk) == {"not_a_real_key"}
|