2525 look_up_strategy ,
2626)
2727from returns .future import Future , FutureResult
28+ from returns .interfaces .applicative import ApplicativeN
2829from returns .io import IO , IOResult , IOResultE
2930from returns .maybe import Maybe
3031from returns .pipeline import is_successful
@@ -112,6 +113,64 @@ def test_custom_readerresult_types_resolve(
112113 assert isinstance (real_result .failure (), str )
113114
114115
116+ def test_merge_settings () -> None :
117+ """Check that each part of the settings can be overridden by users."""
118+ settings1 = _Settings (
119+ settings_kwargs = {'a' : 1 , 'b' : 2 },
120+ use_init = False ,
121+ container_strategy = st .integers (),
122+ other_strategies = {int : st .integers (max_value = 10 ), str : st .text ('abc' )},
123+ )
124+ settings2 = _Settings (
125+ settings_kwargs = {'a' : 1 , 'c' : 3 },
126+ use_init = False ,
127+ container_strategy = st .integers (max_value = 20 ),
128+ other_strategies = {int : st .integers (max_value = 30 ), bool : st .booleans ()},
129+ )
130+
131+ result = settings1 | settings2
132+
133+ assert result == _Settings (
134+ settings_kwargs = {'a' : 1 , 'b' : 2 , 'c' : 3 },
135+ use_init = False ,
136+ container_strategy = st .integers (max_value = 20 ),
137+ other_strategies = {
138+ int : st .integers (max_value = 30 ),
139+ bool : st .booleans (),
140+ str : st .text ('abc' ),
141+ },
142+ )
143+
144+
145+ def test_merge_use_init () -> None :
146+ """Check that `use_init` can be set to `True` by users.
147+
148+ Note: They can't set a `True` to `False`, since we use `|` to merge.
149+ However, the default value is `False`, so this should not be a problem.
150+ """
151+ settings1 = _Settings (
152+ settings_kwargs = {},
153+ use_init = False ,
154+ container_strategy = None ,
155+ other_strategies = {},
156+ )
157+ settings2 = _Settings (
158+ settings_kwargs = {},
159+ use_init = True ,
160+ container_strategy = None ,
161+ other_strategies = {},
162+ )
163+
164+ result = settings1 | settings2
165+
166+ assert result == _Settings (
167+ settings_kwargs = {},
168+ use_init = True ,
169+ container_strategy = None ,
170+ other_strategies = {},
171+ )
172+
173+
115174_ValueType = TypeVar ('_ValueType' )
116175
117176
@@ -166,7 +225,7 @@ def test_types_to_strategies_default() -> None: # noqa: WPS210
166225
167226
168227def test_types_to_strategies_overrides () -> None : # noqa: WPS210
169- """Check that we prefer the strategies in settings ."""
228+ """Check that we allow the user to override all strategies ."""
170229 container_type = test_custom_type_applicative ._Wrapper # noqa: SLF001
171230 # NOTE: There is a type error because `Callable` is a
172231 # special form, not a type.
@@ -178,6 +237,14 @@ def test_types_to_strategies_overrides() -> None: # noqa: WPS210
178237 settings_kwargs = {},
179238 use_init = False ,
180239 container_strategy = st .builds (container_type , st .integers ()),
240+ other_strategies = {
241+ TypeVar : st .text (),
242+ callable_type : st .functions (returns = st .booleans ()),
243+ # This strategy does not get used, because we use
244+ # the given `container_strategy` for all interfaces of the
245+ # container type.
246+ ApplicativeN : st .tuples (st .integers ()),
247+ },
181248 ),
182249 )
183250
@@ -195,20 +262,13 @@ def test_types_to_strategies_overrides() -> None: # noqa: WPS210
195262 ]
196263 assert (
197264 _strategy_string (result [callable_type ], Callable [[int , str ], bool ])
198- == 'functions(like=lambda *args, **kwargs: <unknown>,'
199- ' returns=booleans(), pure=True)'
265+ == 'functions(returns=booleans())'
200266 )
201267 assert (
202268 _strategy_string (result [callable_type ], Callable [[], None ])
203- == 'functions(like=lambda: None, returns=none(), pure=True)'
204- )
205- assert (
206- _strategy_string (result [TypeVar ], _ValueType )
207- == "shared(sampled_from([<class 'NoneType'>, <class 'bool'>,"
208- " <class 'int'>, <class 'float'>, <class 'str'>, <class 'bytes'>]),"
209- " key='typevar=~_ValueType').flatmap(from_type).filter(lambda"
210- ' inner: inner == inner)'
269+ == 'functions(returns=booleans())'
211270 )
271+ assert _strategy_string (result [TypeVar ], _ValueType ) == 'text()'
212272
213273
214274def _interface_factories (type_ : type [Lawful ]) -> list [StrategyFactory | None ]:
0 commit comments