Extract formatter input parsing policy
This commit is contained in:
@@ -29,6 +29,7 @@ import character_profile # noqa: E402
|
||||
import category_cast_config # noqa: E402
|
||||
import category_library # noqa: E402
|
||||
import filter_config # noqa: E402
|
||||
import formatter_input # noqa: E402
|
||||
import hardcore_position_config # noqa: E402
|
||||
import __init__ as sxcp_nodes # noqa: E402
|
||||
import generation_profile_config # noqa: E402
|
||||
@@ -847,6 +848,57 @@ def smoke_row_normalization_policy() -> None:
|
||||
_expect_no_duplicate_comma_items("row_normalization.pair.hard_row_negative", pair["hardcore_row"].get("negative_prompt"))
|
||||
|
||||
|
||||
def smoke_formatter_input_policy() -> None:
|
||||
source_row = {
|
||||
"prompt": "A simple adult portrait. Setting: quiet studio. Pose: standing calmly. Avoid: low quality.",
|
||||
"caption": "adult portrait, quiet studio",
|
||||
"negative_prompt": "low quality",
|
||||
"subject_type": "woman",
|
||||
"primary_subject": "woman",
|
||||
"age": "25-year-old adult",
|
||||
"body_phrase": "average figure",
|
||||
"skin": "warm skin",
|
||||
"hair": "dark hair",
|
||||
"eyes": "brown eyes",
|
||||
"item": "black dress",
|
||||
"scene_text": "quiet studio",
|
||||
"pose": "standing calmly",
|
||||
"composition": "centered portrait",
|
||||
"trigger": Trigger,
|
||||
}
|
||||
source_json = _json(source_row)
|
||||
|
||||
row, method = formatter_input.row_from_inputs(source_json, "", "auto")
|
||||
_expect(method == "source_json", "Formatter input parser should read source JSON when metadata is empty")
|
||||
_expect(row == source_row, "Formatter input parser changed parsed JSON row")
|
||||
_expect(formatter_input.split_avoid("Prompt body. Avoid: blur, watermark") == ("Prompt body", "blur, watermark"), "Avoid split changed")
|
||||
_expect(
|
||||
formatter_input.prompt_field(source_row["prompt"], "Setting") == "quiet studio",
|
||||
"Prompt field extraction changed",
|
||||
)
|
||||
_expect(
|
||||
formatter_input.row_value({"prompt": source_row["prompt"]}, "scene_text", ("Setting",)) == "quiet studio",
|
||||
"Row value prompt fallback changed",
|
||||
)
|
||||
|
||||
_expect(krea_formatter._clean("a b , c") == formatter_input.clean_text("a b , c"), "Krea clean helper is not delegated")
|
||||
_expect(sdxl_formatter._clean("a b , c") == formatter_input.clean_text("a b , c"), "SDXL clean helper is not delegated")
|
||||
_expect(caption_naturalizer._clean_text("a b , c") == formatter_input.clean_text("a b , c"), "Caption clean helper is not delegated")
|
||||
_expect(krea_formatter._strip_trigger(f"{Trigger}, prompt text", False) == "prompt text", "Krea trigger stripping changed")
|
||||
_expect(sdxl_formatter._strip_trigger(f"{SdxlTrigger}, prompt text", False) == "prompt text", "SDXL trigger stripping changed")
|
||||
_expect(caption_naturalizer._remove_trigger(Trigger, Trigger) == "", "Caption exact-trigger removal changed")
|
||||
|
||||
krea = krea_formatter.format_krea2_prompt(source_json, input_hint="auto")
|
||||
sdxl = sdxl_formatter.format_sdxl_prompt(source_json, input_hint="auto", trigger=SdxlTrigger, prepend_trigger=True)
|
||||
caption, caption_method = caption_naturalizer.naturalize_caption(source_json, input_hint="auto", trigger=Trigger)
|
||||
_expect(krea.get("method", "").startswith("source_json:krea2("), "Krea formatter did not use shared source JSON parsing")
|
||||
_expect(sdxl.get("method", "").startswith("source_json:sdxl("), "SDXL formatter did not use shared source JSON parsing")
|
||||
_expect(caption_method.startswith("source_json:metadata("), "Caption naturalizer did not use shared source JSON parsing")
|
||||
_expect_text("formatter_input.krea_prompt", krea.get("krea_prompt"), 20)
|
||||
_expect_text("formatter_input.sdxl_prompt", sdxl.get("sdxl_prompt"), 20)
|
||||
_expect_text("formatter_input.caption", caption, 20)
|
||||
|
||||
|
||||
def smoke_hardcore_position_config_policy() -> None:
|
||||
_expect(
|
||||
pb.HARDCORE_POSITION_FAMILY_CHOICES is hardcore_position_config.HARDCORE_POSITION_FAMILY_CHOICES,
|
||||
@@ -2818,6 +2870,7 @@ SMOKE_CASES: list[tuple[str, Callable[[], None]]] = [
|
||||
("character_config_policy", smoke_character_config_policy),
|
||||
("character_profile_policy", smoke_character_profile_policy),
|
||||
("row_normalization_policy", smoke_row_normalization_policy),
|
||||
("formatter_input_policy", smoke_formatter_input_policy),
|
||||
("hardcore_position_config_policy", smoke_hardcore_position_config_policy),
|
||||
("category_library_route", smoke_category_library_route),
|
||||
("hardcore_category_routes", smoke_hardcore_category_routes),
|
||||
|
||||
Reference in New Issue
Block a user