format: auto-format code [skip ci]

This commit is contained in:
github-actions[bot]
2026-05-17 16:40:09 +00:00
parent 592b6858eb
commit e063911178
4 changed files with 37 additions and 76 deletions
+1 -3
View File
@@ -1456,9 +1456,7 @@ def style_sweep( # noqa: PLR0915
# Template is required for generation, but optional when --list is paired # Template is required for generation, but optional when --list is paired
# with an explicit --styles source. # with an explicit --styles source.
if template is None and not (list_styles and styles is not None): if template is None and not (list_styles and styles is not None):
console.print( console.print("[red]--template is required (or use --list with --styles to inspect a styles file)[/red]")
"[red]--template is required (or use --list with --styles to inspect a styles file)[/red]"
)
raise typer.Exit(1) raise typer.Exit(1)
# ---- Load template (if provided) ---- # ---- Load template (if provided) ----
+21 -38
View File
@@ -130,9 +130,7 @@ def test_limit(tmp_path: Path, calls: list[dict[str, Any]]) -> None:
out_dir = tmp_path / "out" out_dir = tmp_path / "out"
styles_file = _write_styles_file( styles_file = _write_styles_file(
tmp_path, tmp_path,
[ [{"slug": f"{i:02d}-style", "suffix": f"style {i}"} for i in range(1, 6)],
{"slug": f"{i:02d}-style", "suffix": f"style {i}"} for i in range(1, 6)
],
) )
tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file)) tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file))
@@ -313,9 +311,7 @@ def test_cli_output_dir_overrides_template(tmp_path: Path, calls: list[dict[str,
styles_file = _write_styles_file(tmp_path, [{"slug": "x", "suffix": "X"}]) styles_file = _write_styles_file(tmp_path, [{"slug": "x", "suffix": "X"}])
tpl = _write_template(tmp_path, output_dir=tpl_out, styles=str(styles_file)) tpl = _write_template(tmp_path, output_dir=tpl_out, styles=str(styles_file))
result = runner.invoke( result = runner.invoke(app, ["style-sweep", "--template", str(tpl), "--output-dir", str(cli_out)])
app, ["style-sweep", "--template", str(tpl), "--output-dir", str(cli_out)]
)
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
assert calls[0]["output"] == cli_out / "x.png" assert calls[0]["output"] == cli_out / "x.png"
@@ -329,9 +325,7 @@ def test_remote_override(tmp_path: Path, calls: list[dict[str, Any]]) -> None:
styles_file = _write_styles_file(tmp_path, [{"slug": "x", "suffix": "X"}]) styles_file = _write_styles_file(tmp_path, [{"slug": "x", "suffix": "X"}])
tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file)) tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file))
result = runner.invoke( result = runner.invoke(app, ["style-sweep", "--template", str(tpl), "--remote", "junkpile"])
app, ["style-sweep", "--template", str(tpl), "--remote", "junkpile"]
)
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
assert calls[0]["remote"] == "junkpile" assert calls[0]["remote"] == "junkpile"
@@ -346,9 +340,7 @@ def test_list_flag_prints_slugs(tmp_path: Path, calls: list[dict[str, Any]]) ->
"""--list prints all slugs and does not call generate.""" """--list prints all slugs and does not call generate."""
out_dir = tmp_path / "out" out_dir = tmp_path / "out"
slugs = [f"{i:02d}-style" for i in range(1, 5)] slugs = [f"{i:02d}-style" for i in range(1, 5)]
styles_file = _write_styles_file( styles_file = _write_styles_file(tmp_path, [{"slug": s, "suffix": f"suffix for {s}"} for s in slugs])
tmp_path, [{"slug": s, "suffix": f"suffix for {s}"} for s in slugs]
)
tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file)) tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file))
result = runner.invoke(app, ["style-sweep", "--template", str(tpl), "--list"]) result = runner.invoke(app, ["style-sweep", "--template", str(tpl), "--list"])
@@ -366,14 +358,10 @@ def test_list_flag_prints_slugs(tmp_path: Path, calls: list[dict[str, Any]]) ->
def test_list_with_limit(tmp_path: Path, calls: list[dict[str, Any]]) -> None: def test_list_with_limit(tmp_path: Path, calls: list[dict[str, Any]]) -> None:
"""--list --limit N restricts the table to the first N entries.""" """--list --limit N restricts the table to the first N entries."""
out_dir = tmp_path / "out" out_dir = tmp_path / "out"
styles_file = _write_styles_file( styles_file = _write_styles_file(tmp_path, [{"slug": f"{i:02d}-x", "suffix": f"s{i}"} for i in range(1, 6)])
tmp_path, [{"slug": f"{i:02d}-x", "suffix": f"s{i}"} for i in range(1, 6)]
)
tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file)) tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file))
result = runner.invoke( result = runner.invoke(app, ["style-sweep", "--template", str(tpl), "--list", "--limit", "2"])
app, ["style-sweep", "--template", str(tpl), "--list", "--limit", "2"]
)
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
assert "01-x" in result.output assert "01-x" in result.output
@@ -392,9 +380,7 @@ def test_list_without_template(tmp_path: Path, calls: list[dict[str, Any]]) -> N
], ],
) )
result = runner.invoke( result = runner.invoke(app, ["style-sweep", "--styles", str(styles_file), "--list"])
app, ["style-sweep", "--styles", str(styles_file), "--list"]
)
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
assert "alpha" in result.output assert "alpha" in result.output
@@ -405,13 +391,9 @@ def test_list_without_template(tmp_path: Path, calls: list[dict[str, Any]]) -> N
def test_list_long_suffix_truncated(tmp_path: Path) -> None: def test_list_long_suffix_truncated(tmp_path: Path) -> None:
"""Long suffixes are truncated with an ellipsis.""" """Long suffixes are truncated with an ellipsis."""
long_suffix = "very long " * 20 # ~200 chars long_suffix = "very long " * 20 # ~200 chars
styles_file = _write_styles_file( styles_file = _write_styles_file(tmp_path, [{"slug": "long", "suffix": long_suffix}])
tmp_path, [{"slug": "long", "suffix": long_suffix}]
)
result = runner.invoke( result = runner.invoke(app, ["style-sweep", "--styles", str(styles_file), "--list"])
app, ["style-sweep", "--styles", str(styles_file), "--list"]
)
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
assert "long" in result.output assert "long" in result.output
@@ -438,9 +420,7 @@ def test_style_filter_single(tmp_path: Path, calls: list[dict[str, Any]]) -> Non
) )
tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file)) tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file))
result = runner.invoke( result = runner.invoke(app, ["style-sweep", "--template", str(tpl), "--style", "02-bar"])
app, ["style-sweep", "--template", str(tpl), "--style", "02-bar"]
)
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
assert len(calls) == 1 assert len(calls) == 1
@@ -467,9 +447,12 @@ def test_style_filter_multiple(tmp_path: Path, calls: list[dict[str, Any]]) -> N
app, app,
[ [
"style-sweep", "style-sweep",
"--template", str(tpl), "--template",
"-S", "03-c", str(tpl),
"-S", "01-a", "-S",
"03-c",
"-S",
"01-a",
], ],
) )
@@ -491,9 +474,7 @@ def test_style_filter_unknown_slug(tmp_path: Path, calls: list[dict[str, Any]])
) )
tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file)) tpl = _write_template(tmp_path, output_dir=out_dir, styles=str(styles_file))
result = runner.invoke( result = runner.invoke(app, ["style-sweep", "--template", str(tpl), "--style", "99-nope"])
app, ["style-sweep", "--template", str(tpl), "--style", "99-nope"]
)
assert result.exit_code == 1, result.output assert result.exit_code == 1, result.output
assert "99-nope" in result.output assert "99-nope" in result.output
@@ -519,9 +500,11 @@ def test_style_filter_with_list(tmp_path: Path, calls: list[dict[str, Any]]) ->
app, app,
[ [
"style-sweep", "style-sweep",
"--styles", str(styles_file), "--styles",
str(styles_file),
"--list", "--list",
"--style", "02-bar", "--style",
"02-bar",
], ],
) )
+9 -29
View File
@@ -358,24 +358,16 @@ class TestModelFamilyDetection:
"""fcFluxPony*.safetensors → flux_unet (intercepts flux + fluxpony).""" """fcFluxPony*.safetensors → flux_unet (intercepts flux + fluxpony)."""
from tensors.config import detect_model_family from tensors.config import detect_model_family
assert ( assert detect_model_family("fcFluxPonyPerfectBase_fcFluxPerfectBase.safetensors") == "flux_unet"
detect_model_family("fcFluxPonyPerfectBase_fcFluxPerfectBase.safetensors")
== "flux_unet"
)
def test_detect_flux_unet_overrides_base_model(self) -> None: def test_detect_flux_unet_overrides_base_model(self) -> None:
"""Filename UNet-only pattern wins over a (likely wrong) CivitAI base_model tag.""" """Filename UNet-only pattern wins over a (likely wrong) CivitAI base_model tag."""
from tensors.config import detect_model_family from tensors.config import detect_model_family
# cyberrealisticFlux: filename pattern wins over wrong "Pony" tag → flux_unet. # cyberrealisticFlux: filename pattern wins over wrong "Pony" tag → flux_unet.
assert ( assert detect_model_family("cyberrealisticFlux_v25.safetensors", "Pony") == "flux_unet"
detect_model_family("cyberrealisticFlux_v25.safetensors", "Pony") == "flux_unet"
)
# getphat: filename pattern wins over wrong "SDXL 1.0" tag → flux_unet. # getphat: filename pattern wins over wrong "SDXL 1.0" tag → flux_unet.
assert ( assert detect_model_family("getphatFLUXReality_v11.safetensors", "SDXL 1.0") == "flux_unet"
detect_model_family("getphatFLUXReality_v11.safetensors", "SDXL 1.0")
== "flux_unet"
)
def test_flux_unet_family_defaults_has_external_clip(self) -> None: def test_flux_unet_family_defaults_has_external_clip(self) -> None:
"""flux_unet preset advertises external_clip + clip filenames.""" """flux_unet preset advertises external_clip + clip filenames."""
@@ -750,9 +742,7 @@ class TestFluxUnetWorkflowBuilder:
"""flux_unet locks KSampler.cfg to 1.0 and exposes the FluxGuidance dial.""" """flux_unet locks KSampler.cfg to 1.0 and exposes the FluxGuidance dial."""
from tensors.comfyui import _build_workflow from tensors.comfyui import _build_workflow
wf = _build_workflow( wf = _build_workflow(prompt="a cat", model="getphatFLUXReality_v11.safetensors", cfg=7.5)
prompt="a cat", model="getphatFLUXReality_v11.safetensors", cfg=7.5
)
assert wf["160"]["inputs"]["cfg"] == 1.0 assert wf["160"]["inputs"]["cfg"] == 1.0
# The caller's cfg=7.5 should re-route to FluxGuidance (same precedence as plain flux) # The caller's cfg=7.5 should re-route to FluxGuidance (same precedence as plain flux)
assert wf["140"]["inputs"]["guidance"] == 7.5 assert wf["140"]["inputs"]["guidance"] == 7.5
@@ -1178,9 +1168,7 @@ class TestValidateModelAvailable:
}, },
) )
with pytest.raises(typer.Exit) as exc: with pytest.raises(typer.Exit) as exc:
cli_module._validate_model_available( cli_module._validate_model_available("fluxRealVision_v99.safetensors", family="flux", lora=None)
"fluxRealVision_v99.safetensors", family="flux", lora=None
)
assert exc.value.exit_code == 1 assert exc.value.exit_code == 1
def test_unknown_model_in_diffusion_models_bucket(self, monkeypatch: pytest.MonkeyPatch) -> None: def test_unknown_model_in_diffusion_models_bucket(self, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -1198,9 +1186,7 @@ class TestValidateModelAvailable:
}, },
) )
with pytest.raises(typer.Exit): with pytest.raises(typer.Exit):
cli_module._validate_model_available( cli_module._validate_model_available("getphat_v99.safetensors", family="flux_unet", lora=None)
"getphat_v99.safetensors", family="flux_unet", lora=None
)
def test_flux2_klein_uses_diffusion_models_bucket(self, monkeypatch: pytest.MonkeyPatch) -> None: def test_flux2_klein_uses_diffusion_models_bucket(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""flux2_klein family also routes to diffusion_models/.""" """flux2_klein family also routes to diffusion_models/."""
@@ -1215,9 +1201,7 @@ class TestValidateModelAvailable:
}, },
) )
# Should NOT raise — file is present in diffusion_models/. # Should NOT raise — file is present in diffusion_models/.
cli_module._validate_model_available( cli_module._validate_model_available("lust_v10.safetensors", family="flux2_klein", lora=None)
"lust_v10.safetensors", family="flux2_klein", lora=None
)
def test_present_model_passes_silently(self, monkeypatch: pytest.MonkeyPatch) -> None: def test_present_model_passes_silently(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Happy path — model present, no exception.""" """Happy path — model present, no exception."""
@@ -1248,9 +1232,7 @@ class TestValidateModelAvailable:
}, },
) )
with pytest.raises(typer.Exit): with pytest.raises(typer.Exit):
cli_module._validate_model_available( cli_module._validate_model_available("model.safetensors", family="flux", lora="ghost_lora.safetensors")
"model.safetensors", family="flux", lora="ghost_lora.safetensors"
)
def test_network_failure_is_non_fatal(self, monkeypatch: pytest.MonkeyPatch) -> None: def test_network_failure_is_non_fatal(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""If get_loaded_models() raises, validation falls through silently.""" """If get_loaded_models() raises, validation falls through silently."""
@@ -1278,9 +1260,7 @@ class TestValidateModelAvailable:
}, },
) )
with pytest.raises(typer.Exit): with pytest.raises(typer.Exit):
cli_module._validate_model_available( cli_module._validate_model_available("new_unet_model.safetensors", family="flux_unet", lora=None)
"new_unet_model.safetensors", family="flux_unet", lora=None
)
def test_get_loaded_models_includes_diffusion_models_bucket(self) -> None: def test_get_loaded_models_includes_diffusion_models_bucket(self) -> None:
"""The Comfy model-listing helper exposes the UNETLoader bucket. """The Comfy model-listing helper exposes the UNETLoader bucket.