more Parameters fixup

This commit is contained in:
Benoît Sierro
2023-07-27 10:34:54 +02:00
parent d72409f339
commit d08c62f569
5 changed files with 144 additions and 79 deletions

View File

@@ -0,0 +1,21 @@
import numpy as np
import pytest
from scgenerator.parameter import type_checker
def test_type_checker():
numero = type_checker(int)
@numero
def natural_number(name, n):
if n < 0:
raise ValueError(f"{name!r} must be positive")
with pytest.raises(TypeError, match="of type"):
numero("a", np.arange(45))
with pytest.raises(ValueError, match="positive"):
natural_number("b", -1)
with pytest.raises(TypeError, match="of type"):
natural_number("c", 1.0)
natural_number("d", 1)