Added compatibility for hypothesis 4 (#261)

hypothesis `average_size` argument was already deprecated [1], and was
effectively removed in hypothesis 4 [2].

[1] https://github.com/HypothesisWorks/hypothesis/pull/1162
[2] https://hypothesis.readthedocs.io/en/latest/changes.html#v4-0-0
This commit is contained in:
Mario Rodas 2019-06-17 03:10:14 -05:00 committed by Carlton Gibson
parent a3494215cf
commit f46c2448b1
2 changed files with 10 additions and 16 deletions

View File

@ -25,7 +25,7 @@ setup(
install_requires=["twisted[tls]>=18.7", "autobahn>=0.18", "asgiref~=3.0"],
setup_requires=["pytest-runner"],
extras_require={
"tests": ["hypothesis~=3.88", "pytest~=3.10", "pytest-asyncio~=0.8"]
"tests": ["hypothesis~=4.23", "pytest~=3.10", "pytest-asyncio~=0.8"]
},
entry_points={
"console_scripts": ["daphne = daphne.cli:CommandLineInterface.entrypoint"]

View File

@ -17,7 +17,7 @@ def http_method():
def _http_path_portion():
alphabet = string.ascii_letters + string.digits + "-._~"
return strategies.text(min_size=1, average_size=10, max_size=128, alphabet=alphabet)
return strategies.text(min_size=1, max_size=128, alphabet=alphabet)
def http_path():
@ -33,7 +33,7 @@ def http_body():
"""
Returns random binary body data.
"""
return strategies.binary(min_size=0, average_size=600, max_size=1500)
return strategies.binary(min_size=0, max_size=1500)
def valid_bidi(value):
@ -52,24 +52,22 @@ def valid_bidi(value):
def _domain_label():
return strategies.text(
alphabet=letters, min_size=1, average_size=6, max_size=63
).filter(valid_bidi)
return strategies.text(alphabet=letters, min_size=1, max_size=63).filter(valid_bidi)
def international_domain_name():
"""
Returns a byte string of a domain name, IDNA-encoded.
"""
return strategies.lists(_domain_label(), min_size=2, average_size=2).map(
return strategies.lists(_domain_label(), min_size=2).map(
lambda s: (".".join(s)).encode("idna")
)
def _query_param():
return strategies.text(
alphabet=letters, min_size=1, average_size=10, max_size=255
).map(lambda s: s.encode("utf8"))
return strategies.text(alphabet=letters, min_size=1, max_size=255).map(
lambda s: s.encode("utf8")
)
def query_params():
@ -79,7 +77,7 @@ def query_params():
ensures that the total urlencoded query string is not longer than 1500 characters.
"""
return strategies.lists(
strategies.tuples(_query_param(), _query_param()), min_size=0, average_size=5
strategies.tuples(_query_param(), _query_param()), min_size=0
).filter(lambda x: len(parse.urlencode(x)) < 1500)
@ -109,7 +107,6 @@ def header_value():
+ string.punctuation.replace(",", "")
+ " /t",
min_size=1,
average_size=40,
max_size=8190,
)
.map(lambda s: s.encode("utf-8"))
@ -125,8 +122,5 @@ def headers():
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
"""
return strategies.lists(
strategies.tuples(header_name(), header_value()),
min_size=0,
average_size=10,
max_size=100,
strategies.tuples(header_name(), header_value()), min_size=0, max_size=100
)