summaryrefslogtreecommitdiff
path: root/tests/test_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_config.py')
-rw-r--r--tests/test_config.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index b0dfac0..5d339f8 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -269,3 +269,49 @@ def test_prompt_accepts_only_positive(tmp_path: Path) -> None:
config = load_config(path)
assert config.prompt.positive == "masterpiece"
assert config.prompt.negative == ""
+
+
+def test_generation_defaults_clip_skip_and_pad_last_block(tmp_path: Path) -> None:
+ path = tmp_path / "config.toml"
+ path.write_text(
+ f'[model]\nroot = "{tmp_path.as_posix()}"\ncheckpoint = "base.safetensors"\n',
+ encoding="utf-8",
+ )
+ config = load_config(path, validate_paths=False)
+ assert config.generation.clip_skip == 0
+ assert config.generation.pad_last_block is False
+
+
+def test_generation_reads_clip_skip_and_pad_last_block(tmp_path: Path) -> None:
+ path = tmp_path / "config.toml"
+ path.write_text(
+ f'[model]\nroot = "{tmp_path.as_posix()}"\ncheckpoint = "base.safetensors"\n'
+ "[generation]\nclip_skip = 2\npad_last_block = true\n",
+ encoding="utf-8",
+ )
+ config = load_config(path, validate_paths=False)
+ assert config.generation.clip_skip == 2
+ assert config.generation.pad_last_block is True
+
+
+@pytest.mark.parametrize(
+ "clip_skip, message",
+ [
+ (-1, "clip_skip"),
+ (13, "clip_skip"),
+ (2.5, "clip_skip"),
+ (True, "clip_skip"),
+ ],
+)
+def test_rejects_invalid_clip_skip(
+ tmp_path: Path, clip_skip: float | int | bool, message: str
+) -> None:
+ path = tmp_path / "config.toml"
+ literal = "true" if isinstance(clip_skip, bool) else str(clip_skip)
+ path.write_text(
+ f'[model]\nroot = "{tmp_path.as_posix()}"\ncheckpoint = "base.safetensors"\n'
+ f"[generation]\nclip_skip = {literal}\n",
+ encoding="utf-8",
+ )
+ with pytest.raises(ConfigError, match=message):
+ load_config(path, validate_paths=False)