ZONOS3-Mini / tests /test_requests.py
fffiloni's picture
Deploy ZONOS3 Mini ZeroGPU integration v0.1.0
6d1acb0 verified
Raw History Blame Contribute Delete
2.19 kB
import json
import math
import pytest
from config import MAX_CHARS
from requests_schema import InputError, validate
def valid(**updates):
values = dict(text="Bonjour !", picker=json.dumps({"voice":"Gaspard","language":"fr_fr"}),
source="Preset", seed=42, randomize=False, normalize=True,
temperature=.75, top_p=.69, top_k=80, repetition_penalty=2.4,
rate=0, voice_names={"Gaspard","Savannah"}, clip_present=False, consent=False)
values.update(updates)
return validate(**values)
def test_explicit_language_is_preserved():
result = valid(picker=json.dumps({"voice":"Savannah","language":"fr_fr"}))
assert result.voice == "Savannah" and result.language == "fr_fr"
@pytest.mark.parametrize("language", ["hi", "te", "fr", "", "<script>"])
def test_no_silent_english_fallback(language):
with pytest.raises(InputError):
valid(picker={"voice":"Gaspard","language":language})
@pytest.mark.parametrize("text", ["", " \n ", "x"*(MAX_CHARS+1), None])
def test_text_rejected_before_inference(text):
with pytest.raises(InputError):
valid(text=text)
@pytest.mark.parametrize("field,value", [("temperature",math.nan),("top_k",2.5),("seed",-1),
("seed",True),("rate",31),("top_p",math.inf)])
def test_numeric_input_does_not_silently_clamp(field,value):
with pytest.raises(InputError):
valid(**{field:value})
def test_reference_mode_requires_clip_and_permission():
with pytest.raises(InputError): valid(source="Voice clip")
with pytest.raises(InputError): valid(source="Voice clip",clip_present=True)
assert valid(source="Voice clip",clip_present=True,consent=True).source == "Voice clip"
def test_fixed_seed_and_natural_rate():
result=valid()
assert result.seed==42 and result.rate is None
def test_malformed_picker():
with pytest.raises(InputError): valid(picker="{bad json")
@pytest.mark.parametrize("field", ["voice", "language"])
def test_picker_fields_require_strings(field):
value={"voice":"Gaspard", "language":"fr_fr"}
value[field]=[]
with pytest.raises(InputError): valid(picker=value)