Доработка управления моделями
This commit is contained in:
+40
-25
@@ -1,15 +1,14 @@
|
||||
import pytest
|
||||
|
||||
from app.config import DEFAULT_MAPPING
|
||||
from app.config import Settings
|
||||
from app.errors import InvalidRequest
|
||||
from app.injector import build_workflow, new_seed, parse_size
|
||||
from app.templates import load_all
|
||||
from app.config import Settings
|
||||
from app.templates import load_registry
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def templates():
|
||||
return load_all(Settings(_env_file=None))
|
||||
def registry():
|
||||
return load_registry(Settings(_env_file=None))
|
||||
|
||||
|
||||
def test_parse_size():
|
||||
@@ -33,41 +32,57 @@ def test_seed_fixed_and_range():
|
||||
new_seed(-1)
|
||||
|
||||
|
||||
def test_create_injection(templates):
|
||||
create, _ = templates
|
||||
mapping = DEFAULT_MAPPING["create"]
|
||||
graph = build_workflow(create, mapping, prompt="a cat", seed=77, size="832x1216")
|
||||
def test_create_injection_and_template_untouched(registry):
|
||||
create = registry["z-image-turbo"].graph
|
||||
graph = build_workflow(create, {"prompt": "a cat", "seed": 77, "negative": "", "width": 832, "height": 1216})
|
||||
assert graph["83:27"]["inputs"]["text"] == "a cat"
|
||||
assert graph["83:13"]["inputs"]["width"] == 832
|
||||
assert graph["83:13"]["inputs"]["height"] == 1216
|
||||
assert graph["83:3"]["inputs"]["seed"] == 77
|
||||
# template untouched
|
||||
assert create["83:27"]["inputs"]["text"] == "\n"
|
||||
assert create["83:13"]["inputs"]["width"] == 1280
|
||||
# template still holds placeholders (deep copy, no mutation)
|
||||
assert create["83:27"]["inputs"]["text"] == "{prompt}"
|
||||
assert create["83:13"]["inputs"]["width"] == "{width}"
|
||||
assert create["83:3"]["inputs"]["seed"] == "{seed}"
|
||||
|
||||
|
||||
def test_edit_injection(templates):
|
||||
_, edit = templates
|
||||
mapping = DEFAULT_MAPPING["edit"]
|
||||
graph = build_workflow(edit, mapping, prompt="make it night", seed=5, image_name="adapter_x.png")
|
||||
def test_injection_is_typed(registry):
|
||||
graph = build_workflow(registry["z-image-turbo"].graph, {"prompt": "x", "seed": 7, "negative": "", "width": 64, "height": 128})
|
||||
assert isinstance(graph["83:3"]["inputs"]["seed"], int) # numeric token -> int, not "{seed}"
|
||||
assert isinstance(graph["83:13"]["inputs"]["width"], int)
|
||||
assert isinstance(graph["83:27"]["inputs"]["text"], str)
|
||||
|
||||
|
||||
def test_embedded_token_is_string_interpolated():
|
||||
graph = {"1": {"class_type": "X", "inputs": {"text": "prefix {prompt} suffix"}}}
|
||||
out = build_workflow(graph, {"prompt": "hi"})
|
||||
assert out["1"]["inputs"]["text"] == "prefix hi suffix"
|
||||
|
||||
|
||||
def test_edit_injection(registry):
|
||||
edit = registry["qwen-image-edit"].graph
|
||||
graph = build_workflow(edit, {"prompt": "make it night", "seed": 5, "negative": "", "image": "adapter_x.png"})
|
||||
assert graph["115:111"]["inputs"]["prompt"] == "make it night"
|
||||
assert graph["115:110"]["inputs"]["prompt"] == ""
|
||||
assert graph["78"]["inputs"]["image"] == "adapter_x.png"
|
||||
assert graph["115:3"]["inputs"]["seed"] == 5
|
||||
|
||||
|
||||
def test_edit_seed_varies_per_call(templates):
|
||||
_, edit = templates
|
||||
mapping = DEFAULT_MAPPING["edit"]
|
||||
def test_edit_seed_varies_per_call(registry):
|
||||
edit = registry["qwen-image-edit"].graph
|
||||
seeds = set()
|
||||
for _ in range(3):
|
||||
g = build_workflow(edit, mapping, prompt="p", seed=new_seed(None))
|
||||
g = build_workflow(edit, {"prompt": "p", "seed": new_seed(None), "negative": "", "image": "a.png"})
|
||||
seeds.add(g["115:3"]["inputs"]["seed"])
|
||||
assert len(seeds) == 3
|
||||
|
||||
|
||||
def test_unknown_mapping_node_raises(templates):
|
||||
create, _ = templates
|
||||
bad_mapping = {"prompt": {"node": "999", "field": "text"}}
|
||||
with pytest.raises(InvalidRequest, match="999"):
|
||||
build_workflow(create, bad_mapping, prompt="p", seed=1)
|
||||
def test_unrecognized_token_rejected():
|
||||
graph = {"1": {"class_type": "X", "inputs": {"text": "{foo}"}}}
|
||||
with pytest.raises(InvalidRequest, match="unrecognized token"):
|
||||
build_workflow(graph, {"prompt": "p"})
|
||||
|
||||
|
||||
def test_unfilled_token_rejected():
|
||||
graph = {"1": {"class_type": "X", "inputs": {"seed": "{seed}"}}}
|
||||
with pytest.raises(InvalidRequest, match="no value supplied"):
|
||||
build_workflow(graph, {"prompt": "p"})
|
||||
|
||||
Reference in New Issue
Block a user