Skip to content

Commit e093247

Browse files
committed
hypothesis: rearrange functions in calling order.
This package seems to put callers above callees.
1 parent 2957d5e commit e093247

1 file changed

Lines changed: 38 additions & 38 deletions

File tree

returns/contrib/hypothesis/laws.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,40 @@ def _clean_caches() -> None:
163163
st.from_type.__clear_cache() # type: ignore[attr-defined] # noqa: SLF001
164164

165165

166-
def _strategy_for_container(
166+
def _create_law_test_case(
167167
container_type: type[Lawful],
168+
interface: type[Lawful],
169+
law: Law,
170+
*,
168171
settings: _Settings,
169-
) -> StrategyFactory:
170-
return (
171-
strategy_from_container(container_type, use_init=settings.use_init)
172-
if settings.container_strategy is None
173-
else settings.container_strategy
172+
) -> None:
173+
test_function = given(st.data())(
174+
hypothesis_settings(**settings.settings_kwargs)(
175+
_run_law(container_type, law, settings=settings),
176+
),
177+
)
178+
179+
called_from = inspect.stack()[2]
180+
module = inspect.getmodule(called_from[0])
181+
182+
template = 'test_{container}_{interface}_{name}'
183+
test_function.__name__ = template.format( # noqa: WPS125
184+
container=container_type.__qualname__.lower(),
185+
interface=interface.__qualname__.lower(),
186+
name=law.name,
187+
)
188+
189+
setattr(
190+
module,
191+
test_function.__name__,
192+
pytest.mark.filterwarnings(
193+
# We ignore multiple warnings about unused coroutines and stuff:
194+
'ignore::pytest.PytestUnraisableExceptionWarning',
195+
)(
196+
# We mark all tests with `returns_lawful` marker,
197+
# so users can easily skip them if needed.
198+
pytest.mark.returns_lawful(test_function),
199+
),
174200
)
175201

176202

@@ -207,38 +233,12 @@ def _enter_hypothesis_context(
207233
)
208234

209235

210-
def _create_law_test_case(
236+
def _strategy_for_container(
211237
container_type: type[Lawful],
212-
interface: type[Lawful],
213-
law: Law,
214-
*,
215238
settings: _Settings,
216-
) -> None:
217-
test_function = given(st.data())(
218-
hypothesis_settings(**settings.settings_kwargs)(
219-
_run_law(container_type, law, settings=settings),
220-
),
221-
)
222-
223-
called_from = inspect.stack()[2]
224-
module = inspect.getmodule(called_from[0])
225-
226-
template = 'test_{container}_{interface}_{name}'
227-
test_function.__name__ = template.format( # noqa: WPS125
228-
container=container_type.__qualname__.lower(),
229-
interface=interface.__qualname__.lower(),
230-
name=law.name,
231-
)
232-
233-
setattr(
234-
module,
235-
test_function.__name__,
236-
pytest.mark.filterwarnings(
237-
# We ignore multiple warnings about unused coroutines and stuff:
238-
'ignore::pytest.PytestUnraisableExceptionWarning',
239-
)(
240-
# We mark all tests with `returns_lawful` marker,
241-
# so users can easily skip them if needed.
242-
pytest.mark.returns_lawful(test_function),
243-
),
239+
) -> StrategyFactory:
240+
return (
241+
strategy_from_container(container_type, use_init=settings.use_init)
242+
if settings.container_strategy is None
243+
else settings.container_strategy
244244
)

0 commit comments

Comments
 (0)