44import os
55import typing
66import operator
7+ from collections .abc import Sequence
8+
79from hypothesis import strategies
810
911from ascetic_ddd .faker .domain .generators .interfaces import IInputGenerator , IAnyInputGenerator
@@ -38,14 +40,14 @@ def __lt__(self, __other: typing.Any) -> bool: ...
3840def prepare_input_generator (input_generator : IAnyInputGenerator [T ] | None ) -> IInputGenerator [T ] | None :
3941 if input_generator is not None :
4042 if isinstance (input_generator , strategies .SearchStrategy ):
41- input_generator = HypothesisStrategyGenerator (input_generator )
43+ return HypothesisStrategyGenerator (input_generator )
4244 elif isinstance (input_generator , typing .Iterable ) and not isinstance (input_generator , (str , bytes )):
43- input_generator = IterableGenerator (input_generator )
45+ return IterableGenerator (input_generator )
4446 elif callable (input_generator ):
4547 # Check if already wrapped
4648 if not isinstance (input_generator , CallableGenerator ):
47- input_generator = CallableGenerator (input_generator )
48- return input_generator
49+ return CallableGenerator (input_generator )
50+ return None
4951
5052
5153class IterableGenerator (typing .Generic [T ]):
@@ -62,6 +64,20 @@ async def __call__(self, session: ISession, query: IQueryOperator | None = None,
6264 return await self .__call__ (session = session , query = query , position = position )
6365
6466
67+ class ListGenerator (typing .Generic [T ]):
68+ """For RangeDistributorAdapter
69+
70+ This will not work with AOP/FP providers/factories.
71+ """
72+
73+ def __init__ (self , values : Sequence [T ]):
74+ self ._values = values
75+
76+ async def __call__ (self , session : ISession , query : IQueryOperator | None = None , position : int = - 1 ) -> T :
77+ assert 0 <= position < len (self ._values )
78+ return self ._values [position ]
79+
80+
6581class HypothesisStrategyGenerator (typing .Generic [T ]):
6682 """
6783 Do we actually need it?
0 commit comments