Extract caption metadata route assembly
This commit is contained in:
@@ -25,6 +25,7 @@ if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
import caption_naturalizer # noqa: E402
|
||||
import caption_metadata_routes # noqa: E402
|
||||
import caption_policy # noqa: E402
|
||||
import cast_context # noqa: E402
|
||||
import category_extensions # noqa: E402
|
||||
@@ -2258,6 +2259,121 @@ def smoke_caption_policy() -> None:
|
||||
_expect(browsing_method == "text(fallback)", "Caption browsing profile changed fallback method")
|
||||
|
||||
|
||||
def _expect_caption_route_parity(
|
||||
name: str,
|
||||
row: dict[str, Any],
|
||||
route_builder: Callable[
|
||||
[caption_metadata_routes.CaptionMetadataRouteRequest, caption_metadata_routes.CaptionMetadataRouteDependencies],
|
||||
caption_metadata_routes.CaptionMetadataRoute | None,
|
||||
],
|
||||
wrapper: Callable[[dict[str, Any], str, bool], tuple[str, str] | None],
|
||||
expected_method: str,
|
||||
) -> None:
|
||||
request = caption_naturalizer._caption_metadata_route_request(row, "balanced", False)
|
||||
deps = caption_naturalizer._caption_metadata_route_dependencies()
|
||||
typed_route = route_builder(request, deps)
|
||||
legacy_route = wrapper(row, "balanced", False)
|
||||
_expect(typed_route is not None, f"{name} typed caption metadata route did not match")
|
||||
assert typed_route is not None
|
||||
_expect(
|
||||
typed_route.as_tuple() == legacy_route,
|
||||
f"{name} typed caption metadata route should match legacy wrapper output",
|
||||
)
|
||||
_expect(typed_route.method == expected_method, f"{name} caption route method changed")
|
||||
_expect_text(f"{name}.caption_route", typed_route.prose, 20)
|
||||
|
||||
|
||||
def smoke_caption_metadata_routes() -> None:
|
||||
single = {
|
||||
"primary_subject": "woman",
|
||||
"age_band": "25-year-old adult",
|
||||
"body_phrase": "slim figure",
|
||||
"skin": "fair skin",
|
||||
"hair": "long blonde hair",
|
||||
"eyes": "blue eyes",
|
||||
"item": "silk dress",
|
||||
"pose": "standing beside a window",
|
||||
"scene_text": "quiet studio with warm daylight",
|
||||
"expression": "soft smile",
|
||||
"composition": "vertical centered portrait",
|
||||
}
|
||||
_expect_caption_route_parity(
|
||||
"caption_route_single",
|
||||
single,
|
||||
caption_metadata_routes.single_from_row_result,
|
||||
caption_naturalizer._single_from_row,
|
||||
"metadata(single)",
|
||||
)
|
||||
|
||||
couple = {
|
||||
"primary_subject": "a woman and a man",
|
||||
"subject_phrase": "woman and man",
|
||||
"age": "25-year-old adult and 40-year-old adult",
|
||||
"body": "slim and average builds",
|
||||
"item": "Partner A wears black dress; Partner B wears dark shirt",
|
||||
"pose": "standing close together",
|
||||
"scene_text": "private lounge with soft lamps",
|
||||
"expression": "shared confident gaze",
|
||||
"composition": "two-person editorial frame",
|
||||
}
|
||||
_expect_caption_route_parity(
|
||||
"caption_route_couple",
|
||||
couple,
|
||||
caption_metadata_routes.couple_from_row_result,
|
||||
caption_naturalizer._couple_from_row,
|
||||
"metadata(couple)",
|
||||
)
|
||||
|
||||
configured = _fixture_hardcore_row()
|
||||
_expect_caption_route_parity(
|
||||
"caption_route_configured_cast",
|
||||
configured,
|
||||
caption_metadata_routes.configured_cast_from_row_result,
|
||||
caption_naturalizer._configured_cast_from_row,
|
||||
"metadata(configured_cast)",
|
||||
)
|
||||
|
||||
group = {
|
||||
"primary_subject": "group scene",
|
||||
"subject_phrase": "three adult friends",
|
||||
"age": "late 20s adults",
|
||||
"item": "coordinated evening outfits",
|
||||
"scene_text": "rooftop lounge with city lights",
|
||||
"expression": "relaxed shared smiles",
|
||||
"composition": "wide group frame",
|
||||
}
|
||||
_expect_caption_route_parity(
|
||||
"caption_route_group",
|
||||
group,
|
||||
caption_metadata_routes.group_or_layout_from_row_result,
|
||||
caption_naturalizer._group_or_layout_from_row,
|
||||
"metadata(group_layout)",
|
||||
)
|
||||
|
||||
pair = pb.build_insta_of_pair(
|
||||
row_number=1,
|
||||
start_index=1,
|
||||
seed=3511,
|
||||
ethnicity="any",
|
||||
figure="random",
|
||||
no_plus_women=False,
|
||||
no_black=False,
|
||||
trigger=Trigger,
|
||||
prepend_trigger_to_prompt=True,
|
||||
options_json=_insta_options(hardcore_clothing_continuity="partially_removed"),
|
||||
character_cast=_character_cast(),
|
||||
hardcore_position_config=_action_filter("penetration_only"),
|
||||
)
|
||||
_expect_pair(pair, "caption_route_pair")
|
||||
_expect_caption_route_parity(
|
||||
"caption_route_insta_pair",
|
||||
pair,
|
||||
caption_metadata_routes.insta_of_pair_from_row_result,
|
||||
caption_naturalizer._insta_of_pair_from_row,
|
||||
"metadata(insta_of_pair)",
|
||||
)
|
||||
|
||||
|
||||
def smoke_sdxl_presets_policy() -> None:
|
||||
_expect(
|
||||
sdxl_formatter.SDXL_STYLE_PRESETS is sdxl_presets.SDXL_STYLE_PRESETS,
|
||||
@@ -5151,6 +5267,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_metadata_routes", smoke_caption_metadata_routes),
|
||||
("sdxl_presets_policy", smoke_sdxl_presets_policy),
|
||||
("sdxl_tag_routes", smoke_sdxl_tag_routes),
|
||||
("hardcore_position_config_policy", smoke_hardcore_position_config_policy),
|
||||
|
||||
Reference in New Issue
Block a user