Extract caption text policy

This commit is contained in:
2026-06-27 11:58:18 +02:00
parent 2605fae3eb
commit f1567118b4
5 changed files with 396 additions and 189 deletions
+40
View File
@@ -27,6 +27,7 @@ if str(ROOT) not in sys.path:
import caption_naturalizer # noqa: E402
import caption_metadata_routes # noqa: E402
import caption_policy # noqa: E402
import caption_text_policy # noqa: E402
import cast_context # noqa: E402
import category_extensions # noqa: E402
import category_template_metadata # noqa: E402
@@ -2296,6 +2297,44 @@ def smoke_caption_policy() -> None:
_expect(browsing_method == "text(fallback)", "Caption browsing profile changed fallback method")
def smoke_caption_text_policy() -> None:
row = {
"primary_subject": "woman",
"age_band": "25-year-old adult",
"body_phrase": "slim figure",
"caption": f"{Trigger}, woman, 25-year-old adult, slim figure, fair skin, blonde hair, blue eyes, studio",
"formatter_hints": {"caption": ["caption policy hint"]},
}
_expect(
caption_naturalizer._body_phrase("slim", "balanced figure") == caption_text_policy.body_phrase("slim", "balanced figure"),
"Caption body phrase wrapper should delegate to caption_text_policy",
)
_expect(
caption_naturalizer._single_caption_front(row) == caption_text_policy.single_caption_front(row),
"Caption front parser wrapper should delegate to caption_text_policy",
)
_expect(
caption_naturalizer._formatter_hint_parts(row) == caption_text_policy.formatter_hint_parts(row),
"Caption formatter hint wrapper should delegate to caption_text_policy",
)
_expect(
caption_naturalizer._append_formatter_hints("Base sentence.", row)
== caption_text_policy.append_formatter_hints("Base sentence.", row),
"Caption formatter hint append wrapper should delegate to caption_text_policy",
)
_expect(
caption_naturalizer._with_trigger("A caption body", Trigger, True)
== caption_text_policy.with_trigger("A caption body", Trigger, True),
"Caption trigger wrapper should delegate to caption_text_policy",
)
deps = caption_naturalizer._caption_metadata_route_dependencies()
_expect(deps.clean_text is caption_text_policy.clean_text, "Caption route deps lost clean text policy")
_expect(deps.field_row_value is caption_text_policy.field_row_value, "Caption route deps lost field row-value policy")
_expect(deps.expression_disabled is caption_text_policy.expression_disabled, "Caption route deps lost expression policy")
_expect(deps.single_caption_front is caption_text_policy.single_caption_front, "Caption route deps lost front parser")
_expect(deps.metadata_to_prose is caption_naturalizer._metadata_to_prose, "Caption route deps lost metadata recursion callback")
def _expect_caption_route_parity(
name: str,
row: dict[str, Any],
@@ -5349,6 +5388,7 @@ SMOKE_CASES: list[tuple[str, Callable[[], None]]] = [
("formatter_input_policy", smoke_formatter_input_policy),
("formatter_cast_policy", smoke_formatter_cast_policy),
("caption_policy", smoke_caption_policy),
("caption_text_policy", smoke_caption_text_policy),
("caption_metadata_routes", smoke_caption_metadata_routes),
("sdxl_presets_policy", smoke_sdxl_presets_policy),
("sdxl_tag_policy", smoke_sdxl_tag_policy),