Skip to content

Commit 825ea31

Browse files
committed
tests: add regression tests for positional-only sampler init bindings
Covers the seven bindings fixed for #2371: each gets a test confirming a keyword call that's short on positional arguments is rejected outright with TypeError. Also adds one test documenting a related but unfixed case: once every positional slot is already filled, ctypes silently ignores an extra keyword instead of raising. Positional-only marking can't close that, since there's no unfilled slot left for it to protect.
1 parent cf41a32 commit 825ea31

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

‎tests/test_llama_cpp.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import pytest
2+
3+
import llama_cpp
4+
5+
# ctypes function objects built without paramflags bind arguments
6+
# positionally only; the trailing `/` on these bindings just keeps the
7+
# type stub honest about that (#2371).
8+
9+
10+
def test_llama_sampler_init_dist_rejects_keyword_args():
11+
with pytest.raises(TypeError):
12+
llama_cpp.llama_sampler_init_dist(seed=0)
13+
14+
15+
def test_llama_sampler_init_top_k_rejects_keyword_args():
16+
with pytest.raises(TypeError):
17+
llama_cpp.llama_sampler_init_top_k(k=40)
18+
19+
20+
def test_llama_sampler_init_top_p_rejects_keyword_args():
21+
with pytest.raises(TypeError):
22+
llama_cpp.llama_sampler_init_top_p(0.9, min_keep=1)
23+
24+
25+
def test_llama_sampler_init_min_p_rejects_keyword_args():
26+
with pytest.raises(TypeError):
27+
llama_cpp.llama_sampler_init_min_p(0.1, min_keep=1)
28+
29+
30+
def test_llama_sampler_init_typical_rejects_keyword_args():
31+
with pytest.raises(TypeError):
32+
llama_cpp.llama_sampler_init_typical(1.0, min_keep=1)
33+
34+
35+
def test_llama_sampler_init_temp_rejects_keyword_args():
36+
with pytest.raises(TypeError):
37+
llama_cpp.llama_sampler_init_temp(t=0.8)
38+
39+
40+
def test_llama_sampler_init_temp_ext_rejects_keyword_args():
41+
with pytest.raises(TypeError):
42+
llama_cpp.llama_sampler_init_temp_ext(0.8, 0.0, exponent=1.0)
43+
44+
45+
def test_llama_sampler_init_top_p_silently_ignores_extra_keyword():
46+
# Known limitation, not fixed here: with all positional slots filled,
47+
# ctypes has no parameter names to match an extra keyword against, so
48+
# it's silently ignored instead of raising.
49+
sampler = llama_cpp.llama_sampler_init_top_p(0.9, 1, bogus=999)
50+
assert sampler
51+
llama_cpp.llama_sampler_free(sampler)

0 commit comments

Comments
 (0)