Navigation Menu

Skip to content

Commit

Permalink
chore: Remove deprecated _accepts_context internal function
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Jul 3, 2020
1 parent d204391 commit 7396949
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Expand Up @@ -20,6 +20,7 @@ Removed
~~~~~~~

- Deprecated ``skip_validation`` argument to ``HookDispatcher.apply``.
- Deprecated ``_accepts_context`` internal function.

`2.0.0`_ - 2020-07-01
---------------------
Expand Down
14 changes: 1 addition & 13 deletions src/schemathesis/_hypothesis.py
@@ -1,6 +1,5 @@
"""Provide strategies for given endpoint(s) definition."""
import asyncio
import inspect
import re
from base64 import b64encode
from functools import partial
Expand All @@ -16,7 +15,6 @@
from .exceptions import InvalidSchema
from .hooks import GLOBAL_HOOK_DISPATCHER, HookContext, HookDispatcher
from .models import Case, Endpoint
from .types import Hook

PARAMETERS = frozenset(("path_parameters", "headers", "cookies", "query", "body", "form_data"))
LOCATION_TO_CONTAINER = {
Expand Down Expand Up @@ -201,17 +199,7 @@ def _apply_hooks(strategies: Dict[str, st.SearchStrategy], dispatcher: HookDispa
for hook in dispatcher.get_all_by_name(f"before_generate_{key}"):
# Get the strategy on each hook to pass the first hook output as an input to the next one
strategy = strategies[key]
args: Union[Tuple[st.SearchStrategy], Tuple[HookContext, st.SearchStrategy]]
if _accepts_context(hook):
args = (context, strategy)
else:
args = (strategy,)
strategies[key] = hook(*args)


def _accepts_context(hook: Hook) -> bool:
# There are no restrictions on the first argument's name and we don't check its name here.
return len(inspect.signature(hook).parameters) == 2
strategies[key] = hook(context, strategy)


def register_string_format(name: str, strategy: st.SearchStrategy) -> None:
Expand Down
5 changes: 1 addition & 4 deletions src/schemathesis/hooks.py
Expand Up @@ -110,10 +110,7 @@ def add_dispatcher(cls, func: GenericTest) -> "HookDispatcher":
return func._schemathesis_hooks # type: ignore

def register_hook_with_name(self, hook: Callable, name: str) -> Callable:
"""A helper for hooks registration.
Besides its use in this class internally it is used to keep backward compatibility with the old hooks system.
"""
"""A helper for hooks registration."""
self._validate_hook(name, hook)
self._hooks[name].append(hook)
return hook
Expand Down

0 comments on commit 7396949

Please sign in to comment.