11from __future__ import annotations
22
3- import pytest
3+ from typing import Any
44
55from pysatl_core .families import (
66 ParametricFamily ,
77 Parametrization ,
88 ParametrizationConstraint ,
99 constraint ,
10- parametrization ,
1110)
1211from pysatl_core .types import UnivariateContinuous
1312from tests .unit .families .test_basic import TestBaseFamily
13+ from tests .utils .mocks import MockSamplingStrategy
1414
1515
1616class TestParametrizationAPI (TestBaseFamily ):
@@ -30,7 +30,7 @@ def test_constraint_decorator_marks_function(self) -> None:
3030 """Decorator should tag a function so Parametrization.validate() can discover it."""
3131
3232 @constraint ("Value must be positive" )
33- def check_positive (self ) -> bool : # noqa: ANN001 (test signature)
33+ def check_positive (self : Any ) -> bool : # noqa: ANN001 (test signature)
3434 return getattr (self , "value" , 0 ) > 0
3535
3636 # Different code versions may use single or double underscore attributes.
@@ -52,42 +52,7 @@ def test_free_function_parametrization_decorator(self) -> None:
5252 distr_type = UnivariateContinuous ,
5353 distr_parametrizations = ["base" ],
5454 distr_characteristics = {},
55- sampling_strategy = lambda n , d , ** _ : __import__ ("numpy" ).random .random ((n , 1 )), # type: ignore[assignment]
56- computation_strategy = lambda : None , # type: ignore[assignment]
57- )
58-
59- @parametrization (family = family , name = "base" )
60- class Base (Parametrization ):
61- value : float
62-
63- @constraint ("Value must be positive" )
64- def check_positive (self ) -> bool :
65- return self .value > 0
66-
67- instance = Base (value = 5.0 ) # type: ignore[call-arg]
68- assert instance .name == "base"
69- assert instance .parameters == {"value" : 5.0 }
70- assert getattr (Base , "__family__" , None ) is family
71- assert getattr (Base , "__param_name__" , None ) == "base"
72- assert hasattr (Base , "__dataclass_fields__" )
73-
74- # Validation succeeds
75- instance .validate ()
76-
77- # Validation fails
78- invalid = Base (value = - 1.0 ) # type: ignore[call-arg]
79- with pytest .raises (ValueError , match = "Constraint.*does not hold" ):
80- invalid .validate ()
81-
82- def test_method_style_parametrization_decorator (self ) -> None :
83- """family.parametrization(name=...) should behave the same as the free decorator."""
84- family = ParametricFamily (
85- name = "MethodDecoratorFamily" ,
86- distr_type = UnivariateContinuous ,
87- distr_parametrizations = ["kind" ],
88- distr_characteristics = {},
89- sampling_strategy = lambda n , d , ** _ : __import__ ("numpy" ).random .random ((n , 1 )), # type: ignore[assignment]
90- computation_strategy = lambda : None , # type: ignore[assignment]
55+ sampling_strategy = MockSamplingStrategy (),
9156 )
9257
9358 @family .parametrization (name = "kind" )
@@ -118,4 +83,4 @@ def test_get_base_parameters_uses_family_logic(self) -> None:
11883 base_from_alt = family .get_base_parameters (alt_params )
11984 assert isinstance (base_from_alt , BaseCls )
12085 # Our default factory maps Alt(value=v) → Base(value=v)
121- assert base_from_alt .value == 3.0
86+ assert base_from_alt .value == 3.0 # type: ignore[attr-defined]
0 commit comments